修改获取登录url,修改拦截

This commit is contained in:
junleea 2025-04-26 11:03:34 +08:00
parent 06afc13d67
commit 5cc9135d0e
2 changed files with 19 additions and 7 deletions

View File

@ -56,7 +56,7 @@ func SetUpToolGroup(router *gin.Engine) {
//服务器、设备状态接口 //服务器、设备状态接口
toolGroup.POST("/monitor", SetDeviceStatusV2) toolGroup.POST("/monitor", SetDeviceStatusV2)
toolGroup.POST("/qq_callback", handleQQCallback) toolGroup.POST("/qq_callback", handleQQCallback)
toolGroup.POST("/qq_auth", GetAuthCode) toolGroup.POST("/qq_auth", GetQQAuthUrl)
toolGroup.POST("/github_auth", ToGithubAuthPage) toolGroup.POST("/github_auth", ToGithubAuthPage)
toolGroup.POST("/github_callback", handleGithubCallback) toolGroup.POST("/github_callback", handleGithubCallback)
//发送邮件 //发送邮件
@ -112,11 +112,11 @@ type QQCallbackReq struct {
State string `json:"state" form:"state"` State string `json:"state" form:"state"`
} }
func GetAuthCode(c *gin.Context) { func GetQQAuthUrl(c *gin.Context) {
//query //query
uuid := c.Query("uuid") uuid := c.Query("uuid")
if uuid == "" {
var resp proto.GenerateResp var resp proto.GenerateResp
if uuid == "" {
resp.Code = proto.ParameterError resp.Code = proto.ParameterError
resp.Message = "uuid is empty" resp.Message = "uuid is empty"
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
@ -128,7 +128,11 @@ func GetAuthCode(c *gin.Context) {
params.Add("state", "saw_"+uuid) params.Add("state", "saw_"+uuid)
str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), worker.RedirectURI) str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), worker.RedirectURI)
loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/authorize", str) loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/authorize", str)
c.Redirect(http.StatusFound, loginURL) //重定向到QQ登录页面 //c.Redirect(http.StatusFound, loginURL) //重定向到QQ登录页面
resp.Message = "success"
resp.Code = proto.SuccessCode
resp.Data = loginURL
c.JSON(http.StatusOK, resp)
} }
func handleQQCallback(c *gin.Context) { func handleQQCallback(c *gin.Context) {
@ -640,8 +644,11 @@ func handleGithubCallback(c *gin.Context) {
func ToGithubAuthPage(c *gin.Context) { func ToGithubAuthPage(c *gin.Context) {
uuid := c.Query("uuid") uuid := c.Query("uuid")
var resp proto.GenerateResp
if uuid == "" { if uuid == "" {
c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": "uuid is empty"}) resp.Code = proto.ParameterError
resp.Message = "uuid is empty"
c.JSON(http.StatusOK, resp)
return return
} }
params := url.Values{} params := url.Values{}
@ -651,5 +658,10 @@ func ToGithubAuthPage(c *gin.Context) {
baseUri := "https://github.com/login/oauth/authorize" baseUri := "https://github.com/login/oauth/authorize"
redirectUrl := fmt.Sprintf("%s?%s", baseUri, params.Encode()) redirectUrl := fmt.Sprintf("%s?%s", baseUri, params.Encode())
redirectUrl = fmt.Sprintf("%s&redirect_uri=%s", redirectUrl, "https://sv.ljsea.top") redirectUrl = fmt.Sprintf("%s&redirect_uri=%s", redirectUrl, "https://sv.ljsea.top")
c.Redirect(http.StatusFound, redirectUrl) //c.Redirect(http.StatusFound, redirectUrl)
resp.Message = "success"
resp.Code = proto.SuccessCode
resp.Data = redirectUrl
c.JSON(http.StatusOK, resp)
} }

View File

@ -9,7 +9,7 @@ import (
var Config ConfigStruct var Config ConfigStruct
var SigningKey = []byte{} var SigningKey = []byte{}
var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true, "/user/sync": true, "/tool/file/": true, "/user/reset": true, "/tool/qq_auth": true, "/tool/qq_callback": true} // 不需要token验证的url var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true, "/user/sync": true, "/tool/file/": true, "/user/reset": true, "/tool/qq_auth": true, "/tool/qq_callback": true, "/tool/github_auth": true, "/tool/github_callback": true, "/user/oAuth": true, "/user/oAuth_uuid": true} // 不需要token验证的url
var Per_menu_map = map[string]int{"/video/": 1, "/device/": 2, "/cid/": 3} var Per_menu_map = map[string]int{"/video/": 1, "/device/": 2, "/cid/": 3}
var File_Type = map[string]int{"im": 1, "avatar": 2, "file": 3, "config": 4} // 文件类型 var File_Type = map[string]int{"im": 1, "avatar": 2, "file": 3, "config": 4} // 文件类型
const ( const (