q
This commit is contained in:
parent
444edafd54
commit
8ca48912f0
@ -17,5 +17,6 @@ func (this *DBEngine) UnInit() {
|
|||||||
|
|
||||||
func (this *DBEngine) NewAdminConn() *q5.Mysql {
|
func (this *DBEngine) NewAdminConn() *q5.Mysql {
|
||||||
conn := q5.NewMysql("127.0.0.1", 3306, "root", "keji178", "admindb")
|
conn := q5.NewMysql("127.0.0.1", 3306, "root", "keji178", "admindb")
|
||||||
|
conn.Open()
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"database/sql"
|
||||||
"q5"
|
"q5"
|
||||||
"f5"
|
"f5"
|
||||||
)
|
)
|
||||||
@ -38,53 +40,67 @@ func (this *UserMgr) _userLogin(c *f5.Context) {
|
|||||||
content := q5.NewMxoObject()
|
content := q5.NewMxoObject()
|
||||||
content.SetXValue("username", c.Request("username"))
|
content.SetXValue("username", c.Request("username"))
|
||||||
content.SetXValue("password", c.Request("password"))
|
content.SetXValue("password", c.Request("password"))
|
||||||
respStr, err := q5.HttpPostContent(url,
|
respStr := ""
|
||||||
|
if err := q5.HttpPostContent(url,
|
||||||
"application/json;charset=utf-8",
|
"application/json;charset=utf-8",
|
||||||
content.ToJsonStr())
|
content.ToJsonStr(),
|
||||||
if err == nil {
|
&respStr); err != nil {
|
||||||
f5.SysLog().Debug("respStr:%s", respStr)
|
c.ResponseErr(500, "服务器内部错误")
|
||||||
respObj := q5.NewXoFromJsonStr(respStr)
|
return
|
||||||
if respObj == nil || !respObj.IsObject() {
|
}
|
||||||
|
f5.SysLog().Debug("respStr:%s", respStr)
|
||||||
|
respObj := struct {
|
||||||
|
ErrCode *int32 `json:"errcode"`
|
||||||
|
ErrMsg string `json:"errmsg"`
|
||||||
|
Token string `json:"token"`
|
||||||
|
UserInfo *struct {
|
||||||
|
UserName string `json:"username"`
|
||||||
|
FullName string `json:"fullname"`
|
||||||
|
AvatarUrl string `json:"avatar"`
|
||||||
|
} `json:"userInfo"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal([]byte(respStr), &respObj); err != nil || respObj.ErrCode == nil {
|
||||||
|
c.ResponseErr(500, "服务器内部错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if *respObj.ErrCode != 0 {
|
||||||
|
c.Response(respStr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userInfo := respObj.UserInfo
|
||||||
|
nowUnix := f5.App.NowUnix()
|
||||||
|
conn := G.DBEngine.NewAdminConn()
|
||||||
|
row := conn.QueryRow("SELECT username FROM `user` WHERE username=?;",
|
||||||
|
userInfo.UserName)
|
||||||
|
{
|
||||||
|
userName := ""
|
||||||
|
err := row.Scan(&userName)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
c.ResponseErr(500, "服务器内部错误")
|
c.ResponseErr(500, "服务器内部错误")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
errCode := respObj.GetSimpleStr("errcode", "")
|
if err == sql.ErrNoRows {
|
||||||
userInfo := respObj.At("userinfo")
|
//新用户
|
||||||
if errCode != "0" || userInfo == nil || !userInfo.IsObject() {
|
conn.Exec("INSERT `user`(username, fullname, avatar_url, createtime, " +
|
||||||
c.Response(respStr)
|
" modifytime) " +
|
||||||
|
"VALUES(?, ?, ?, ?, ?);",
|
||||||
|
userInfo.UserName,
|
||||||
|
userInfo.FullName,
|
||||||
|
userInfo.AvatarUrl,
|
||||||
|
nowUnix,
|
||||||
|
nowUnix)
|
||||||
} else {
|
} else {
|
||||||
userName := userInfo.GetSimpleStr("username", "")
|
//老用户
|
||||||
fullName := userInfo.GetSimpleStr("fullname", "")
|
conn.Exec("UPDATE `user` SET fullname=?, avatar_url=?, " +
|
||||||
avatarUrl := userInfo.GetSimpleStr("avatar_url", "")
|
" modifytime=? " +
|
||||||
nowUnix := f5.App.NowUnix()
|
"WHERE username=?;",
|
||||||
conn := G.DBEngine.NewAdminConn()
|
userInfo.FullName,
|
||||||
row := conn.QueryRow("SELECT username FROM `user` WHERE username='?'", userName)
|
userInfo.AvatarUrl,
|
||||||
var idx int64
|
nowUnix,
|
||||||
if err := row.Scan(&idx); err == nil {
|
userInfo.UserName)
|
||||||
//新用户
|
|
||||||
conn.Exec("INSERT `user`(username, fullname, avatar_url, createtime, " +
|
|
||||||
" modifytime) " +
|
|
||||||
"VALUES('?', '?', '?', ?, ?);",
|
|
||||||
userName,
|
|
||||||
fullName,
|
|
||||||
avatarUrl,
|
|
||||||
nowUnix,
|
|
||||||
nowUnix)
|
|
||||||
} else {
|
|
||||||
//老用户
|
|
||||||
conn.Exec("UPDATE `user` SET fullname='?', avatar_url='?', " +
|
|
||||||
" modifytime=? " +
|
|
||||||
"WHERE username='?';",
|
|
||||||
fullName,
|
|
||||||
avatarUrl,
|
|
||||||
nowUnix,
|
|
||||||
userName)
|
|
||||||
}
|
|
||||||
c.Response(respStr)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.ResponseErr(500, "服务器内部错误")
|
|
||||||
}
|
}
|
||||||
|
c.Response(respStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *UserMgr) _userInfo(c *f5.Context, user *AuthedUser) {
|
func (this *UserMgr) _userInfo(c *f5.Context, user *AuthedUser) {
|
||||||
|
2
third_party/f5
vendored
2
third_party/f5
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 60518a8f3ccb28de37ba2b386fd36923b085b965
|
Subproject commit 72fe2ec77dfada4c3e839718327c63afd2254070
|
Loading…
x
Reference in New Issue
Block a user