From 1892bc4676e71ae49ec6b8fe35828a263a36f127 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 2 Sep 2020 12:04:03 +0800 Subject: [PATCH] fix:bug --- controllers/client/login.go | 41 +++++++++++++++++++++-------------------- main.go | 3 ++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/controllers/client/login.go b/controllers/client/login.go index 716fafd..661ece4 100644 --- a/controllers/client/login.go +++ b/controllers/client/login.go @@ -161,9 +161,8 @@ func (t *UserCtl) WxLogin() { } func (t *UserCtl) Login() { - //activityId := t.MustGetInt("activity_id") + activityId := t.MustGetInt("activity_id") wxcode := t.MustGet("code") - admin := t.DefaultInt("admin", 0) user := new(models.User) token, err := wechat.GetToken(wxcode) @@ -177,24 +176,26 @@ func (t *UserCtl) Login() { } area := &models.AreaStore{} - //if admin == 1 { - // username := t.MustGet("username") - // password := t.MustGet("password") - // exist, err := area.Login(activityId, username, password) - // t.CheckErr(err) - // t.Assert(exist, code.MSG_ERR_Authority, "不存在地区管理员") - // if area.UserId != user.Id { - // area.UserId = user.Id - // _, err = models.Update(area.Id, area, "user_id") - // t.CheckErr(err) - // } - //} else { - // exist, err := area.GetByUserId(activityId, user.Id) - // t.CheckErr(err) - // if exist { // 管理员 - // admin = 1 - // } - //} + admin := 0 + if username, ok := t.Get("username"); ok && username != "" { + username := t.MustGet("username") + password := t.MustGet("password") + exist, err := area.Login(activityId, username, password) + t.CheckErr(err) + t.Assert(exist, code.MSG_ERR_Authority, "不存在地区管理员") + if area.UserId != user.Id { + area.UserId = user.Id + _, err = models.Update(area.Id, area, "user_id") + t.CheckErr(err) + } + admin = 1 + } else { + exist, err := area.GetByUserId(activityId, user.Id) + t.CheckErr(err) + if exist { // 管理员 + admin = 1 + } + } jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0) t.CheckErr(err) diff --git a/main.go b/main.go index b4d3183..09df912 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,12 @@ import ( "hudongzhuanjia/controllers/client" "hudongzhuanjia/controllers/common" "hudongzhuanjia/controllers/pc" + "hudongzhuanjia/utils/define" //_ "net/http/pprof" ) func main() { - //define.SetDebug(true) + define.SetDebug(true) // pc core.GetInstanceRouterManage().Registered(new(pc.WsCtl)) // 用户