feat:优化项目信息
This commit is contained in:
@ -77,3 +77,18 @@ func (*Account) Logout(c *gin.Context) {
|
||||
err := account.NewLogout()(_session).Launch()
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
// ResetPassword 重置密码
|
||||
func (*Account) ResetPassword(c *gin.Context) {
|
||||
form := &struct {
|
||||
Token string `json:"token" form:"token" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPass string `json:"repeat_pass" form:"repeat_pass" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := account.NewInstance()().ResetPassword(form.Token, form.Password, form.RepeatPass)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
package api
|
||||
|
||||
type Config struct{}
|
@ -1,11 +1,13 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@ -20,12 +22,12 @@ type (
|
||||
InstanceLoginParams struct {
|
||||
UID uint64
|
||||
Avatar, Name, Mobile string
|
||||
Vip model.UserInstanceVipKind
|
||||
Vip model2.UserInstanceVipKind
|
||||
VipStatus bool
|
||||
VipDeadline time.Time
|
||||
Currency float64
|
||||
Identity, SelectIdentity int
|
||||
Status model.AccountStatusKind
|
||||
Status model2.AccountStatusKind
|
||||
}
|
||||
InstanceLoginReturn struct {
|
||||
Token string `json:"token"`
|
||||
@ -57,6 +59,41 @@ func (c *Instance) Login() InstanceLoginCallback {
|
||||
}
|
||||
}
|
||||
|
||||
// ResetPassword 重置密码
|
||||
func (c *Instance) ResetPassword(token, password, repeatPass string) error {
|
||||
tokenInfo := utils.JWTDecrypt(token)
|
||||
|
||||
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
||||
return errors.New("操作错误,Token无效")
|
||||
}
|
||||
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
|
||||
expTime := time.Unix(expTimestamp, 0)
|
||||
ok := expTime.After(time.Now())
|
||||
|
||||
if !ok {
|
||||
return errors.New("操作错误,Token过期")
|
||||
}
|
||||
if password != repeatPass {
|
||||
return errors.New("操作错误,两次密码不一致")
|
||||
}
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "name", "mobile", "status"},
|
||||
model2.NewWhere("mobile", tokenInfo["mobile"]))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,系统中未找到此手机用户")
|
||||
}
|
||||
mUserInstance.Password = password
|
||||
mUserInstance.SetPasswordAttribute()
|
||||
|
||||
return model2.Updates(mUserInstance.UserInstance, map[string]interface{}{
|
||||
"password": mUserInstance.Password, "salt": mUserInstance.Salt, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func() *Instance {
|
||||
return &Instance{}
|
||||
|
Reference in New Issue
Block a user