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{}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Sms struct{}
|
||||
|
||||
func (a *Sms) sCaptcha(c *gin.Context) {
|
||||
func (*Sms) Captcha(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
}{}
|
||||
@ -16,5 +16,18 @@ func (a *Sms) sCaptcha(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := controller.NewSms()().Captcha(form.Mobile)
|
||||
APIResponse(err)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sms) CaptchaValidate(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
}{}
|
||||
if err := Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewSms()().CaptchaValidate(form.Mobile, form.Captcha)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -4,18 +4,26 @@ import (
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Sms struct{}
|
||||
|
||||
type SmsHandle func() *Sms
|
||||
|
||||
func (c *Sms) captchaCallback(mobile, code string) error {
|
||||
//content := fmt.Sprintf("【汇安科技】您的验证码是%s,三分钟内有效", code)
|
||||
// 发送短信
|
||||
//_ = platform.NewSms().Send()(platform.SmsSendModeForGroup, &platform.SmsParam{
|
||||
// Mobile: []string{mobile}, Content: content,
|
||||
//})
|
||||
type (
|
||||
CaptchaCallback struct {
|
||||
Token string `json:"token"`
|
||||
EffectTime int `json:"effect_time"`
|
||||
}
|
||||
)
|
||||
|
||||
// tokenEffectTime Token有效期,单位s
|
||||
var tokenEffectTime = 5 * 60
|
||||
|
||||
func (c *Sms) captchaCallback(mobile, code string, callback func() error) error {
|
||||
content := fmt.Sprintf("【中科云】您的验证码是%s,三分钟内有效", code)
|
||||
fmt.Println(content)
|
||||
// 执行保存数据库
|
||||
//mSysSmsLogs := model.NewSysSmsLogs()
|
||||
//mSysSmsLogs.Mobile = mobile
|
||||
@ -23,6 +31,14 @@ func (c *Sms) captchaCallback(mobile, code string) error {
|
||||
//mSysSmsLogs.Usage = model2.SysSmsLogsUsageForCaptcha
|
||||
//
|
||||
//return model2.Create(mSysSmsLogs.SysSmsLogs)
|
||||
|
||||
// 发送短信
|
||||
//_ = platform.NewSms().Send()(platform.SmsSendModeForGroup, &platform.SmsParam{
|
||||
// Mobile: []string{mobile}, Content: content,
|
||||
//})
|
||||
if callback != nil {
|
||||
//_ = callback()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -32,11 +48,32 @@ func (c *Sms) Captcha(mobile string) error {
|
||||
return errors.New("手机格式不正确")
|
||||
}
|
||||
if err := handle.NewCaptcha().Sms(6, mobile, c.captchaCallback); err != nil {
|
||||
return errors.New("操作错误")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Sms) CaptchaValidate(mobile, captcha string) (*CaptchaCallback, error) {
|
||||
if !utils.ValidateMobile(mobile) {
|
||||
return nil, errors.New("手机格式不正确")
|
||||
}
|
||||
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
|
||||
Mobile: mobile,
|
||||
Captcha: captcha,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("手机号或验证码错误")
|
||||
}
|
||||
return &CaptchaCallback{
|
||||
Token: utils.JWTEncrypt(tokenEffectTime, map[string]interface{}{
|
||||
"mobile": mobile,
|
||||
}),
|
||||
EffectTime: tokenEffectTime,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewSms() SmsHandle {
|
||||
return func() *Sms {
|
||||
return &Sms{}
|
||||
|
@ -28,11 +28,11 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
type SmsCallback func(mobile, code string) error
|
||||
type SmsCallback func(mobile, code string, function func() error) error
|
||||
|
||||
const (
|
||||
// SmsCaptchaEffectiveTime 短信验证码有效时间
|
||||
SmsCaptchaEffectiveTime int = 3600 * 3
|
||||
SmsCaptchaEffectiveTime int = 60 * 3
|
||||
)
|
||||
|
||||
func (this *CaptchaSms) validate() (bool, error) {
|
||||
@ -55,13 +55,12 @@ func (this *CaptchaImage) validate() (bool, error) {
|
||||
// Sms 短信
|
||||
func (this *Captcha) Sms(length int, mobile string, callback SmsCallback) error {
|
||||
code := utils.GetRandomCode(length)
|
||||
// 存储redis
|
||||
if err := cache.Cache.Set(mobile, code, SmsCaptchaEffectiveTime); err != nil {
|
||||
return err
|
||||
}
|
||||
// 发送短信
|
||||
//NewSms().Handle(mobile)
|
||||
return callback(mobile, code)
|
||||
return callback(mobile, code, func() error {
|
||||
// 存储redis
|
||||
return cache.Cache.Set(mobile, code, SmsCaptchaEffectiveTime)
|
||||
})
|
||||
}
|
||||
|
||||
// Image 图形
|
||||
|
@ -56,7 +56,7 @@ func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error
|
||||
if this.Keyword != "" {
|
||||
mustParams["keyword"] = this.Keyword
|
||||
}
|
||||
termParams["is_show"] = 1
|
||||
//termParams["is_show"] = 1
|
||||
|
||||
return es.Search(this, this.Index(), &es.SearchParams{
|
||||
TermParams: termParams,
|
||||
|
Reference in New Issue
Block a user