commit
e6a5789dfc
1 changed files with 9 additions and 4 deletions
|
|
@ -46,20 +46,25 @@ func processLoginAdmin(process *gou.Process) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sid := session.ID()
|
||||||
|
if csid, ok := payload["sid"].(string); ok {
|
||||||
|
sid = csid
|
||||||
|
}
|
||||||
|
|
||||||
email := any.Of(payload.Get("email")).CString()
|
email := any.Of(payload.Get("email")).CString()
|
||||||
mobile := any.Of(payload.Get("mobile")).CString()
|
mobile := any.Of(payload.Get("mobile")).CString()
|
||||||
password := any.Of(payload.Get("password")).CString()
|
password := any.Of(payload.Get("password")).CString()
|
||||||
if email != "" {
|
if email != "" {
|
||||||
return auth("email", email, password)
|
return auth("email", email, password, sid)
|
||||||
} else if mobile != "" {
|
} else if mobile != "" {
|
||||||
return auth("mobile", mobile, password)
|
return auth("mobile", mobile, password, sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception.New("参数错误", 400).Ctx(payload).Throw()
|
exception.New("参数错误", 400).Ctx(payload).Throw()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func auth(field string, value string, password string) maps.Map {
|
func auth(field string, value string, password string, sid string) maps.Map {
|
||||||
column, has := loginTypes[field]
|
column, has := loginTypes[field]
|
||||||
if !has {
|
if !has {
|
||||||
exception.New("登录方式(%s)尚未支持", 400, field).Throw()
|
exception.New("登录方式(%s)尚未支持", 400, field).Throw()
|
||||||
|
|
@ -95,13 +100,13 @@ func auth(field string, value string, password string) maps.Map {
|
||||||
expiresAt := time.Now().Unix() + 3600
|
expiresAt := time.Now().Unix() + 3600
|
||||||
|
|
||||||
// token := MakeToken(row, expiresAt)
|
// token := MakeToken(row, expiresAt)
|
||||||
sid := session.ID()
|
|
||||||
id := any.Of(row.Get("id")).CInt()
|
id := any.Of(row.Get("id")).CInt()
|
||||||
token := helper.JwtMake(id, map[string]interface{}{}, map[string]interface{}{
|
token := helper.JwtMake(id, map[string]interface{}{}, map[string]interface{}{
|
||||||
"expires_at": expiresAt,
|
"expires_at": expiresAt,
|
||||||
"sid": sid,
|
"sid": sid,
|
||||||
"issuer": "yao",
|
"issuer": "yao",
|
||||||
})
|
})
|
||||||
|
log.Debug("[login] auth sid=%s", sid)
|
||||||
session.Global().Expire(time.Duration(token.ExpiresAt)*time.Second).ID(sid).Set("user_id", id)
|
session.Global().Expire(time.Duration(token.ExpiresAt)*time.Second).ID(sid).Set("user_id", id)
|
||||||
session.Global().ID(sid).Set("user", row)
|
session.Global().ID(sid).Set("user", row)
|
||||||
session.Global().ID(sid).Set("issuer", "yao")
|
session.Global().ID(sid).Set("issuer", "yao")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue