From 4a23356a5840b624c81dda44b0028ed8fc3656cc Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 13 十月 2023 11:14:25 +0800
Subject: [PATCH] 销售线索简单数据权限
---
api/v1/captcha.go | 104 ++---
api/v1/salesLeads.go | 9
router/image.go | 31
middleware/jwt.go | 11
router/base.go | 32
utils/clamis.go | 24 -
model/user.go | 2
api/v1/user.go | 723 ++++++++++++++++++++---------------------
router/index.go | 16
model/request/jwt.go | 2
router/user.go | 48 +-
11 files changed, 488 insertions(+), 514 deletions(-)
diff --git a/api/v1/captcha.go b/api/v1/captcha.go
index 4be71ca..124ed57 100644
--- a/api/v1/captcha.go
+++ b/api/v1/captcha.go
@@ -1,62 +1,50 @@
package v1
-import (
- "aps_crm/conf"
- "aps_crm/constvar"
- "aps_crm/model/response"
- "aps_crm/pkg/contextx"
- "aps_crm/pkg/convertx"
- "aps_crm/pkg/ecode"
- "aps_crm/pkg/logx"
- "github.com/gin-gonic/gin"
- "github.com/mojocn/base64Captcha"
- "time"
-)
-
type BaseApi struct{}
-// Captcha
-// @Tags Base
-// @Summary 鑾峰彇楠岃瘉鐮�
-// @Produce application/json
-// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛"
-// @Router /api/base/captcha [post]
-func (slf *BaseApi) Captcha(c *gin.Context) {
- ctx, ok := contextx.NewContext(c, nil)
- if !ok {
- return
- }
-
- // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚�
- openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁�
- openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿
- key := c.ClientIP()
- v, ok := constvar.BlackCache.Get(key)
- if !ok {
- constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
- }
-
- var oc bool
- if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟
- oc = true
- }
- // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃�
- // 鐢熸垚榛樿鏁板瓧鐨刣river
- driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80)
- cp := base64Captcha.NewCaptcha(driver, store)
- id, b64s, err := cp.Generate()
- captcha := store.Get(id, false)
- logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha)
- if err != nil {
- logx.Errorf("Captcha Generate err:%v", err)
- ctx.Fail(ecode.CaptchaGenerateFailed)
- return
- }
-
- ctx.OkWithDetailed(response.CaptchaResponse{
- CaptchaId: id,
- PicPath: b64s,
- CaptchaLength: conf.Conf.Captcha.KeyLong,
- OpenCaptcha: oc,
- })
-}
+//
+//// Captcha
+//// @Tags Base
+//// @Summary 鑾峰彇楠岃瘉鐮�
+//// @Produce application/json
+//// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛"
+//// @Router /api/base/captcha [post]
+//func (slf *BaseApi) Captcha(c *gin.Context) {
+// ctx, ok := contextx.NewContext(c, nil)
+// if !ok {
+// return
+// }
+//
+// // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚�
+// openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁�
+// openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿
+// key := c.ClientIP()
+// v, ok := constvar.BlackCache.Get(key)
+// if !ok {
+// constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
+// }
+//
+// var oc bool
+// if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟
+// oc = true
+// }
+// // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃�
+// // 鐢熸垚榛樿鏁板瓧鐨刣river
+// driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80)
+// cp := base64Captcha.NewCaptcha(driver, store)
+// id, b64s, err := cp.Generate()
+// captcha := store.Get(id, false)
+// logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha)
+// if err != nil {
+// logx.Errorf("Captcha Generate err:%v", err)
+// ctx.Fail(ecode.CaptchaGenerateFailed)
+// return
+// }
+//
+// ctx.OkWithDetailed(response.CaptchaResponse{
+// CaptchaId: id,
+// PicPath: b64s,
+// CaptchaLength: conf.Conf.Captcha.KeyLong,
+// OpenCaptcha: oc,
+// })
+//}
diff --git a/api/v1/salesLeads.go b/api/v1/salesLeads.go
index 1e751b5..fb44f74 100644
--- a/api/v1/salesLeads.go
+++ b/api/v1/salesLeads.go
@@ -7,6 +7,7 @@
"aps_crm/model/response"
"aps_crm/pkg/contextx"
"aps_crm/pkg/ecode"
+ "aps_crm/utils"
"github.com/gin-gonic/gin"
)
@@ -152,6 +153,14 @@
return
}
+ userInfo := utils.GetUserInfo(c)
+ if userInfo.UserType == constvar.UserTypeSub {
+ if params.SearchMap == nil {
+ params.SearchMap = make(map[string]interface{}, 0)
+ }
+ params.SearchMap["member_id"] = userInfo.CrmUserId
+ }
+
salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.SearchMap)
if errCode != ecode.OK {
ctx.Fail(errCode)
diff --git a/api/v1/user.go b/api/v1/user.go
index 9cd713c..76fecfc 100644
--- a/api/v1/user.go
+++ b/api/v1/user.go
@@ -1,381 +1,364 @@
package v1
-import (
- "aps_crm/conf"
- "aps_crm/constvar"
- "aps_crm/model"
- "aps_crm/model/request"
- "aps_crm/model/response"
- "aps_crm/pkg/contextx"
- "aps_crm/pkg/ecode"
- "aps_crm/pkg/encrypt"
- "aps_crm/pkg/logx"
- "aps_crm/pkg/snowflake"
- "aps_crm/utils"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-redis/redis/v8"
- "github.com/mojocn/base64Captcha"
-)
-
-// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮�
-// var store = captcha.NewDefaultRedisStore()
-var store = base64Captcha.DefaultMemStore
-
-// Login
//
-// @Tags Base
-// @Summary 鐢ㄦ埛鐧诲綍
-// @Produce application/json
-// @Param object body request.Login true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛"
-// @Router /api/base/login [post]
-func (slf *BaseApi) Login(c *gin.Context) {
- var params request.Login
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚�
- 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))
- //}
-
- //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
- }
- // 璧嬪�艰彍鍗旾D鍒楄〃
- //user.MenuIds, _ = menuService.GetUserMenuIds(user.UUID, user.UserType)
- slf.TokenNext(ctx, *user)
- return
- //}
-
- // 楠岃瘉鐮佹鏁�+1
- //_ = constvar.BlackCache.Increment(key, 1)
- //ctx.Fail(ecode.CaptchaErr)
-}
-
-// TokenNext 鐧诲綍浠ュ悗绛惧彂jwt
-func (slf *BaseApi) TokenNext(ctx *contextx.Context, user model.User) {
- logx.Infof("TokenNext user:%+v", user)
- j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕
- claims := j.CreateClaims(request.BaseClaims{
- UserId: user.UUID,
- Username: user.Username,
- UserType: user.UserType,
- AuthorityId: user.AuthorityId,
- })
- token, err := j.CreateToken(claims)
- if err != nil {
- logx.Errorf("鍒涘缓token澶辫触! err:%v", err)
- ctx.Fail(ecode.CreateTokenErr)
- return
- }
- if !conf.Conf.System.UseMultipoint { // 涓嶅厑璁稿鐐圭櫥褰�
- ctx.OkWithDetailed(response.LoginResponse{
- User: user,
- Token: token,
- //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
- })
- return
- }
-
- if jwtStr, err := jwtService.GetRedisJWT(user.Username); err == redis.Nil { // redis鏃燡WT鏁版嵁
- if err := jwtService.SetRedisJWT(token, user.Username); err != nil {
- logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err)
- ctx.Fail(ecode.RedisErr)
- return
- }
- ctx.OkWithDetailed(response.LoginResponse{
- User: user,
- Token: token,
- //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
- })
- } else if err != nil { // redis鑾峰彇JWT鎶ラ敊
- logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err)
- ctx.Fail(ecode.RedisErr)
- } else { // 鎴愬姛鑾峰彇redis鐨凧WT锛屾棫鐨勪綔搴�
- var blackJWT model.JwtBlacklist
- blackJWT.Jwt = jwtStr
- if err := jwtService.JsonInBlacklist(blackJWT); err != nil {
- ctx.Fail(ecode.DBErr)
- return
- }
- if err := jwtService.SetRedisJWT(token, user.Username); err != nil {
- ctx.Fail(ecode.RedisErr)
- return
- }
- ctx.OkWithDetailed(response.LoginResponse{
- User: user,
- Token: token,
- //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
- })
- }
-}
-
-// Register
+//// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮�
+//// var store = captcha.NewDefaultRedisStore()
+//var store = base64Captcha.DefaultMemStore
//
-// @Tags User
-// @Summary 娉ㄥ唽璐﹀彿
-// @Produce application/json
-// @Param object body request.Register true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{data=response.UserResponse} "鎴愬姛"
-// @Router /api/user/register [post]
-func (slf *BaseApi) Register(c *gin.Context) {
- var params request.Register
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- userInfo := utils.GetUserInfo(c)
- if len(userInfo.UserId) <= 0 {
- ctx.Fail(ecode.UnknownErr)
- return
- }
-
- 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
- }
-
- var userId = fmt.Sprintf("u%v", snowflake.GenerateId())
- var passWord = encrypt.BcryptHash(params.Password)
- var userType constvar.UserType
-
- 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
- // }
- //}
-
- ctx.OkWithDetailed(response.UserResponse{User: *userReturn})
-}
-
-// ChangePassword
+//// Login
+////
+//// @Tags Base
+//// @Summary 鐢ㄦ埛鐧诲綍
+//// @Produce application/json
+//// @Param object body request.Login true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛"
+//// @Router /api/base/login [post]
+//func (slf *BaseApi) Login(c *gin.Context) {
+// var params request.Login
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
//
-// @Tags User
-// @Summary 鐢ㄦ埛淇敼瀵嗙爜
-// @Produce application/json
-// @Param object body request.ChangePasswordReq true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/changePassword [post]
-func (slf *BaseApi) ChangePassword(c *gin.Context) {
- var params request.ChangePasswordReq
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- u := &model.User{UUID: utils.GetUserID(c), Password: params.Password}
- _, errCode := userService.ChangePassword(u, params.NewPassword)
- if errCode != ecode.OK {
- ctx.Fail(errCode)
- return
- }
- ctx.Ok()
-}
-
-// GetUserList
+// // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚�
+// 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))
+// //}
//
-// @Tags User
-// @Summary 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�)
-// @Produce application/json
-// @Param object body request.GetUserList true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{data=response.PageResult} "鎴愬姛"
-// @Router /api/user/getUserList [post]
-func (slf *BaseApi) GetUserList(c *gin.Context) {
- var params request.GetUserList
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- userInfo := utils.GetUserInfo(c)
- if len(userInfo.UserId) <= 0 || len(userInfo.ParentId) == 0 {
- ctx.Fail(ecode.UnknownErr)
- return
- }
-
- ctx.OkWithDetailed(response.PageResult{
- Page: params.Page,
- PageSize: params.PageSize,
- })
-}
-
-// DeleteUser
+// //var oc = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃叉毚娆℃暟
//
-// @Tags User
-// @Summary 鍒犻櫎鐢ㄦ埛
-// @Produce application/json
-// @Param object body request.DeleteUserReq true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/deleteUser [delete]
-func (slf *BaseApi) DeleteUser(c *gin.Context) {
- var params request.DeleteUserReq
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- if len(params.UserId) <= 0 {
- ctx.Fail(ecode.ParamsErr)
- return
- }
-
- userInfo := utils.GetUserInfo(c)
- if userInfo.UserType != constvar.UserTypePrimary || userInfo.UserId == params.UserId {
- ctx.Fail(ecode.NoPowerErr)
- return
- }
-
- err := userService.DeleteUser(params.UserId)
- if err != nil {
- logx.Errorf("鍒犻櫎澶辫触! err:%v", err)
- ctx.Fail(ecode.DBErr)
- return
- }
- ctx.Ok()
-}
-
-// SetUserInfo
+// //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
+// //}
//
-// @Tags User
-// @Summary 璁剧疆鐢ㄦ埛淇℃伅
-// @Produce application/json
-// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/setUserInfo [post]
-func (slf *BaseApi) SetUserInfo(c *gin.Context) {
- var params request.ChangeUserInfo
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- err := userService.SetUserInfo(model.User{
- UUID: params.ID,
- NickName: params.NickName,
- HeaderImg: params.HeaderImg,
- Phone: params.Phone,
- Email: params.Email,
- Pos: params.Pos,
- })
- if err != nil {
- logx.Errorf("璁剧疆澶辫触! err:%v", err)
- ctx.Fail(ecode.DBErr)
- return
- }
- ctx.Ok()
-}
-
-// SetSelfInfo
+// // 楠岃瘉鐮佹鏁�+1
+// //_ = constvar.BlackCache.Increment(key, 1)
+// //ctx.Fail(ecode.CaptchaErr)
+//}
//
-// @Tags User
-// @Summary 璁剧疆鐢ㄦ埛淇℃伅
-// @Produce application/json
-// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/setSelfInfo [post]
-func (slf *BaseApi) SetSelfInfo(c *gin.Context) {
- var params request.ChangeUserInfo
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- params.ID = utils.GetUserID(c)
- err := userService.SetUserInfo(model.User{
- UUID: params.ID,
- NickName: params.NickName,
- HeaderImg: params.HeaderImg,
- Phone: params.Phone,
- Email: params.Email,
- Pos: params.Pos,
- })
- if err != nil {
- logx.Errorf("璁剧疆澶辫触! err:%v", err)
- ctx.Fail(ecode.DBErr)
- return
- }
- ctx.Ok()
-}
-
-// GetUserInfo
+//// TokenNext 鐧诲綍浠ュ悗绛惧彂jwt
+//func (slf *BaseApi) TokenNext(ctx *contextx.Context, user model.User) {
+// logx.Infof("TokenNext user:%+v", user)
+// j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕
+// claims := j.CreateClaims(request.BaseClaims{
+// UserId: user.UUID,
+// Username: user.Username,
+// UserType: user.UserType,
+// AuthorityId: user.AuthorityId,
+// })
+// token, err := j.CreateToken(claims)
+// if err != nil {
+// logx.Errorf("鍒涘缓token澶辫触! err:%v", err)
+// ctx.Fail(ecode.CreateTokenErr)
+// return
+// }
+// if !conf.Conf.System.UseMultipoint { // 涓嶅厑璁稿鐐圭櫥褰�
+// ctx.OkWithDetailed(response.LoginResponse{
+// User: user,
+// Token: token,
+// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
+// })
+// return
+// }
//
-// @Tags User
-// @Summary 鑾峰彇鑷韩淇℃伅
-// @Produce application/json
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/getUserInfo [post]
-func (slf *BaseApi) GetUserInfo(c *gin.Context) {
- ctx, ok := contextx.NewContext(c, nil)
- if !ok {
- return
- }
-
- id := utils.GetUserID(c)
- ReqUser, err := userService.GetUserInfo(id)
- if err != nil {
- logx.Errorf("鑾峰彇澶辫触! err:%v", err)
- ctx.Fail(ecode.DBErr)
- return
- }
- ctx.OkWithDetailed(response.UserResponse{
- User: *ReqUser,
- })
-}
-
-// ResetPassword
+// if jwtStr, err := jwtService.GetRedisJWT(user.Username); err == redis.Nil { // redis鏃燡WT鏁版嵁
+// if err := jwtService.SetRedisJWT(token, user.Username); err != nil {
+// logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err)
+// ctx.Fail(ecode.RedisErr)
+// return
+// }
+// ctx.OkWithDetailed(response.LoginResponse{
+// User: user,
+// Token: token,
+// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
+// })
+// } else if err != nil { // redis鑾峰彇JWT鎶ラ敊
+// logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err)
+// ctx.Fail(ecode.RedisErr)
+// } else { // 鎴愬姛鑾峰彇redis鐨凧WT锛屾棫鐨勪綔搴�
+// var blackJWT model.JwtBlacklist
+// blackJWT.Jwt = jwtStr
+// if err := jwtService.JsonInBlacklist(blackJWT); err != nil {
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// if err := jwtService.SetRedisJWT(token, user.Username); err != nil {
+// ctx.Fail(ecode.RedisErr)
+// return
+// }
+// ctx.OkWithDetailed(response.LoginResponse{
+// User: user,
+// Token: token,
+// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
+// })
+// }
+//}
//
-// @Tags User
-// @Summary 閲嶇疆鐢ㄦ埛瀵嗙爜
-// @Produce application/json
-// @Param object body model.User true "鏌ヨ鍙傛暟"
-// @Success 200 {object} contextx.Response{} "鎴愬姛"
-// @Router /api/user/resetPassword [post]
-func (slf *BaseApi) ResetPassword(c *gin.Context) {
- var params model.User
- ctx, ok := contextx.NewContext(c, ¶ms)
- if !ok {
- return
- }
-
- err := userService.ResetPassword(params.UUID)
- if err != nil {
- logx.Errorf("閲嶇疆澶辫触! err:%v", err)
- ctx.Fail(ecode.DBErr)
- return
- }
- ctx.Ok()
-}
+//// Register
+////
+//// @Tags User
+//// @Summary 娉ㄥ唽璐﹀彿
+//// @Produce application/json
+//// @Param object body request.Register true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{data=response.UserResponse} "鎴愬姛"
+//// @Router /api/user/register [post]
+//func (slf *BaseApi) Register(c *gin.Context) {
+// var params request.Register
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// userInfo := utils.GetUserInfo(c)
+// if len(userInfo.UserId) <= 0 {
+// ctx.Fail(ecode.UnknownErr)
+// return
+// }
+//
+// 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
+// }
+//
+// var userId = fmt.Sprintf("u%v", snowflake.GenerateId())
+// var passWord = encrypt.BcryptHash(params.Password)
+// var userType constvar.UserType
+//
+// 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
+// // }
+// //}
+//
+// ctx.OkWithDetailed(response.UserResponse{User: *userReturn})
+//}
+//
+//// ChangePassword
+////
+//// @Tags User
+//// @Summary 鐢ㄦ埛淇敼瀵嗙爜
+//// @Produce application/json
+//// @Param object body request.ChangePasswordReq true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/changePassword [post]
+//func (slf *BaseApi) ChangePassword(c *gin.Context) {
+// var params request.ChangePasswordReq
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// u := &model.User{UUID: utils.GetUserID(c), Password: params.Password}
+// _, errCode := userService.ChangePassword(u, params.NewPassword)
+// if errCode != ecode.OK {
+// ctx.Fail(errCode)
+// return
+// }
+// ctx.Ok()
+//}
+//
+//// GetUserList
+////
+//// @Tags User
+//// @Summary 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�)
+//// @Produce application/json
+//// @Param object body request.GetUserList true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{data=response.PageResult} "鎴愬姛"
+//// @Router /api/user/getUserList [post]
+//func (slf *BaseApi) GetUserList(c *gin.Context) {
+// var params request.GetUserList
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// userInfo := utils.GetUserInfo(c)
+// if len(userInfo.UserId) <= 0 || len(userInfo.ParentId) == 0 {
+// ctx.Fail(ecode.UnknownErr)
+// return
+// }
+//
+// ctx.OkWithDetailed(response.PageResult{
+// Page: params.Page,
+// PageSize: params.PageSize,
+// })
+//}
+//
+//// DeleteUser
+////
+//// @Tags User
+//// @Summary 鍒犻櫎鐢ㄦ埛
+//// @Produce application/json
+//// @Param object body request.DeleteUserReq true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/deleteUser [delete]
+//func (slf *BaseApi) DeleteUser(c *gin.Context) {
+// var params request.DeleteUserReq
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// if len(params.UserId) <= 0 {
+// ctx.Fail(ecode.ParamsErr)
+// return
+// }
+//
+// userInfo := utils.GetUserInfo(c)
+// if userInfo.UserType != constvar.UserTypePrimary || userInfo.UserId == params.UserId {
+// ctx.Fail(ecode.NoPowerErr)
+// return
+// }
+//
+// err := userService.DeleteUser(params.UserId)
+// if err != nil {
+// logx.Errorf("鍒犻櫎澶辫触! err:%v", err)
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// ctx.Ok()
+//}
+//
+//// SetUserInfo
+////
+//// @Tags User
+//// @Summary 璁剧疆鐢ㄦ埛淇℃伅
+//// @Produce application/json
+//// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/setUserInfo [post]
+//func (slf *BaseApi) SetUserInfo(c *gin.Context) {
+// var params request.ChangeUserInfo
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// err := userService.SetUserInfo(model.User{
+// UUID: params.ID,
+// NickName: params.NickName,
+// HeaderImg: params.HeaderImg,
+// Phone: params.Phone,
+// Email: params.Email,
+// Pos: params.Pos,
+// })
+// if err != nil {
+// logx.Errorf("璁剧疆澶辫触! err:%v", err)
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// ctx.Ok()
+//}
+//
+//// SetSelfInfo
+////
+//// @Tags User
+//// @Summary 璁剧疆鐢ㄦ埛淇℃伅
+//// @Produce application/json
+//// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/setSelfInfo [post]
+//func (slf *BaseApi) SetSelfInfo(c *gin.Context) {
+// var params request.ChangeUserInfo
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// params.ID = utils.GetUserID(c)
+// err := userService.SetUserInfo(model.User{
+// UUID: params.ID,
+// NickName: params.NickName,
+// HeaderImg: params.HeaderImg,
+// Phone: params.Phone,
+// Email: params.Email,
+// Pos: params.Pos,
+// })
+// if err != nil {
+// logx.Errorf("璁剧疆澶辫触! err:%v", err)
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// ctx.Ok()
+//}
+//
+//// GetUserInfo
+////
+//// @Tags User
+//// @Summary 鑾峰彇鑷韩淇℃伅
+//// @Produce application/json
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/getUserInfo [post]
+//func (slf *BaseApi) GetUserInfo(c *gin.Context) {
+// ctx, ok := contextx.NewContext(c, nil)
+// if !ok {
+// return
+// }
+//
+// id := utils.GetUserID(c)
+// ReqUser, err := userService.GetUserInfo(id)
+// if err != nil {
+// logx.Errorf("鑾峰彇澶辫触! err:%v", err)
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// ctx.OkWithDetailed(response.UserResponse{
+// User: *ReqUser,
+// })
+//}
+//
+//// ResetPassword
+////
+//// @Tags User
+//// @Summary 閲嶇疆鐢ㄦ埛瀵嗙爜
+//// @Produce application/json
+//// @Param object body model.User true "鏌ヨ鍙傛暟"
+//// @Success 200 {object} contextx.Response{} "鎴愬姛"
+//// @Router /api/user/resetPassword [post]
+//func (slf *BaseApi) ResetPassword(c *gin.Context) {
+// var params model.User
+// ctx, ok := contextx.NewContext(c, ¶ms)
+// if !ok {
+// return
+// }
+//
+// err := userService.ResetPassword(params.UUID)
+// if err != nil {
+// logx.Errorf("閲嶇疆澶辫触! err:%v", err)
+// ctx.Fail(ecode.DBErr)
+// return
+// }
+// ctx.Ok()
+//}
diff --git a/middleware/jwt.go b/middleware/jwt.go
index 0a7e688..ec143b0 100644
--- a/middleware/jwt.go
+++ b/middleware/jwt.go
@@ -105,11 +105,14 @@
c.Next()
return
}
- c.Set("claims", claims)
userInfo := service.GetUserBaseCache(claims.UserId)
- c.Set("user_id", userInfo.UserId)
- c.Set("user_name", userInfo.NickName)
-
+ if userInfo == nil {
+ SyncUserInfo()
+ userInfo = service.GetUserBaseCache(claims.UserId)
+ }
+ claims.CrmUserId = userInfo.UserId
+ claims.NickName = userInfo.NickName
+ c.Set("claims", claims)
if CheckAuth(c.Request.RequestURI, token) {
c.Next()
} else {
diff --git a/model/request/jwt.go b/model/request/jwt.go
index 1b2f444..e67ab55 100644
--- a/model/request/jwt.go
+++ b/model/request/jwt.go
@@ -10,6 +10,8 @@
BaseClaims
BufferTime int64
jwt.StandardClaims
+ CrmUserId int
+ NickName string
}
type BaseClaims struct {
diff --git a/model/user.go b/model/user.go
index 6cbf77f..925d6d7 100644
--- a/model/user.go
+++ b/model/user.go
@@ -89,7 +89,7 @@
var db = slf.Orm.Model(&User{}).Preload("Menus")
if slf.UUID != "" {
- db = db.Where("id = ?", slf.UUID)
+ db = db.Where("uuid = ?", slf.UUID)
}
if slf.Username != "" {
diff --git a/router/base.go b/router/base.go
index 6b05fa6..32c786d 100644
--- a/router/base.go
+++ b/router/base.go
@@ -1,18 +1,18 @@
package router
-import (
- "aps_crm/api/v1"
- "github.com/gin-gonic/gin"
-)
-
-type BaseRouter struct{}
-
-func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
- baseRouter := Router.Group("base")
- baseApi := v1.ApiGroup.BaseApi
- {
- baseRouter.POST("login", baseApi.Login) // 鐢ㄦ埛鐧诲綍
- baseRouter.POST("captcha", baseApi.Captcha) // 鑾峰彇楠岃瘉鐮�
- }
- return baseRouter
-}
+//import (
+// "aps_crm/api/v1"
+// "github.com/gin-gonic/gin"
+//)
+//
+//type BaseRouter struct{}
+//
+//func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
+// baseRouter := Router.Group("base")
+// baseApi := v1.ApiGroup.BaseApi
+// {
+// baseRouter.POST("login", baseApi.Login) // 鐢ㄦ埛鐧诲綍
+// baseRouter.POST("captcha", baseApi.Captcha) // 鑾峰彇楠岃瘉鐮�
+// }
+// return baseRouter
+//}
diff --git a/router/image.go b/router/image.go
index af08f81..41b64c1 100644
--- a/router/image.go
+++ b/router/image.go
@@ -1,17 +1,18 @@
package router
-import (
- "aps_crm/api/v1"
- "github.com/gin-gonic/gin"
-)
-
-type ImageRouter struct{}
-
-func (s *BaseRouter) InitImageRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
- imageRouter := Router.Group("image")
- imageApi := v1.ApiGroup.ImageApi
- {
- imageRouter.POST("upload", imageApi.Upload) // 涓婁紶鍥惧儚
- }
- return imageRouter
-}
+//
+//import (
+// "aps_crm/api/v1"
+// "github.com/gin-gonic/gin"
+//)
+//
+//type ImageRouter struct{}
+//
+//func (s *BaseRouter) InitImageRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
+// imageRouter := Router.Group("image")
+// imageApi := v1.ApiGroup.ImageApi
+// {
+// imageRouter.POST("upload", imageApi.Upload) // 涓婁紶鍥惧儚
+// }
+// return imageRouter
+//}
diff --git a/router/index.go b/router/index.go
index 2c3d5b3..9bccebb 100644
--- a/router/index.go
+++ b/router/index.go
@@ -27,8 +27,8 @@
IsVisitRouter
SolveRateRouter
TimelyRateRouter
- BaseRouter
- UserRouter
+ //BaseRouter
+ //UserRouter
JwtRouter
CountryRouter
ProvinceRouter
@@ -104,18 +104,18 @@
c.JSON(http.StatusOK, "ok")
})
}
- {
- routerGroup.InitBaseRouter(PublicGroup) // 娉ㄥ唽鍩虹鍔熻兘璺敱 涓嶅仛閴存潈
- routerGroup.InitImageRouter(PublicGroup) // 鍥惧儚鍔熻兘璺敱
- }
+ //{
+ // routerGroup.InitBaseRouter(PublicGroup) // 娉ㄥ唽鍩虹鍔熻兘璺敱 涓嶅仛閴存潈
+ // routerGroup.InitImageRouter(PublicGroup) // 鍥惧儚鍔熻兘璺敱
+ //}
PrivateGroup := Router.Group("api")
//PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
PrivateGroup.Use(middleware.JWTAuth2())
//PrivateGroup.Use(middleware.CasbinHandler())
{
- routerGroup.InitJwtRouter(PrivateGroup) // jwt鐩稿叧璺敱
- routerGroup.InitUserRouter(PrivateGroup) // 娉ㄥ唽鐢ㄦ埛璺敱
+ routerGroup.InitJwtRouter(PrivateGroup) // jwt鐩稿叧璺敱
+ //routerGroup.InitUserRouter(PrivateGroup) // 娉ㄥ唽鐢ㄦ埛璺敱
routerGroup.InitCountryRouter(PrivateGroup) // 娉ㄥ唽country璺敱
routerGroup.InitProvinceRouter(PrivateGroup) // 娉ㄥ唽province璺敱
routerGroup.InitCityRouter(PrivateGroup) // 娉ㄥ唽city璺敱
diff --git a/router/user.go b/router/user.go
index 5e624ea..9bc3f81 100644
--- a/router/user.go
+++ b/router/user.go
@@ -1,26 +1,26 @@
package router
-import (
- "aps_crm/api/v1"
- "github.com/gin-gonic/gin"
-)
-
-type UserRouter struct{}
-
-func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
- userRouter := Router.Group("user")
- userRouterWithoutRecord := Router.Group("user")
- baseApi := v1.ApiGroup.BaseApi
- {
- userRouter.POST("register", baseApi.Register) // 娉ㄥ唽璐﹀彿
- //userRouter.POST("changePassword", baseApi.ChangePassword) // 鐢ㄦ埛淇敼瀵嗙爜
- //userRouter.POST("resetPassword", baseApi.ResetPassword) // 閲嶇疆鐢ㄦ埛瀵嗙爜
- userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 鍒犻櫎鐢ㄦ埛
- userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 璁剧疆鐢ㄦ埛淇℃伅
- //userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 璁剧疆鑷韩淇℃伅
- }
- {
- userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�)
- userRouterWithoutRecord.GET("getUserInfo", baseApi.GetUserInfo) // 鑾峰彇鑷韩淇℃伅
- }
-}
+//import (
+// "aps_crm/api/v1"
+// "github.com/gin-gonic/gin"
+//)
+//
+//type UserRouter struct{}
+//
+//func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
+// userRouter := Router.Group("user")
+// userRouterWithoutRecord := Router.Group("user")
+// baseApi := v1.ApiGroup.BaseApi
+// {
+// userRouter.POST("register", baseApi.Register) // 娉ㄥ唽璐﹀彿
+// //userRouter.POST("changePassword", baseApi.ChangePassword) // 鐢ㄦ埛淇敼瀵嗙爜
+// //userRouter.POST("resetPassword", baseApi.ResetPassword) // 閲嶇疆鐢ㄦ埛瀵嗙爜
+// userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 鍒犻櫎鐢ㄦ埛
+// userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 璁剧疆鐢ㄦ埛淇℃伅
+// //userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 璁剧疆鑷韩淇℃伅
+// }
+// {
+// userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�)
+// userRouterWithoutRecord.GET("getUserInfo", baseApi.GetUserInfo) // 鑾峰彇鑷韩淇℃伅
+// }
+//}
diff --git a/utils/clamis.go b/utils/clamis.go
index 1e10801..305d0ce 100644
--- a/utils/clamis.go
+++ b/utils/clamis.go
@@ -22,30 +22,18 @@
return claims, err
}
-// GetUserID 浠嶨in鐨凜ontext涓幏鍙栦粠jwt瑙f瀽鍑烘潵鐨勭敤鎴稩D
-func GetUserID(c *gin.Context) string {
- if claims, exists := c.Get("claims"); !exists {
- if cl, err := GetClaims(c); err != nil {
- return ""
- } else {
- return cl.UserId
- }
- } else {
+func GetUserID(c *gin.Context) int {
+ if claims, exists := c.Get("claims"); exists {
waitUse := claims.(*request.CustomClaims)
- return waitUse.UserId
+ return waitUse.CrmUserId
}
+ return 0
}
-// GetUserInfo 浠嶨in鐨凜ontext涓幏鍙栦粠jwt瑙f瀽鍑烘潵鐨勭敤鎴蜂俊鎭�
func GetUserInfo(c *gin.Context) *request.CustomClaims {
- if claims, exists := c.Get("claims"); !exists {
- if cl, err := GetClaims(c); err != nil {
- return nil
- } else {
- return cl
- }
- } else {
+ if claims, exists := c.Get("claims"); exists {
waitUse := claims.(*request.CustomClaims)
return waitUse
}
+ return nil
}
--
Gitblit v1.8.0