// ResetPasswordRequest allows to send the user an email to reset his password
ResetPasswordRequest allows to send the user an email to reset his password
// ResetPasswordRequest allows to send the user an email to reset his password
func (UserController) ResetPasswordRequest(c *gin.Context) {
	dbUser, err := store.GetUser(c, params.M{"email": c.Param("email")})
	if err != nil {
		utils.Log(c, "warn", "ResetPasswordRequest failed with input:", c.Param("email"))
		return
	}
	encodedKey := []byte(config.GetString(c, "rsa_private"))
	privateKey, err := helpers.GetRSAPrivateKey(encodedKey)
	utils.CheckErr(err)
	token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
		"sub":           "define",
		"userId":        dbUser.ID,
		"userKey":       dbUser.Key,
		"userEmail":     dbUser.Email,
		"userFirstname": dbUser.FirstName,
		"userLastname":  dbUser.LastName,
	})
	tokenStr, err := token.SignedString(privateKey)
	utils.CheckErr(err)
	apiURL := `https://` + config.GetString(c, "front_url") + `/update-account/` + tokenStr
	frontURL := config.GetString(c, "front_url")
	appName := config.GetString(c, "mail_sender_name")
	s := services.GetEmailSender(c)
	err = s.SendResetEmail(dbUser, apiURL, appName, frontURL)
	if err != nil {
		logrus.Infoln(err)
		c.AbortWithError(http.StatusUnauthorized, helpers.ErrorWithCode("mail_sending_error", "Error when sending mail", err))
		return
	}
}
func ( UserController ) ResetPasswordRequest ( c * gin . Context ) { dbUser , err := store . GetUser ( c , params . M { " " : c . Param ( " " ) } ) if err != nil { utils . Log ( c , " " , " " , c . Param ( " " ) ) return } encodedKey := [ ] byte ( config . GetString ( c , " " ) ) privateKey , err := helpers . GetRSAPrivateKey ( encodedKey ) utils . CheckErr ( err ) token := jwt . NewWithClaims ( jwt . SigningMethodRS256 , jwt . MapClaims { " " : " " , " " : dbUser . ID , " " : dbUser . Key , " " : dbUser . Email , " " : dbUser . FirstName , " " : dbUser . LastName , } ) tokenStr , err := token . SignedString ( privateKey ) utils . CheckErr ( err ) apiURL := `https://` + config . GetString ( c , " " ) + `/update-account/` + tokenStr frontURL := config . GetString ( c , " " ) appName := config . GetString ( c , " " ) s := services . GetEmailSender ( c ) err = s . SendResetEmail ( dbUser , apiURL , appName , frontURL ) if err != nil { logrus . Infoln ( err ) c . AbortWithError ( http . StatusUnauthorized , helpers . ErrorWithCode ( " " , " " , err ) ) return } }
ResetPasswordRequest allows to send the user an email to reset his password
ResetPasswordRequest allows to send the user an email to reset his password