MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Oauth

Method Oauth

controllers/AcountController.go:38–225  ·  view source on GitHub ↗

第三方登录回调 封装一个内部调用的函数,loginByMemberId

()

Source from the content-addressed store, hash-verified

36//第三方登录回调
37//封装一个内部调用的函数,loginByMemberId
38func (this *AccountController) Oauth() {
39
40 var (
41 nickname string //昵称
42 avatar string //头像的http链接地址
43 email string //邮箱地址
44 username string //用户名
45 tips string
46 id interface{} //第三方的用户id,唯一识别码
47 IsEmail bool //是否是使用邮箱注册
48 captchaOn bool //是否开启了验证码
49 )
50
51 //如果开启了验证码
52 if v, ok := this.Option["ENABLED_CAPTCHA"]; ok && strings.EqualFold(v, "true") {
53 captchaOn = true
54 this.Data["CaptchaOn"] = captchaOn
55 }
56
57 oauthLogin := false
58 if v, ok := this.Option["LOGIN_QQ"]; ok && strings.EqualFold(v, "true") {
59 this.Data["LoginQQ"] = true
60 oauthLogin = true
61 }
62 if v, ok := this.Option["LOGIN_GITHUB"]; ok && strings.EqualFold(v, "true") {
63 this.Data["LoginGitHub"] = true
64 oauthLogin = true
65 }
66 if v, ok := this.Option["LOGIN_GITEE"]; ok && strings.EqualFold(v, "true") {
67 this.Data["LoginGitee"] = true
68 oauthLogin = true
69 }
70 this.Data["OauthLogin"] = oauthLogin
71
72 oa := this.GetString(":oauth")
73 code := this.GetString("code")
74 switch oa {
75 case "gitee":
76 tips = `您正在使用【码云】登录`
77 token, err := oauth.GetGiteeAccessToken(code)
78 if err != nil {
79 beego.Error(err)
80 this.Abort("404")
81 }
82
83 info, err := oauth.GetGiteeUserInfo(token.AccessToken)
84 if err != nil {
85 beego.Error(err)
86 this.Abort("404")
87 }
88
89 if info.Id > 0 {
90 existInfo, _ := models.ModelGitee.GetUserByGiteeId(info.Id, "id", "member_id")
91 if existInfo.MemberId > 0 { //直接登录
92 err = this.loginByMemberId(existInfo.MemberId)
93 if err != nil {
94 beego.Error(err)
95 this.Abort("404")

Callers

nothing calls this directly

Calls 12

GetGiteeAccessTokenFunction · 0.92
GetGiteeUserInfoFunction · 0.92
GetGithubAccessTokenFunction · 0.92
GetGithubUserInfoFunction · 0.92
GetQQAccessTokenFunction · 0.92
GetQQOpenIdFunction · 0.92
GetQQUserInfoFunction · 0.92
GetUserByGiteeIdMethod · 0.80
loginByMemberIdMethod · 0.80
GetUserByGithubIdMethod · 0.80
InsertMethod · 0.45
GetUserByOpenidMethod · 0.45

Tested by

no test coverage detected