|
@@ -6,9 +6,9 @@ import (
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
"hongze/hongze_yb_en_api/controller/resp"
|
|
|
"hongze/hongze_yb_en_api/global"
|
|
|
- "hongze/hongze_yb_en_api/models"
|
|
|
"hongze/hongze_yb_en_api/models/english_report_email"
|
|
|
"hongze/hongze_yb_en_api/models/msg_code"
|
|
|
+ "hongze/hongze_yb_en_api/models/session"
|
|
|
"hongze/hongze_yb_en_api/services"
|
|
|
"hongze/hongze_yb_en_api/utils"
|
|
|
"time"
|
|
@@ -18,7 +18,7 @@ type AuthController struct {
|
|
|
}
|
|
|
|
|
|
func (a *AuthController) Login(c *gin.Context) {
|
|
|
- req := new(models.LoginReq)
|
|
|
+ req := new(services.LoginReq)
|
|
|
err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -48,8 +48,8 @@ func (a *AuthController) Login(c *gin.Context) {
|
|
|
}
|
|
|
account := utils.MD5(req.Account)
|
|
|
token, err := utils.GenToken(account)
|
|
|
- sysSession := new(models.EnglishYbSession)
|
|
|
- sysSession.UserId = int(sysUser.AdminId)
|
|
|
+ sysSession := new(session.EnglishYbSession)
|
|
|
+ sysSession.UserId = int(sysUser.Id)
|
|
|
//现在要求永不过期
|
|
|
sysSession.ExpireTime = time.Now().AddDate(99, 0, 0)
|
|
|
sysSession.CreatedTime = time.Now()
|
|
@@ -67,7 +67,7 @@ func (a *AuthController) Login(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func (a *AuthController) Register(c *gin.Context) {
|
|
|
- req := new(models.RegisterReq)
|
|
|
+ req := new(services.RegisterReq)
|
|
|
err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -118,8 +118,8 @@ func (a *AuthController) Register(c *gin.Context) {
|
|
|
// @Success 200 {object} models.LoginResp
|
|
|
// @router /modifyPwd [post]
|
|
|
func (a *AuthController) ModifyPwd(c *gin.Context) {
|
|
|
- req := new(models.ModifyPwdReq)
|
|
|
- err := c.BindQuery(&req)
|
|
|
+ req := new(services.ModifyPwdReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
|
if !ok {
|
|
@@ -129,7 +129,36 @@ func (a *AuthController) ModifyPwd(c *gin.Context) {
|
|
|
resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
return
|
|
|
}
|
|
|
+ userinfo := services.GetInfoByClaims(c)
|
|
|
+
|
|
|
+ if req.NewPwd == "" {
|
|
|
+ resp.Fail("新密码不能为空", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.OldPwd == "" {
|
|
|
+ resp.Fail("旧密码不能为空", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.OldPwd != userinfo.Password{
|
|
|
+ resp.Fail("旧密码错误,请重新输入", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ emailitem := english_report_email.Email{
|
|
|
+ Id: userinfo.Id,
|
|
|
+ Password: req.NewPwd,
|
|
|
+ }
|
|
|
+ emailitem.ModifyTime = time.Now()
|
|
|
+
|
|
|
+ err = emailitem.Update([]string{"Password"})
|
|
|
+ if err != nil {
|
|
|
+ resp.FailMsg("修改密码失败", "修改密码失败,Err:" + err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
+ resp.Ok("修改成功", c)
|
|
|
}
|
|
|
|
|
|
// GetSmsCode 获取短信验证码接口
|