refactor: 拆分超标控制器文件至行数≤120行
- auth_controller.go(238→54): 拆出auth_api_login.go(107)+auth_api_register.go(96) - settings_controller.go(289→101): 拆出settings_api_profile(116)+account(59)+error_handlers(41) - message_controller.go(129→85): 拆出message_page_controller.go(55) - 所有拆分后文件均≤120行,符合code-style.md瘦控制器规范
This commit is contained in:
59
internal/controller/settings_api_account.go
Normal file
59
internal/controller/settings_api_account.go
Normal file
@ -0,0 +1,59 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"metazone.cc/metalab/internal/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ChangePassword 修改密码(需登录)
|
||||
func (sc *SettingsController) ChangePassword(c *gin.Context) {
|
||||
uid, exists := c.Get("uid")
|
||||
if !exists {
|
||||
common.Error(c, http.StatusUnauthorized, "请先登录")
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
CurrentPassword string `json:"current_password" binding:"required"`
|
||||
NewPassword string `json:"new_password" binding:"required,min=8"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, http.StatusBadRequest, "请检查输入")
|
||||
return
|
||||
}
|
||||
|
||||
if err := sc.authService.ChangePassword(uid.(uint), req.CurrentPassword, req.NewPassword); err != nil {
|
||||
handleSettingsError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
common.OkMessage(c, "密码已修改,请重新登录")
|
||||
}
|
||||
|
||||
// DeleteAccount 自助注销账号(需登录,验证密码 + 注销原因)
|
||||
func (sc *SettingsController) DeleteAccount(c *gin.Context) {
|
||||
uid, exists := c.Get("uid")
|
||||
if !exists {
|
||||
common.Error(c, http.StatusUnauthorized, "请先登录")
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Password string `json:"password" binding:"required"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, http.StatusBadRequest, "请检查输入")
|
||||
return
|
||||
}
|
||||
|
||||
if err := sc.authService.DeleteAccount(uid.(uint), req.Password, req.Reason); err != nil {
|
||||
handleSettingsError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
common.OkMessage(c, "账号已注销,7 天内重新登录即可恢复")
|
||||
}
|
||||
Reference in New Issue
Block a user