|
@@ -52,6 +52,20 @@ func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.A
|
|
|
|
|
|
// AuthCode 判断此手机号是否有账号存在 鉴定验证码 用户信息存入redis 并返回Token
|
|
|
func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (string, *http_model.CodeLoginData, error) {
|
|
|
+
|
|
|
+ // 1. 验证码校验
|
|
|
+ vcode, err := l.getSessionCode(ctx, phone)
|
|
|
+ if err != nil {
|
|
|
+ return "", nil, err
|
|
|
+ }
|
|
|
+ fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, code)
|
|
|
+ if vcode != code {
|
|
|
+ // 验证码错误
|
|
|
+ logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
|
|
|
+ return "验证码有误", nil, errors.New("auth fail")
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询是否存在用户信息,存在则取出,不存在则注册并取出
|
|
|
var userData *gorm_model.YounggeeUser
|
|
|
user, err := db.GetUserByPhone(ctx, phone)
|
|
|
fmt.Println("login_auth", user, err)
|
|
@@ -81,32 +95,22 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (st
|
|
|
} else if user != nil {
|
|
|
userData = user
|
|
|
}
|
|
|
- vcode, err := l.getSessionCode(ctx, phone)
|
|
|
- if err != nil {
|
|
|
- return "", nil, err
|
|
|
- }
|
|
|
- fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, code)
|
|
|
- if vcode != code {
|
|
|
- // 验证码错误
|
|
|
- logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
|
|
|
- return "验证码有误", nil, errors.New("auth fail")
|
|
|
- }
|
|
|
- token := l.getToken(ctx, phone)
|
|
|
|
|
|
- var jobData *gorm_model.YounggeeJob
|
|
|
- var accountData *gorm_model.YounggeeSubAccount
|
|
|
- accountData.SubAccountId = 0
|
|
|
- accountData.EnterpriseId = "-1"
|
|
|
- jobData.JobName = "-1"
|
|
|
- jobData.WorkshopPermission = "-1"
|
|
|
- jobData.CooperatePermission = "-1"
|
|
|
- jobData.FinancialPermission = "-1"
|
|
|
- jobData.TaskcenterPermission = "-1"
|
|
|
+ token := l.getToken(ctx, phone)
|
|
|
+ var jobData gorm_model.YounggeeJob
|
|
|
+ var accountData gorm_model.YounggeeSubAccount
|
|
|
+ var enterpriseUser gorm_model.Enterprise
|
|
|
+ var loginUserData http_model.CodeLoginData
|
|
|
+ var ifEnterprise int = 0
|
|
|
+ var ifSubAccount int = 0
|
|
|
|
|
|
+ // 3. 根据用户类型的不同补充信息
|
|
|
// 若为商家用户
|
|
|
if string(userData.Role) == consts.BRole {
|
|
|
+ ifEnterprise = 1
|
|
|
fmt.Println("商家主账号")
|
|
|
enterprise, err := db.GetEnterpriseByUID(ctx, userData.ID)
|
|
|
+ enterpriseUser = *enterprise
|
|
|
if err != nil {
|
|
|
return "", nil, err
|
|
|
}
|
|
@@ -127,9 +131,10 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (st
|
|
|
}
|
|
|
} else {
|
|
|
// 若为商家子账号
|
|
|
+ ifSubAccount = 1
|
|
|
fmt.Printf("商家子账号")
|
|
|
subaccount, err := db.FindSubAccountByPhone(ctx, phone)
|
|
|
- accountData = subaccount
|
|
|
+ accountData = *subaccount
|
|
|
if err != nil {
|
|
|
return "", nil, err
|
|
|
}
|
|
@@ -146,24 +151,39 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (st
|
|
|
}
|
|
|
|
|
|
job, err := db.FindJobByJobId(ctx, subaccount.JobId)
|
|
|
- jobData = job
|
|
|
+ jobData = *job
|
|
|
if err := l.setSession(ctx, phone, auth); err != nil {
|
|
|
fmt.Printf("setSession error\n")
|
|
|
return "", nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- loginUserData := http_model.CodeLoginData{
|
|
|
- UserId: userData.ID,
|
|
|
- Token: token,
|
|
|
- Role: userData.Role,
|
|
|
- SubAccountId: accountData.SubAccountId,
|
|
|
- JobName: jobData.JobName,
|
|
|
- EnterpriseId: accountData.EnterpriseId,
|
|
|
- WorkshopPermission: jobData.WorkshopPermission,
|
|
|
- CooperatePermission: jobData.CooperatePermission,
|
|
|
- FinancialPermission: jobData.FinancialPermission,
|
|
|
- TaskcenterPermission: jobData.TaskcenterPermission,
|
|
|
+ if ifEnterprise == 1 {
|
|
|
+ loginUserData = http_model.CodeLoginData{
|
|
|
+ UserId: userData.ID,
|
|
|
+ Token: token,
|
|
|
+ Role: userData.Role,
|
|
|
+ SubAccountId: -1,
|
|
|
+ JobName: "-1",
|
|
|
+ EnterpriseId: enterpriseUser.EnterpriseID,
|
|
|
+ WorkshopPermission: "-1",
|
|
|
+ CooperatePermission: "-1",
|
|
|
+ FinancialPermission: "-1",
|
|
|
+ TaskcenterPermission: "-1",
|
|
|
+ }
|
|
|
+ } else if ifSubAccount == 1 {
|
|
|
+ loginUserData = http_model.CodeLoginData{
|
|
|
+ UserId: userData.ID,
|
|
|
+ Token: token,
|
|
|
+ Role: userData.Role,
|
|
|
+ SubAccountId: accountData.SubAccountId,
|
|
|
+ JobName: jobData.JobName,
|
|
|
+ EnterpriseId: accountData.EnterpriseId,
|
|
|
+ WorkshopPermission: jobData.WorkshopPermission,
|
|
|
+ CooperatePermission: jobData.CooperatePermission,
|
|
|
+ FinancialPermission: jobData.FinancialPermission,
|
|
|
+ TaskcenterPermission: jobData.TaskcenterPermission,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return "", &loginUserData, nil
|