Files
kami_boss/internal/controllers/loginController.go
danial c3906e940e refactor(account): 重构账户管理页面布局和样式
-精简HTML结构,优化`account.html`,`apple-card/account.html`,和`t-mall-game/account.html`中iframe的布局。
- 调整CSS样式,以增强用户界面的一致性和可读性。
- 优化`account_history.html`中的表格和搜索栏的样式与对齐。

fix(controller): 修正新增控制器参数顺序

- 修正`addController.go`中的参数顺序,确保交易类型正确传递给服务层。
- 更新数据库插入操作,确保UUID正确分配给新记录,防止SQL错误。
2024-09-04 09:54:18 +08:00

123 lines
3.3 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 controllers
import (
"boss/internal/common"
"boss/internal/datas"
"boss/internal/models/user"
"boss/internal/utils"
"boss/internal/utils/mfa"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/validation"
beego "github.com/beego/beego/v2/server/web"
)
type LoginController struct {
beego.Controller
}
func (c *LoginController) Prepare() {
}
func (c *LoginController) Login() {
userID := c.GetString("userID")
passWD := c.GetString("passwd")
code := c.GetString("Code")
totpCode := c.GetString("totpCode")
dataJSON := new(datas.KeyDataJSON)
valid := validation.Validation{}
if v := valid.Required(userID, "userID"); !v.Ok {
dataJSON.Key = v.Error.Key
dataJSON.Code = -1
dataJSON.Msg = "手机号不能为空!"
} else if v := valid.Required(passWD, "passWD"); !v.Ok {
dataJSON.Code = -1
dataJSON.Key = v.Error.Key
dataJSON.Msg = "登录密码不能为空!"
} else if v := valid.Length(code, common.VERIFY_CODE_LEN, "code"); !v.Ok {
dataJSON.Code = -1
dataJSON.Key = v.Error.Key
dataJSON.Msg = "验证码不正确!"
}
userInfo := user.GetUserInfoByUserID(userID)
if userInfo.UserId == "" {
dataJSON.Code = -1
dataJSON.Key = "userID"
dataJSON.Msg = "用户不存在,请求联系管理员!"
} else if userInfo.OtpSecret != "" && totpCode == "" {
dataJSON.Code = -1
dataJSON.Key = "userID"
dataJSON.Msg = "需要输入二次验证!"
} else {
// 如果验证失败
if userInfo.OtpSecret != "" && !mfa.ValidCode(totpCode, userInfo.OtpSecret) {
dataJSON.Key = "userID"
dataJSON.Code = -1
dataJSON.Msg = "二次验证不正确,请输入二次验证!"
c.Data["json"] = dataJSON
_ = c.ServeJSON()
return
}
codeInterface := c.GetSession("verifyCode")
if userInfo.Passwd != utils.GetMD5Upper(passWD) {
dataJSON.Key = "passWD"
dataJSON.Msg = "密码不正确!"
dataJSON.Code = -1
} else if codeInterface == nil {
dataJSON.Key = "code"
dataJSON.Msg = "验证码失效!"
dataJSON.Code = -1
} else if code != codeInterface.(string) {
dataJSON.Key = "code"
dataJSON.Code = -1
dataJSON.Msg = "验证码不正确!"
} else if userInfo.Status == common.UNACTIVE {
dataJSON.Key = common.UNACTIVE
dataJSON.Msg = "用户已被冻结!"
dataJSON.Code = -1
} else if userInfo.Status == "del" {
dataJSON.Key = "del"
dataJSON.Code = -1
dataJSON.Msg = "用户已被删除!"
}
}
go func() {
userInfo.Ip = c.Ctx.Input.IP()
user.UpdateUserInfoIP(userInfo)
}()
if dataJSON.Key == "" {
_ = c.SetSession("userID", userID)
_ = c.DelSession("verifyCode")
}
c.Data["json"] = dataJSON
_ = c.ServeJSON()
}
/*
* 退出登录,删除session中的数据避免数据量过大内存吃紧
*/
func (c *LoginController) Logout() {
dataJSON := new(datas.BaseDataJSON)
_ = c.DelSession("userID")
dataJSON.Code = 200
c.Data["json"] = dataJSON
_ = c.ServeJSON()
}
// GetVerifyImg 验证码获取如果获取成功并将验证码存到session中
func (c *LoginController) GetVerifyImg() {
Image, verifyCode := utils.GenerateVerifyCodeImg()
if Image == nil || len(verifyCode) != common.VERIFY_CODE_LEN {
logs.Error("获取验证码图片失败!")
} else {
_ = c.SetSession("verifyCode", verifyCode)
}
if Image == nil {
logs.Error("生成验证码失败!")
} else {
_, _ = Image.WriteTo(c.Ctx.ResponseWriter)
}
}