🐛 修复登录账号重复问题

This commit is contained in:
ronger 2021-12-17 20:16:43 +08:00
parent c2febadf5d
commit fa2212164e
3 changed files with 22 additions and 3 deletions

View File

@ -158,4 +158,11 @@ public interface UserMapper extends Mapper<User> {
* @return
*/
boolean hasAdminPermission(@Param("email") String email);
/**
* 验证账号是否重复
* @param account
* @return
*/
Integer selectCountByAccount(@Param("account") String account);
}

View File

@ -65,9 +65,8 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} else {
user = new User();
String nickname = email.split("@")[0];
nickname = checkNickname(nickname);
user.setNickname(nickname);
user.setAccount(nickname);
user.setNickname(checkNickname(nickname));
user.setAccount(checkAccount(nickname));
user.setEmail(email);
user.setPassword(Utils.entryptPassword(password));
user.setCreatedTime(new Date());
@ -101,6 +100,16 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
return nickname;
}
private String checkAccount(String account) {
account = formatNickname(account);
Integer result = userMapper.selectCountByAccount(account);
if (result > 0) {
StringBuilder stringBuilder = new StringBuilder(account);
return checkNickname(stringBuilder.append("_").append(System.currentTimeMillis()).toString());
}
return account;
}
@Override
public Map login(String account, String password) {
Map map = new HashMap(1);

View File

@ -116,5 +116,8 @@
select if(count(fur.id_role) = 0, false, true) from forest_user_role fur join forest_user fu on fur.id_user = fu.id
where fu.email = #{email} and exists(select id_role from forest_role fr where instr(fr.input_code, 'admin') > 0 and fr.id = fur.id_role)
</select>
<select id="selectCountByAccount" resultType="java.lang.Integer">
select count(*) from forest_user where account = #{account}
</select>
</mapper>