|
|
|
@ -35,6 +35,7 @@ import (
|
|
|
|
|
type IUser interface { |
|
|
|
|
GetAdminUserByUsernamePassword(ctx context.Context, req *system.UserLoginReq) (user *model2.LoginUserRes, err error) |
|
|
|
|
GetAdminUserByPhone(ctx context.Context, req *system.UserLoginMobileReq) (user *model2.LoginUserRes, err error) |
|
|
|
|
GetAdminUserByEmail(ctx context.Context, req *system.UserLoginEmailReq) (user *model2.LoginUserRes, err error) |
|
|
|
|
LoginLog(ctx context.Context, params *model2.LoginLogParams) |
|
|
|
|
UpdateLoginInfo(ctx context.Context, id uint64, ip string) (err error) |
|
|
|
|
NotCheckAuthAdminIds(ctx context.Context) *gset.Set |
|
|
|
@ -49,7 +50,9 @@ type IUser interface {
|
|
|
|
|
Delete(ctx context.Context, ids []int) (err error) |
|
|
|
|
GetUserByUsername(ctx context.Context, userName string) (user *model2.LoginUserRes, err error) |
|
|
|
|
GetUserByMobile(ctx context.Context, mobile string) (user *model2.LoginUserRes, err error) |
|
|
|
|
GetUserByEmail(ctx context.Context, email string) (user *model2.LoginUserRes, err error) |
|
|
|
|
GetCodeByMobile(ctx context.Context, mobile string) (code string, err error) |
|
|
|
|
GetCodeByEmail(ctx context.Context, email string) (code string, err error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type userImpl struct { |
|
|
|
@ -127,6 +130,29 @@ func (s *userImpl) GetAdminUserByPhone(ctx context.Context, req *system.UserLogi
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *userImpl) GetAdminUserByEmail(ctx context.Context, req *system.UserLoginEmailReq) (user *model2.LoginUserRes, err error) { |
|
|
|
|
err = g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
user, err = s.GetUserByEmail(ctx, req.Email) |
|
|
|
|
liberr.ErrIsNil(ctx, err) |
|
|
|
|
liberr.ValueIsNil(user, "验证码错误") |
|
|
|
|
log.Printf("GetAdminUserByPhone >>> Email:%s", req.Email) |
|
|
|
|
//验证密码
|
|
|
|
|
model, ok := codes[req.Email] |
|
|
|
|
log.Printf("GetAdminUserByPhone >>> Email:%s, time %s ", req.Email, fmt.Sprint(model.Time.Unix())+"--"+fmt.Sprint(gtime.Now().Unix())) |
|
|
|
|
if !ok || model.Time.Unix()+600 < gtime.Now().Unix() { |
|
|
|
|
liberr.ErrIsNil(ctx, gerror.New("验证码错误")) |
|
|
|
|
} |
|
|
|
|
if libUtils.EncryptPassword(req.Code+fmt.Sprint(model.Time.Unix()), user.UserSalt) != model.Password { |
|
|
|
|
liberr.ErrIsNil(ctx, gerror.New("验证码错误")) |
|
|
|
|
} |
|
|
|
|
//账号状态
|
|
|
|
|
if user.UserStatus == 0 { |
|
|
|
|
liberr.ErrIsNil(ctx, gerror.New("账号已被冻结")) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUserByUsername 通过用户名获取用户信息
|
|
|
|
|
func (s *userImpl) GetUserByUsername(ctx context.Context, userName string) (user *model2.LoginUserRes, err error) { |
|
|
|
|
err = g.Try(ctx, func(ctx context.Context) { |
|
|
|
@ -147,6 +173,16 @@ func (s *userImpl) GetUserByMobile(ctx context.Context, mobile string) (user *mo
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUserByEmail 通过邮箱获取用户信息
|
|
|
|
|
func (s *userImpl) GetUserByEmail(ctx context.Context, email string) (user *model2.LoginUserRes, err error) { |
|
|
|
|
err = g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
user = &model2.LoginUserRes{} |
|
|
|
|
err = dao.SysUser.Ctx(ctx).Fields(user).Where(dao.SysUser.Columns().UserEmail, email).Scan(user) |
|
|
|
|
liberr.ErrIsNil(ctx, err, "验证码错误") |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetCodeByMobile 通过手机号获取Code
|
|
|
|
|
func (s *userImpl) GetCodeByMobile(ctx context.Context, mobile string) (code string, err error) { |
|
|
|
|
err = g.Try(ctx, func(ctx context.Context) { |
|
|
|
@ -173,6 +209,32 @@ func (s *userImpl) GetCodeByMobile(ctx context.Context, mobile string) (code str
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetCodeByEmail 通过邮箱获取Code
|
|
|
|
|
func (s *userImpl) GetCodeByEmail(ctx context.Context, email string) (code string, err error) { |
|
|
|
|
err = g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
user, err := s.GetUserByEmail(ctx, email) |
|
|
|
|
liberr.ErrIsNil(ctx, err) |
|
|
|
|
liberr.ValueIsNil(user, "验证码错误") |
|
|
|
|
log.Printf("GetCodeByMobile >>> email:%s", email) |
|
|
|
|
code = utils.GenerateRandomString(6) |
|
|
|
|
//验证密码
|
|
|
|
|
time := gtime.Now() |
|
|
|
|
password := libUtils.EncryptPassword(code+fmt.Sprint(time.Unix()), user.UserSalt) |
|
|
|
|
codes[email] = CodeModel{ |
|
|
|
|
Code: code, |
|
|
|
|
Time: time, |
|
|
|
|
Password: password, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.Printf("GetCodeByMobile >>> email:%s", gjson.MustEncodeString(codes[email])) |
|
|
|
|
//账号状态
|
|
|
|
|
if user.UserStatus == 0 { |
|
|
|
|
liberr.ErrIsNil(ctx, gerror.New("账号已被冻结")) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LoginLog 记录登录日志
|
|
|
|
|
func (s *userImpl) LoginLog(ctx context.Context, params *model2.LoginLogParams) { |
|
|
|
|
ua := user_agent.New(params.UserAgent) |
|
|
|
|