更新项目配置,修改 Go 版本至 1.24,添加依赖项,重构主程序以加载配置和初始化服务,删除不再使用的远程目标配置文件。
This commit is contained in:
83
cmii-uav-watchdog/controllers/auth_controller.go
Normal file
83
cmii-uav-watchdog/controllers/auth_controller.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cmii-uav-watchdog/models"
|
||||
"cmii-uav-watchdog/services"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AuthController 授权控制器
|
||||
type AuthController struct {
|
||||
authService *services.AuthService
|
||||
}
|
||||
|
||||
// NewAuthController 创建授权控制器
|
||||
func NewAuthController() *AuthController {
|
||||
return &AuthController{
|
||||
authService: services.NewAuthService(),
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateAuthFile 生成授权文件
|
||||
func (ac *AuthController) GenerateAuthFile(c *gin.Context) {
|
||||
// 生成授权文件
|
||||
authFile, err := ac.authService.GenerateAuthorizationFile()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "生成授权文件失败",
|
||||
Data: nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "生成授权文件成功",
|
||||
Data: authFile,
|
||||
})
|
||||
}
|
||||
|
||||
// ReceiveAuthCode 接收授权码
|
||||
func (ac *AuthController) ReceiveAuthCode(c *gin.Context) {
|
||||
var authCode models.AuthorizationCode
|
||||
if err := c.ShouldBindJSON(&authCode); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.Response{
|
||||
Code: 400,
|
||||
Message: "无效的请求参数",
|
||||
Data: nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 处理授权码
|
||||
err := ac.authService.ProcessAuthorizationCode(authCode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "处理授权码失败: " + err.Error(),
|
||||
Data: nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "处理授权码成功",
|
||||
Data: nil,
|
||||
})
|
||||
}
|
||||
|
||||
// NotifyAuthInfo 通知授权信息
|
||||
func (ac *AuthController) NotifyAuthInfo(c *gin.Context) {
|
||||
// 获取授权信息
|
||||
authInfo := ac.authService.GetAuthorizationInfo()
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "获取授权信息成功",
|
||||
Data: authInfo,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user