From 5fac03fb857cf9a160e1736a25de2c5f95f5e44f Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期二, 18 七月 2023 17:18:18 +0800
Subject: [PATCH] add

---
 api/v1/user.go |  116 +++++++++++++++++++++++++--------------------------------
 1 files changed, 51 insertions(+), 65 deletions(-)

diff --git a/api/v1/user.go b/api/v1/user.go
index 99534cf..a791a7d 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.ID, 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.ID,
+		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{ID: 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
@@ -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
@@ -317,6 +300,7 @@
 }
 
 // SetSelfInfo
+//
 //	@Tags		User
 //	@Summary	璁剧疆鐢ㄦ埛淇℃伅
 //	@Produce	application/json
@@ -348,6 +332,7 @@
 }
 
 // GetUserInfo
+//
 //	@Tags		User
 //	@Summary	鑾峰彇鑷韩淇℃伅
 //	@Produce	application/json
@@ -372,6 +357,7 @@
 }
 
 // ResetPassword
+//
 //	@Tags		User
 //	@Summary	閲嶇疆鐢ㄦ埛瀵嗙爜
 //	@Produce	application/json

--
Gitblit v1.8.0