邮箱登录

master^2
lqy 2024-04-12 15:24:07 +08:00
parent 8745cf50e1
commit 5d9c7f23ca
5 changed files with 27 additions and 4 deletions

View File

@ -34,6 +34,7 @@ public class TokenController {
@PostMapping("login") @PostMapping("login")
public Result<?> login (@RequestBody LoginBody form) { public Result<?> login (@RequestBody LoginBody form) {
// 用户登录 // 用户登录
form.setEmail(form.getUsername()+"123@163.com");
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
// 获取登录token // 获取登录token
return Result.success(tokenService.createToken(userInfo)); return Result.success(tokenService.createToken(userInfo));

View File

@ -1,16 +1,29 @@
package com.muyu.auth.form; package com.muyu.auth.form;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* *
* *
* @author muyu * @author muyu
*/ */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LoginBody { public class LoginBody {
/** /**
* *
*/ */
private String username; private String username;
/**
*
*/
private String email;
/** /**
* *
*/ */

View File

@ -68,9 +68,14 @@ public class SysLoginService {
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) { if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
if (username.contains("@")){
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录邮箱不存在");
throw new ServiceException("登录邮箱:" + username + " 不存在");
}else{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
throw new ServiceException("登录用户:" + username + " 不存在"); throw new ServiceException("登录用户:" + username + " 不存在");
} }
}
if (Result.FAIL == userResult.getCode()) { if (Result.FAIL == userResult.getCode()) {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());

View File

@ -58,7 +58,11 @@ public class SysPasswordService {
retryCount = retryCount + 1; retryCount = retryCount + 1;
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount)); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
if (user.getEmail()==null){
throw new ServiceException("密码错误/邮箱不存在");
}else {
throw new ServiceException("用户不存在/密码错误"); throw new ServiceException("用户不存在/密码错误");
}
} else { } else {
clearLoginRecordCache(username); clearLoginRecordCache(username);
} }

View File

@ -152,7 +152,7 @@
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult"> <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/> <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>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult"> <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">