|
|
@ -63,7 +63,6 @@ func (t *UserCtl) EntryLogin() { |
|
|
|
func (t *UserCtl) WxLogin() { |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
wxcode := t.MustGet("code") |
|
|
|
_type, _ := t.Get("type") // mini 小程序登陆 base 静默授权 userinfo 或者为空 非静默授权
|
|
|
|
|
|
|
|
activity, exist, err := activity_service.GetActivityById(activityId) |
|
|
|
t.CheckErr(err) |
|
|
@ -83,64 +82,42 @@ func (t *UserCtl) WxLogin() { |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
if token.AccessToken == "" || token.OpenId == "" { |
|
|
|
t.ERROR("code无效", code.MSG_ERR) |
|
|
|
} |
|
|
|
info, err := wechat.GetUserInfo(token) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
user := new(models.User) |
|
|
|
exist, err = user.GetUserByOpenid(info.OpenId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
user.ActivityId = activityId |
|
|
|
user.AreaId = area.Id |
|
|
|
user.AreaName = area.Name |
|
|
|
if _type == "mini" { |
|
|
|
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) |
|
|
|
if token.AccessToken == "" || token.OpenId == "" { |
|
|
|
t.ERROR("code无效", code.MSG_ERR) |
|
|
|
} |
|
|
|
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 { |
|
|
|
if info.Sex == 1 { |
|
|
|
return "男" |
|
|
|
} |
|
|
|
return "女" |
|
|
|
}() |
|
|
|
user.Avatar = info.HeadImageURL |
|
|
|
user.Unionid = info.UnionId |
|
|
|
user.City = info.City |
|
|
|
user.Province = info.Province |
|
|
|
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) |
|
|
|
user.Nickname = info.Nickname |
|
|
|
user.Openid = info.OpenId |
|
|
|
user.Gender = func() string { |
|
|
|
if info.Sex == 1 { |
|
|
|
return "男" |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
return "女" |
|
|
|
}() |
|
|
|
user.Avatar = info.HeadImageURL |
|
|
|
user.Unionid = info.UnionId |
|
|
|
user.City = info.City |
|
|
|
user.Province = info.Province |
|
|
|
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) |
|
|
|
|
|
|
|
history := new(models.SignHistory) |
|
|
|
signExist, err := history.GetByUserId(activityId, user.Id, activity.RehearsalId, area.Id) |
|
|
@ -176,60 +153,16 @@ func (t *UserCtl) WxLogin() { |
|
|
|
|
|
|
|
func (t *UserCtl) Login() { |
|
|
|
wxcode := t.MustGet("code") |
|
|
|
_type, _ := t.Get("type") |
|
|
|
// _type, _ := t.Get("type")
|
|
|
|
|
|
|
|
user := new(models.User) |
|
|
|
if _type == "mini" { |
|
|
|
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) |
|
|
|
t.CheckErr(err) |
|
|
|
if token.AccessToken == "" || token.OpenId == "" { |
|
|
|
t.ERROR("code无效", code.MSG_ERR) |
|
|
|
} |
|
|
|
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 { |
|
|
|
if info.Sex == 1 { |
|
|
|
return "男" |
|
|
|
} |
|
|
|
return "女" |
|
|
|
}() |
|
|
|
user.Avatar = info.HeadImageURL |
|
|
|
user.Unionid = info.UnionId |
|
|
|
user.City = info.City |
|
|
|
user.Province = info.Province |
|
|
|
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) |
|
|
|
} |
|
|
|
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) |
|
|
|
} |
|
|
|
|
|
|
|