邮箱登录
parent
8745cf50e1
commit
5d9c7f23ca
|
@ -34,6 +34,7 @@ public class TokenController {
|
|||
@PostMapping("login")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
form.setEmail(form.getUsername()+"123@163.com");
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
// 获取登录token
|
||||
return Result.success(tokenService.createToken(userInfo));
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
package com.muyu.auth.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 用户登录对象
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoginBody {
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
|
|
|
@ -68,8 +68,13 @@ public class SysLoginService {
|
|||
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||
if (username.contains("@")){
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录邮箱不存在");
|
||||
throw new ServiceException("登录邮箱:" + username + " 不存在");
|
||||
}else{
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||
}
|
||||
}
|
||||
|
||||
if (Result.FAIL == userResult.getCode()) {
|
||||
|
|
|
@ -58,7 +58,11 @@ public class SysPasswordService {
|
|||
retryCount = retryCount + 1;
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
|
||||
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
|
||||
throw new ServiceException("用户不存在/密码错误");
|
||||
if (user.getEmail()==null){
|
||||
throw new ServiceException("密码错误/邮箱不存在");
|
||||
}else {
|
||||
throw new ServiceException("用户不存在/密码错误");
|
||||
}
|
||||
} else {
|
||||
clearLoginRecordCache(username);
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_name = #{userName} and u.del_flag = '0'
|
||||
where u.user_name = #{userName} or u.email = #{userName} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||
|
|
Loading…
Reference in New Issue