Files
mce/internal/controller/settings_api_account.go
Victor_Jay a19b1fcb51 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瘦控制器规范
2026-05-27 13:57:08 +08:00

60 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 天内重新登录即可恢复")
}