From a631f0f8f824caca91bc99e7dbb1f27c6c0a39ef Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 18 八月 2023 17:12:20 +0800
Subject: [PATCH] fix
---
api/v1/user.go | 124 ++++++++++++++++++-----------------------
1 files changed, 55 insertions(+), 69 deletions(-)
diff --git a/api/v1/user.go b/api/v1/user.go
index 99534cf..9cd713c 100644
--- a/api/v1/user.go
+++ b/api/v1/user.go
@@ -6,9 +6,7 @@
"aps_crm/model"
"aps_crm/model/request"
"aps_crm/model/response"
- _ "aps_crm/model/response"
"aps_crm/pkg/contextx"
- "aps_crm/pkg/convertx"
"aps_crm/pkg/ecode"
"aps_crm/pkg/encrypt"
"aps_crm/pkg/logx"
@@ -18,7 +16,6 @@
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
"github.com/mojocn/base64Captcha"
- "time"
)
// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮�
@@ -26,6 +23,7 @@
var store = base64Captcha.DefaultMemStore
// Login
+//
// @Tags Base
// @Summary 鐢ㄦ埛鐧诲綍
// @Produce application/json
@@ -41,41 +39,34 @@
// 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚�
key := c.ClientIP()
- openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁�
- openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿
- v, ok := constvar.BlackCache.Get(key)
- if !ok {
- constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
- }
+ //openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鏆存鏁�
+ //openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿
+ //v, ok := constvar.BlackCache.Get(key)
+ //if !ok {
+ // constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
+ //}
- var oc bool = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟
+ //var oc = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃叉毚娆℃暟
- if !oc || store.Verify(params.CaptchaId, params.Captcha, true) {
- u := &model.User{Username: params.Username, Password: params.Password}
- user, errCode := userService.Login(u)
- if errCode != ecode.OK {
- logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛鍚嶄笉瀛樺湪鎴栬�呭瘑鐮侀敊璇�! errCode:%v", errCode)
- // 楠岃瘉鐮佹鏁�+1
- _ = constvar.BlackCache.Increment(key, 1)
- ctx.Fail(errCode)
- return
- }
- if !user.Enable {
- logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛琚姝㈢櫥褰�!")
- // 楠岃瘉鐮佹鏁�+1
- _ = constvar.BlackCache.Increment(key, 1)
- ctx.Fail(ecode.UserForbidden)
- return
- }
- // 璧嬪�艰彍鍗旾D鍒楄〃
- //user.MenuIds, _ = menuService.GetUserMenuIds(user.ID, user.UserType)
- slf.TokenNext(ctx, *user)
+ //if !oc || store.Verify(params.CaptchaId, params.Captcha, true) {
+ u := &model.User{Username: params.Username, Password: params.Password}
+ user, errCode := userService.Login(u)
+ if errCode != ecode.OK {
+ logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛鍚嶄笉瀛樺湪鎴栬�呭瘑鐮侀敊璇�! errCode:%v", errCode)
+ // 楠岃瘉鐮佹鏁�+1
+ _ = constvar.BlackCache.Increment(key, 1)
+ ctx.Fail(errCode)
return
}
+ // 璧嬪�艰彍鍗旾D鍒楄〃
+ //user.MenuIds, _ = menuService.GetUserMenuIds(user.UUID, user.UserType)
+ slf.TokenNext(ctx, *user)
+ return
+ //}
// 楠岃瘉鐮佹鏁�+1
- _ = constvar.BlackCache.Increment(key, 1)
- ctx.Fail(ecode.CaptchaErr)
+ //_ = constvar.BlackCache.Increment(key, 1)
+ //ctx.Fail(ecode.CaptchaErr)
}
// TokenNext 鐧诲綍浠ュ悗绛惧彂jwt
@@ -83,10 +74,10 @@
logx.Infof("TokenNext user:%+v", user)
j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕
claims := j.CreateClaims(request.BaseClaims{
- UserId: user.ID,
- Username: user.Username,
- ParentId: user.ParentName,
- UserType: user.UserType,
+ UserId: user.UUID,
+ Username: user.Username,
+ UserType: user.UserType,
+ AuthorityId: user.AuthorityId,
})
token, err := j.CreateToken(claims)
if err != nil {
@@ -137,6 +128,7 @@
}
// Register
+//
// @Tags User
// @Summary 娉ㄥ唽璐﹀彿
// @Produce application/json
@@ -156,7 +148,7 @@
return
}
- if len(params.Username) == 0 || len(params.Password) == 0 || len(params.Phone) == 0 || len(params.NickName) == 0 {
+ if len(params.Username) == 0 || len(params.Password) == 0 || len(params.NickName) == 0 || params.AuthorityId == 0 || len(params.RePassword) == 0 || params.DepartmentId == 0 {
ctx.Fail(ecode.ParamsErr)
return
}
@@ -164,46 +156,34 @@
var userId = fmt.Sprintf("u%v", snowflake.GenerateId())
var passWord = encrypt.BcryptHash(params.Password)
var userType constvar.UserType
- var parentId string
- var parentName string
- if userInfo.UserType == constvar.UserTypeSuper {
- userType = constvar.UserTypePrimary //銆�涓昏处鎴风殑鐖剁敤鎴稩D鏄嚜宸�
- parentId = userId
- parentName = params.Username
- } else if userInfo.UserType == constvar.UserTypePrimary {
- userType = constvar.UserTypeSub
- parentId = userInfo.UserId
- parentName = userInfo.ParentId
- } else {
- ctx.Fail(ecode.NoPowerErr)
- return
- }
- user := &model.User{ID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Enable: true, ParentId: parentId, ParentName: parentName, Phone: params.Phone, Email: params.Email}
+ user := &model.User{UUID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Phone: params.Phone, Email: params.Email, DepartmentId: params.DepartmentId, AuthorityId: params.AuthorityId}
userReturn, errCode := userService.Register(user)
if errCode != ecode.OK {
ctx.Fail(errCode)
return
}
- if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴�
- err := model.NewMysql().CreateDatabase(user.Username)
- if err != nil {
- ctx.Fail(ecode.CreateDatabaseErr)
- return
- }
- defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username)
- err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username)
- if err != nil {
- ctx.Fail(ecode.CreateDatabaseUserErr)
- return
- }
- }
+ //if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴�
+ // err := model.NewMysql().CreateDatabase(user.Username)
+ // if err != nil {
+ // ctx.Fail(ecode.CreateDatabaseErr)
+ // return
+ // }
+ //
+ // defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username)
+ // err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username)
+ // if err != nil {
+ // ctx.Fail(ecode.CreateDatabaseUserErr)
+ // return
+ // }
+ //}
ctx.OkWithDetailed(response.UserResponse{User: *userReturn})
}
// ChangePassword
+//
// @Tags User
// @Summary 鐢ㄦ埛淇敼瀵嗙爜
// @Produce application/json
@@ -217,7 +197,7 @@
return
}
- u := &model.User{ID: utils.GetUserID(c), Password: params.Password}
+ u := &model.User{UUID: utils.GetUserID(c), Password: params.Password}
_, errCode := userService.ChangePassword(u, params.NewPassword)
if errCode != ecode.OK {
ctx.Fail(errCode)
@@ -227,6 +207,7 @@
}
// GetUserList
+//
// @Tags User
// @Summary 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�)
// @Produce application/json
@@ -253,6 +234,7 @@
}
// DeleteUser
+//
// @Tags User
// @Summary 鍒犻櫎鐢ㄦ埛
// @Produce application/json
@@ -287,6 +269,7 @@
}
// SetUserInfo
+//
// @Tags User
// @Summary 璁剧疆鐢ㄦ埛淇℃伅
// @Produce application/json
@@ -301,7 +284,7 @@
}
err := userService.SetUserInfo(model.User{
- ID: params.ID,
+ UUID: params.ID,
NickName: params.NickName,
HeaderImg: params.HeaderImg,
Phone: params.Phone,
@@ -317,6 +300,7 @@
}
// SetSelfInfo
+//
// @Tags User
// @Summary 璁剧疆鐢ㄦ埛淇℃伅
// @Produce application/json
@@ -332,7 +316,7 @@
params.ID = utils.GetUserID(c)
err := userService.SetUserInfo(model.User{
- ID: params.ID,
+ UUID: params.ID,
NickName: params.NickName,
HeaderImg: params.HeaderImg,
Phone: params.Phone,
@@ -348,6 +332,7 @@
}
// GetUserInfo
+//
// @Tags User
// @Summary 鑾峰彇鑷韩淇℃伅
// @Produce application/json
@@ -372,6 +357,7 @@
}
// ResetPassword
+//
// @Tags User
// @Summary 閲嶇疆鐢ㄦ埛瀵嗙爜
// @Produce application/json
@@ -385,7 +371,7 @@
return
}
- err := userService.ResetPassword(params.ID)
+ err := userService.ResetPassword(params.UUID)
if err != nil {
logx.Errorf("閲嶇疆澶辫触! err:%v", err)
ctx.Fail(ecode.DBErr)
--
Gitblit v1.8.0