go-platform/controllers/platform_auth.go
2026-03-31 17:28:07 +08:00

156 lines
3.8 KiB
Go

package controllers
import (
"encoding/json"
"io"
"net/http"
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
type platformLoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
// PlatformAuthController 平台端认证控制器
type PlatformAuthController struct {
beego.Controller
}
// Login 平台登录
func (c *PlatformAuthController) Login() {
var req platformLoginRequest
// 支持前端以 JSON body 方式提交
body, err := io.ReadAll(c.Ctx.Request.Body)
if err != nil {
c.Ctx.Output.SetStatus(http.StatusBadRequest)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "参数错误",
}
_ = c.ServeJSON()
return
}
if err := json.Unmarshal(body, &req); err != nil {
c.Ctx.Output.SetStatus(http.StatusBadRequest)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "参数错误",
}
_ = c.ServeJSON()
return
}
if req.Username == "" || req.Password == "" {
c.Ctx.Output.SetStatus(http.StatusBadRequest)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "用户名或密码不能为空",
}
_ = c.ServeJSON()
return
}
// 控制器只做 HTTP 解析与响应编排,业务逻辑放 services 层
token, err := services.PlatformLogin(req.Username, req.Password)
if err != nil {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "未实现",
}
_ = c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{
"success": true,
"token": token,
}
_ = c.ServeJSON()
}
// SendLoginCode 发送登录验证码(占位实现)
func (c *PlatformAuthController) SendLoginCode() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "发送登录验证码暂未实现",
}
_ = c.ServeJSON()
}
// LoginBySms 手机号验证码登录(占位实现)
func (c *PlatformAuthController) LoginBySms() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "手机号验证码登录暂未实现",
}
_ = c.ServeJSON()
}
// Logout 平台退出登录(占位实现,当前为无状态直接返回成功)
func (c *PlatformAuthController) Logout() {
c.Data["json"] = map[string]interface{}{
"success": true,
}
_ = c.ServeJSON()
}
// GetGeetest3Infos 获取极验3.0配置(占位实现)
func (c *PlatformAuthController) GetGeetest3Infos() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "极验3.0暂未实现",
}
_ = c.ServeJSON()
}
// GetGeetest4Infos 获取极验4.0配置(占位实现)
func (c *PlatformAuthController) GetGeetest4Infos() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "极验4.0暂未实现",
}
_ = c.ServeJSON()
}
// GetOpenVerify 判断是否开启登录验证(占位实现)
func (c *PlatformAuthController) GetOpenVerify() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "登录验证开关暂未实现",
}
_ = c.ServeJSON()
}
// ResetPassword 忘记密码重置(占位实现)
func (c *PlatformAuthController) ResetPassword() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "重置密码暂未实现",
}
_ = c.ServeJSON()
}
// SendResetCode 发送找回密码验证码(占位实现)
func (c *PlatformAuthController) SendResetCode() {
c.Ctx.Output.SetStatus(http.StatusNotImplemented)
c.Data["json"] = map[string]interface{}{
"success": false,
"message": "发送找回密码验证码暂未实现",
}
_ = c.ServeJSON()
}