|
|
@ -91,10 +91,22 @@ func (t *UserCtl) WxLogin() { |
|
|
|
session, err := wechat.MiniAuth(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Openid = session.OpenId |
|
|
|
exist, err = user.GetUserByOpenid(user.Openid) |
|
|
|
t.CheckErr(err) |
|
|
|
if exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
} else if _type == "base" { |
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Openid = token.OpenId |
|
|
|
exist, err = user.GetUserByOpenid(user.Openid) |
|
|
|
t.CheckErr(err) |
|
|
|
if exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
} else if _type == "" { |
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
@ -103,6 +115,10 @@ func (t *UserCtl) WxLogin() { |
|
|
|
} |
|
|
|
info, err := wechat.GetUserInfo(token) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
exist, err = user.GetUserByOpenid(info.OpenId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
user.Nickname = info.Nickname |
|
|
|
user.Openid = info.OpenId |
|
|
|
user.Gender = func() string { |
|
|
@ -118,11 +134,14 @@ func (t *UserCtl) WxLogin() { |
|
|
|
user.Country = info.Country |
|
|
|
user.CreatedAt = time.Now() |
|
|
|
user.UpdatedAt = time.Now() |
|
|
|
if !exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
} else { |
|
|
|
_, err = user.SaveUserInfo(user.Id) |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
|
|
|
|
err = user.SaveAndUpdateWithOpenId() |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
history := new(models.SignHistory) |
|
|
|
signExist, err := history.GetByUserId(activityId, user.Id, activity.RehearsalId, area.Id) |
|
|
|
t.CheckErr(err) |
|
|
@ -164,10 +183,22 @@ func (t *UserCtl) Login() { |
|
|
|
session, err := wechat.MiniAuth(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Openid = session.OpenId |
|
|
|
exist, err := user.GetUserByOpenid(user.Openid) |
|
|
|
t.CheckErr(err) |
|
|
|
if exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
} else if _type == "base" { |
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Openid = token.OpenId |
|
|
|
exist, err := user.GetUserByOpenid(user.Openid) |
|
|
|
t.CheckErr(err) |
|
|
|
if exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
} else if _type == "" || _type == "userinfo" { |
|
|
|
//token, err := wx.GetToken(wxcode)
|
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
@ -178,6 +209,8 @@ func (t *UserCtl) Login() { |
|
|
|
//info, err := wx.GetUserInfo(token.AccessToken, token.OpenId)
|
|
|
|
info, err := wechat.GetUserInfo(token) |
|
|
|
t.CheckErr(err) |
|
|
|
exist, err := user.GetUserByOpenid(info.OpenId) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Nickname = info.Nickname |
|
|
|
user.Openid = info.OpenId |
|
|
|
user.Gender = func() string { |
|
|
@ -193,12 +226,14 @@ func (t *UserCtl) Login() { |
|
|
|
user.Country = info.Country |
|
|
|
user.CreatedAt = time.Now() |
|
|
|
user.UpdatedAt = time.Now() |
|
|
|
|
|
|
|
if !exist { |
|
|
|
_, err = core.GetXormAuto().Insert(user) |
|
|
|
} else { |
|
|
|
_, err = user.SaveUserInfo(user.Id) |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
|
|
|
|
err := user.SaveAndUpdateWithOpenId() |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, 0, 0, 0, 0) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, jwtToken) |
|
|
@ -275,7 +310,12 @@ func (t *UserAuthCtl) SaveUserInfo() { |
|
|
|
user.Country = info.Country |
|
|
|
_, err := user.SaveUserInfo(uid) |
|
|
|
t.CheckErr(err) |
|
|
|
//
|
|
|
|
//exist, err := models.GetById(&user, uid)
|
|
|
|
//t.CheckErr(err)
|
|
|
|
//t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
|
|
|
|
|
|
|
|
user.Id = uid |
|
|
|
sign, err := im.AccountImport(fmt.Sprintf("%d", user.Id), user.Avatar, user.Nickname) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|