feat:优化项目信息

This commit is contained in:
henry
2022-02-11 11:02:29 +08:00
parent 95f1401468
commit cbc0ad1a41
9 changed files with 132 additions and 24 deletions

View File

@ -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{}