This commit is contained in:
henry
2021-11-24 09:59:29 +08:00
parent cf91d55ab2
commit f007168919
21 changed files with 360 additions and 93 deletions

View File

@ -3,7 +3,6 @@ package api
import (
account2 "SciencesServer/app/api/enterprise/controller/account"
"SciencesServer/app/basic/api"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
@ -12,7 +11,7 @@ type Account struct{}
type (
accountLoginForm struct {
Mode int `json:"mode" form:"mode" binding:"required"`
Mobile string `json:"mobile" form:"mobile"`
Account string `json:"account" form:"account"`
Captcha string `json:"captcha" form:"captcha"`
Password string `json:"password" form:"password"`
}
@ -37,11 +36,11 @@ func (a *Account) Login(c *gin.Context) {
Captcha: struct {
Mobile string
Captcha string
}{Mobile: form.Mobile, Captcha: form.Captcha},
}{Mobile: form.Account, Captcha: form.Captcha},
Password: struct {
Mobile string
Account string
Password string
}{Mobile: form.Mobile, Password: form.Password},
}{Account: form.Account, Password: form.Password},
})
api.APIResponse(err, data)(c)
}
@ -60,18 +59,20 @@ func (a *Account) Register(c *gin.Context) {
api.APIResponse(err, data)(c)
}
func (a *Account) BindMobile(c *gin.Context) {
func (*Account) Authorize(c *gin.Context) {
}
func (*Account) BindMobile(c *gin.Context) {
//account.NewOther()().BindMobile()
}
func (a *Account) Logout(c *gin.Context) {
handle := api.GetSession()(c)
func (*Account) Logout(c *gin.Context) {
// 因跳过中间键故只能自己去获取token用户信息
//token := c.GetHeader(config.APIRequestToken)
session := new(service.SessionEnterprise)
//session, _ := service.NewAuthToken(token).Auth()
if handle != nil {
session = handle.(*service.SessionEnterprise)
}
err := account2.NewLogout()(session).Launch()
err := account2.NewLogout()(nil).Launch()
api.APIResponse(err)(c)
}

View File

@ -20,7 +20,7 @@ type (
Mobile, Captcha string
}
Password struct {
Mobile, Password string
Account, Password string
}
Platform struct {
OpenID string
@ -88,13 +88,13 @@ RETURNS:
// loginForPassword 密码登陆
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
if !utils.ValidateMobile(params.Password.Mobile) {
if !utils.ValidateMobile(params.Password.Account) {
return nil, errors.New("手机号码格式异常")
}
mUserInstance := model3.NewUserInstance()
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
model2.NewWhere("mobile", params.Password.Mobile), model2.NewWhere("local", local))
model2.NewWhere("mobile", params.Password.Account), model2.NewWhere("local", local))
if err != nil {
return nil, err

View File

@ -13,7 +13,7 @@ type Logout struct {
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
func (c *Logout) Launch() error {
if c.UID > 0 {
if c.SessionEnterprise != nil && c.UID > 0 {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
}
return nil

View File

@ -62,6 +62,7 @@ func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error)
return nil, errors.New("当前手机号码已注册")
}
mUserInstance.Local.Local = c.local
mUserInstance.Source = model2.UserInstanceSourceForLocal
mUserInstance.Password = utils.GetRandomString(12)
mUserInstance.Mobile = params.Mobile
mUserInstance.Password = params.Password

View File

@ -24,7 +24,7 @@ type (
// Expert 专家数据
func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserManageForExpert, error) {
query := orm.GetDB().Table(m.TableName()+" AS m").
db := orm.GetDB().Table(m.TableName()+" AS m").
Select(strings.Join([]string{"m.id", "m.name", "u.mobile", "m.identity_info"}, ",")).
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON m.uid = u.uuid", model.NewUserInstance().TableName())).
Where("m.is_deleted = ?", model.DeleteStatusForNot).
@ -34,13 +34,13 @@ func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.Mo
if len(where) > 0 {
for _, v := range where {
query = query.Where(v.Condition, v.Value)
db = db.Where(v.Condition, v.Value)
}
}
if err := query.Count(count).Error; err != nil {
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := query.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil