本文整理匯總了Golang中github.com/dorajistyle/goyangi/model.User.TokenExpiration方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.TokenExpiration方法的具體用法?Golang User.TokenExpiration怎麽用?Golang User.TokenExpiration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dorajistyle/goyangi/model.User
的用法示例。
在下文中一共展示了User.TokenExpiration方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UpdateUserCore
// UpdateUserCore updates a user. (Applying the modifed data of user).
func UpdateUserCore(user *model.User) (int, error) {
user.Md5 = crypto.GenerateMD5Hash(user.Email)
token, err := crypto.GenerateRandomToken32()
if err != nil {
return http.StatusInternalServerError, errors.New("Token not generated.")
}
user.Token = token
user.TokenExpiration = timeHelper.FewDaysLater(config.AuthTokenExpirationDay)
if db.ORM.Save(user).Error != nil {
return http.StatusInternalServerError, errors.New("User is not updated.")
}
return http.StatusOK, nil
}
示例2: CreateUserFromForm
// CreateUserFromForm creates a user from a registration form.
func CreateUserFromForm(registrationForm RegistrationForm) (model.User, error) {
var user model.User
log.Debugf("registrationForm %+v\n", registrationForm)
modelHelper.AssignValue(&user, ®istrationForm)
user.Md5 = crypto.GenerateMD5Hash(user.Email)
token, err := crypto.GenerateRandomToken32()
if err != nil {
return user, errors.New("Token not generated.")
}
user.Token = token
user.TokenExpiration = timeHelper.FewDaysLater(config.AuthTokenExpirationDay)
log.Debugf("user %+v\n", user)
if db.ORM.Create(&user).Error != nil {
return user, errors.New("User is not created.")
}
return user, nil
}