Update github.go
This commit is contained in:
parent
d0e4687607
commit
80546d5e3c
@ -28,7 +28,7 @@ type GitHubUser struct {
|
|||||||
|
|
||||||
func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
||||||
if code == "" {
|
if code == "" {
|
||||||
return nil, errors.New("无效的参数")
|
return nil, errors.New("invalid parameter")
|
||||||
}
|
}
|
||||||
values := map[string]string{"client_id": common.GitHubClientId, "client_secret": common.GitHubClientSecret, "code": code}
|
values := map[string]string{"client_id": common.GitHubClientId, "client_secret": common.GitHubClientSecret, "code": code}
|
||||||
jsonData, err := json.Marshal(values)
|
jsonData, err := json.Marshal(values)
|
||||||
@ -47,7 +47,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
|||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysLog(err.Error())
|
common.SysLog(err.Error())
|
||||||
return nil, errors.New("无法连接至 GitHub 服务器,请稍后重试!")
|
return nil, errors.New("Unable to connect to GitHub servers, please try again later!")
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
var oAuthResponse GitHubOAuthResponse
|
var oAuthResponse GitHubOAuthResponse
|
||||||
@ -63,7 +63,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
|||||||
res2, err := client.Do(req)
|
res2, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysLog(err.Error())
|
common.SysLog(err.Error())
|
||||||
return nil, errors.New("无法连接至 GitHub 服务器,请稍后重试!")
|
return nil, errors.New("Unable to connect to GitHub server, please try again later!")
|
||||||
}
|
}
|
||||||
defer res2.Body.Close()
|
defer res2.Body.Close()
|
||||||
var githubUser GitHubUser
|
var githubUser GitHubUser
|
||||||
@ -72,7 +72,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if githubUser.Login == "" {
|
if githubUser.Login == "" {
|
||||||
return nil, errors.New("返回值非法,用户字段为空,请稍后重试!")
|
return nil, errors.New("ilegal return value, user field is empty, please try again later!")
|
||||||
}
|
}
|
||||||
return &githubUser, nil
|
return &githubUser, nil
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
if !common.GitHubOAuthEnabled {
|
if !common.GitHubOAuthEnabled {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "管理员未开启通过 GitHub 登录以及注册",
|
"message": "The administrator has not enabled login and registration through GitHub",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "管理员关闭了新用户注册",
|
"message": "Admin turned off new user registration",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
|
|
||||||
if user.Status != common.UserStatusEnabled {
|
if user.Status != common.UserStatusEnabled {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": "用户已被封禁",
|
"message": "User has been banned",
|
||||||
"success": false,
|
"success": false,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -155,7 +155,7 @@ func GitHubBind(c *gin.Context) {
|
|||||||
if !common.GitHubOAuthEnabled {
|
if !common.GitHubOAuthEnabled {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "管理员未开启通过 GitHub 登录以及注册",
|
"message": "The administrator has not enabled login and registration through GitHub",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ func GitHubBind(c *gin.Context) {
|
|||||||
if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
|
if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "该 GitHub 账户已被绑定",
|
"message": "The GitHub account has been bound",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user