校验邮箱是否存在

This commit is contained in:
shiziyuan9527 2020-05-27 21:09:24 +08:00
parent fd4854d4ab
commit d4a4d74926
1 changed files with 9 additions and 0 deletions

View File

@ -196,6 +196,15 @@ public class UserService {
if (!roles.isEmpty()) {
insertUserRole(roles, user.getId());
}
String email = user.getEmail();
User u = userMapper.selectByPrimaryKey(userId);
if (!StringUtils.equals(email, u.getEmail())) {
UserExample userExample = new UserExample();
userExample.createCriteria().andEmailEqualTo(email);
if (userMapper.countByExample(userExample) > 0) {
MSException.throwException(Translator.get("user_email_already_exists"));
}
}
user.setUpdateTime(System.currentTimeMillis());
userMapper.updateByPrimaryKeySelective(user);
}