TODO: password
This commit is contained in:
@@ -92,14 +92,15 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
token, err := l.svcCtx.OAuthTokenManger.Decrypt(req.Token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
}
|
||||
|
||||
switch token.OperateType {
|
||||
switch auth.OperateType(req.OpType) {
|
||||
case auth.OpTypeRegister:
|
||||
|
||||
token, err := l.svcCtx.OAuthTokenManger.Decrypt(req.Token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
}
|
||||
|
||||
if time.Since(token.CreateAt) > 30*time.Minute {
|
||||
return resp.SetStatusWithMessage(basic.CodeOAuthConfirmationTimeoutErr, "Verification links expire after 30 minute.")
|
||||
}
|
||||
@@ -135,6 +136,36 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
}
|
||||
logx.Info("success:", token.TraceId)
|
||||
}
|
||||
case auth.OpTypeResetToken:
|
||||
|
||||
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.Token) // ResetToken
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err.Error())
|
||||
}
|
||||
|
||||
// TODO: 存储
|
||||
if rt.OperateType != auth.OpTypeResetToken {
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, "error OperateType: rt.OperateType != auth.OpTypeResetToken")
|
||||
}
|
||||
|
||||
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
|
||||
user := &gmodel.FsUser{Id: int64(rt.UserId)}
|
||||
err := tx.Take(user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if *user.PasswordHash != rt.OldPassword {
|
||||
return fmt.Errorf("password had beed updated")
|
||||
}
|
||||
return tx.Update("PasswordHash", rt.NewPassword).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
||||
default:
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
|
||||
Reference in New Issue
Block a user