Xingyu Xian 1 долоо хоног өмнө
parent
commit
5733883dcf
1 өөрчлөгдсөн 7 нэмэгдсэн , 5 устгасан
  1. 7 5
      service/login_auth.go

+ 7 - 5
service/login_auth.go

@@ -98,7 +98,7 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 		userData = userInfo
 	}
 
-	token := l.getToken(ctx, phone)
+	token := l.getToken(ctx, phone, userData.Role)
 	var jobData gorm_model.YounggeeJob
 	var accountData gorm_model.YounggeeSubAccount
 	var enterpriseUser gorm_model.Enterprise
@@ -127,7 +127,8 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 				Token:        token,
 				EnterpriseID: enterpriseUserInfo.EnterpriseID,
 			}
-			if sessionErr := l.setSession(ctx, phone, auth); sessionErr != nil {
+			key := phone + userData.Role
+			if sessionErr := l.setSession(ctx, key, auth); sessionErr != nil {
 				fmt.Printf("setSession error\n")
 				return 0, nil, sessionErr
 			}
@@ -159,7 +160,8 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 			}
 			if jobInfo != nil {
 				jobData = *jobInfo
-				if sessionErr := l.setSession(ctx, phone, auth); sessionErr != nil {
+				key := phone + userData.Role
+				if sessionErr := l.setSession(ctx, key, auth); sessionErr != nil {
 					fmt.Printf("setSession error\n")
 					return 0, nil, sessionErr
 				}
@@ -264,9 +266,9 @@ func (l *loginAuth) getSessionAuth(ctx context.Context, phone string) (*redis_mo
 	return auth, nil
 }
 
-func (l *loginAuth) getToken(ctx context.Context, phone string) string {
+func (l *loginAuth) getToken(ctx context.Context, phone string, role string) string {
 	timeSeed := strconv.FormatInt(time.Now().Unix(), 10)
-	token := phone + "." + timeSeed + "." + util.MD5(phone, timeSeed, consts.AuthSalt)
+	token := phone + role + "." + timeSeed + "." + util.MD5(phone+role, timeSeed, consts.AuthSalt)
 	return token
 }