|
@@ -36,7 +36,7 @@ func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.A
|
|
|
logrus.Debug("token格式错误:%+v", token)
|
|
|
return nil, err
|
|
|
}
|
|
|
- auth, err := l.getSession(ctx, phone)
|
|
|
+ auth, err := l.getSessionAuth(ctx, phone)
|
|
|
if err != nil {
|
|
|
logrus.Debug("获取session redis错误: token:%+v,err:%+v", token, err)
|
|
|
return nil, err
|
|
@@ -48,35 +48,43 @@ func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.A
|
|
|
return auth, nil
|
|
|
}
|
|
|
|
|
|
-func (l *loginAuth) AuthMSG(ctx context.Context, phone string, vcode string) (string, error) {
|
|
|
- // 验证是否存在
|
|
|
+func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (string, error) {
|
|
|
user, err := db.GetUserByPhone(ctx, phone)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
+ } else if user == nil {
|
|
|
+ // 账号不存在
|
|
|
+ logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
|
|
|
+ return "账号不存在", errors.New("auth fail")
|
|
|
+ } else if string(user.Role) != consts.BRole {
|
|
|
+ // 账号权限有误
|
|
|
+ logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
|
|
|
+ return "权限错误,请登录企业账号", errors.New("auth fail")
|
|
|
}
|
|
|
- code, err := l.getSessionCode(ctx, phone)
|
|
|
+ vcode, err := l.getSessionCode(ctx, phone)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
- if user == nil || string(user.Role) != consts.BRole || *code != vcode { // 登录失败
|
|
|
- logrus.Debugf("[AuthPassword] auth fail,phone:%+v", phone)
|
|
|
- return "", errors.New("auth fail")
|
|
|
+ if *vcode != code {
|
|
|
+ // 验证码错误
|
|
|
+ logrus.Debugf("[AuthCode] auth fail,phone:%+v", phone)
|
|
|
+ return "验证码有误", errors.New("auth fail")
|
|
|
}
|
|
|
- enterpriseID, err := db.GetEnterpriseByUID(ctx, user.ID)
|
|
|
+ token := l.getToken(ctx, phone)
|
|
|
+ enterprise, err := db.GetEnterpriseByUID(ctx, user.ID)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
- token := l.getToken(ctx, phone)
|
|
|
auth := &redis_model.Auth{
|
|
|
Phone: phone,
|
|
|
ID: user.ID,
|
|
|
- EnterpriseID: *enterpriseID,
|
|
|
User: user.User,
|
|
|
Username: user.Username,
|
|
|
RealName: user.RealName,
|
|
|
Role: user.Role,
|
|
|
Email: user.Email,
|
|
|
Token: token,
|
|
|
+ EnterpriseID: enterprise.EnterpriseID,
|
|
|
}
|
|
|
if err := l.setSession(ctx, phone, auth); err != nil {
|
|
|
fmt.Printf("setSession error\n")
|
|
@@ -135,7 +143,7 @@ func (l *loginAuth) getSessionCode(ctx context.Context, phone string) (*string,
|
|
|
return &value, nil
|
|
|
}
|
|
|
|
|
|
-func (l *loginAuth) getSession(ctx context.Context, phone string) (*redis_model.Auth, error) {
|
|
|
+func (l *loginAuth) getSessionAuth(ctx context.Context, phone string) (*redis_model.Auth, error) {
|
|
|
value, err := redis.Get(ctx, l.getRedisKey(phone))
|
|
|
if err != nil {
|
|
|
if err == consts.RedisNil {
|