|
|
@ -161,8 +161,10 @@ func (t *UserCtl) WxLogin() { |
|
|
|
} |
|
|
|
|
|
|
|
func (t *UserCtl) Login() { |
|
|
|
activityId := t.MustGetInt("activity_id") |
|
|
|
wxcode := t.MustGet("code") |
|
|
|
// _type, _ := t.Get("type")
|
|
|
|
admin := t.DefaultInt("admin", 0) |
|
|
|
|
|
|
|
user := new(models.User) |
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
@ -174,6 +176,26 @@ func (t *UserCtl) Login() { |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, jwtToken) |
|
|
@ -185,6 +207,8 @@ func (t *UserCtl) Login() { |
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"user": user, |
|
|
|
"token": jwtToken, |
|
|
|
"area": area, |
|
|
|
"admin": admin, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|