feat:完善项目

This commit is contained in:
henry
2021-11-08 11:09:27 +08:00
parent 85b58968d1
commit 1502076841
20 changed files with 397 additions and 32 deletions

View File

@ -2,7 +2,6 @@ package account
import (
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/handle"
"ArmedPolice/app/model"
"ArmedPolice/app/service"
"ArmedPolice/config"
@ -18,14 +17,15 @@ type (
InstanceLoginResponse struct {
Token string `json:"token"`
EffectTime int `json:"effect_time"`
WsUrl string `json:"ws_url"`
}
)
func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string) (interface{}, error) {
// 验证验证码
if pass, _ := handle.NewCaptcha().Validate(&handle.CaptchaImage{Key: captchaKey, Captcha: captchaValue}); !pass {
return nil, errors.New("验证码错误")
}
//if pass, _ := handle.NewCaptcha().Validate(&handle.CaptchaImage{Key: captchaKey, Captcha: captchaValue}); !pass {
// return nil, errors.New("验证码错误")
//}
mSysUser := model.NewSysUser()
isExist, err := mSysUser.GetByAccountOrMobile(account)
@ -67,13 +67,15 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, key, session)
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip)
return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime,
WsUrl: config.SystemConfig[config.WsDomain].(string)}, nil
}
// Logout 退出请求
func (c *Instance) Logout() error {
if c.UID > 0 {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
service.HubMessage.UnregisterHandle(service.NewWebsocket(c.UIDToString(), nil))
}
return nil
}