Ejemplo n.º 1
0
// SendPasswordResetToken sends a password reset token.
func SendPasswordResetToken(c *gin.Context) (int, error) {
	var user model.User
	var sendPasswordResetForm SendPasswordResetForm
	var err error
	log.Debugf("c.Params : %v", c.Params)
	c.BindWith(&sendPasswordResetForm, binding.Form)
	if db.ORM.Where(&model.User{Email: sendPasswordResetForm.Email}).First(&user).RecordNotFound() {
		return http.StatusNotFound, errors.New("User is not found. Please Check the email.")
	}
	user.PasswordResetUntil = timeHelper.TwentyFourHoursLater()
	user.PasswordResetToken, err = crypto.GenerateRandomToken16()
	if err != nil {
		return http.StatusInternalServerError, err
	}
	log.Debugf("generated token : %s", user.PasswordResetToken)
	status, err := UpdateUserCore(&user)
	if err != nil {
		return status, err
	}
	err = SendEmailPasswordResetToken(user.Email, user.PasswordResetToken, "en-us")
	if err != nil {
		return http.StatusInternalServerError, err
	}
	return http.StatusOK, nil
}
Ejemplo n.º 2
0
// SendVerificationToUser sends an email verification token to user.
func SendVerificationToUser(user model.User) (int, error) {
	var status int
	var err error
	user.ActivateUntil = timeHelper.TwentyFourHoursLater()
	user.ActivationToken, err = crypto.GenerateRandomToken32()
	if err != nil {
		return http.StatusInternalServerError, err
	}
	user.Activation = false
	log.Debugf("generated token : %s", user.ActivationToken)
	status, err = UpdateUserCore(&user)
	if err != nil {
		return status, err
	}
	err = SendEmailVerfication(user.Email, user.ActivationToken, "en-us")
	if err != nil {
		return http.StatusInternalServerError, err
	}
	return http.StatusOK, err
}