本文整理匯總了Golang中github.com/dorajistyle/goyangi/model.User.ActivateUntil方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.ActivateUntil方法的具體用法?Golang User.ActivateUntil怎麽用?Golang User.ActivateUntil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dorajistyle/goyangi/model.User
的用法示例。
在下文中一共展示了User.ActivateUntil方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: EmailVerification
// EmailVerification verifies an email of user.
func EmailVerification(c *gin.Context) (int, error) {
var user model.User
var verifyEmailForm VerifyEmailForm
c.BindWith(&verifyEmailForm, binding.Form)
log.Debugf("verifyEmailForm.ActivationToken : %s", verifyEmailForm.ActivationToken)
if db.ORM.Where(&model.User{ActivationToken: verifyEmailForm.ActivationToken}).First(&user).RecordNotFound() {
return http.StatusNotFound, errors.New("User is not found.")
}
isExpired := timeHelper.IsExpired(user.ActivateUntil)
log.Debugf("passwordResetUntil : %s", user.ActivateUntil.UTC())
log.Debugf("expired : %t", isExpired)
if isExpired {
return http.StatusForbidden, errors.New("token not valid.")
}
user.ActivationToken = ""
user.ActivateUntil = time.Now()
user.ActivatedAt = time.Now()
user.Activation = true
status, err := UpdateUserCore(&user)
if err != nil {
return status, err
}
status, err = SetCookie(c, user.Token)
return status, err
}
示例2: SendVerificationToUser
// 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
}