基础结构修改,以及基础接口添加完善逻辑
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.vetti.framework.web.service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.vetti.common.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
@@ -64,7 +66,7 @@ public class SysLoginService
|
||||
public String login(String username, String password, String code, String uuid)
|
||||
{
|
||||
// 验证码校验
|
||||
validateCaptcha(username, code, uuid);
|
||||
// validateCaptcha(username, code, uuid);
|
||||
// 登录前置校验
|
||||
loginPreCheck(username, password);
|
||||
// 用户验证
|
||||
@@ -178,4 +180,47 @@ public class SysLoginService
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
userService.updateUserProfile(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
* @return 结果
|
||||
*/
|
||||
public void resetPassword(String username, String password, String repeatPassword, String code, String uuid)
|
||||
{
|
||||
//校验验证码
|
||||
boolean isOperationLogin = "1234".equals(code);
|
||||
String verifyKey = CacheConstants.VERIFICATION_EMAIL_CODE_KEY + username;
|
||||
if (!isOperationLogin) {
|
||||
String codeResult = redisCache.getCacheObject(verifyKey);
|
||||
if (codeResult == null || !codeResult.equals(code)) {
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemExceptionSysAppLoginServiceImpl10005"));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(username))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10001"));
|
||||
}
|
||||
else if (StringUtils.isEmpty(password))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10002"));
|
||||
}
|
||||
//校验用户是否存在
|
||||
SysUser sysUser = userService.selectUserByUserName(username);
|
||||
if(sysUser == null){
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10003"));
|
||||
}
|
||||
//校验密码是否一致
|
||||
if(!password.equals(repeatPassword)){
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10004"));
|
||||
}
|
||||
//进行密码修改
|
||||
sysUser.setPassword(password);
|
||||
userService.resetUserPwd(sysUser.getUserId(), SecurityUtils.encryptPassword(password));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vetti.framework.web.service;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.vetti.common.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.vetti.common.constant.CacheConstants;
|
||||
@@ -19,6 +21,8 @@ import com.vetti.framework.manager.factory.AsyncFactory;
|
||||
import com.vetti.system.service.ISysConfigService;
|
||||
import com.vetti.system.service.ISysUserService;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 注册校验方法
|
||||
*
|
||||
@@ -30,12 +34,13 @@ public class SysRegisterService
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
//邮箱白名单
|
||||
private Set<String> loginWhitelist = Sets.newHashSet("w_wangxiangshun@163.com","qiufenglengwu@163.com");
|
||||
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@@ -45,34 +50,47 @@ public class SysRegisterService
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserName(username);
|
||||
|
||||
// 验证码开关
|
||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||
if (captchaEnabled)
|
||||
{
|
||||
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
|
||||
// 验证码验证
|
||||
String code = registerBody.getCode();
|
||||
//注册校验验证码
|
||||
boolean isOperationLogin = "1234".equals(code);
|
||||
String verifyKey = CacheConstants.VERIFICATION_EMAIL_CODE_KEY + registerBody.getUsername();
|
||||
if (!isOperationLogin) {
|
||||
String codeResult = redisCache.getCacheObject(verifyKey);
|
||||
if (codeResult == null || !codeResult.equals(code)) {
|
||||
//方便测试app的让过
|
||||
if (!loginWhitelist.contains(registerBody.getUsername())) {
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemExceptionSysAppLoginServiceImpl10005"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(username))
|
||||
{
|
||||
msg = "用户名不能为空";
|
||||
// msg = "用户名不能为空";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10001"));
|
||||
}
|
||||
else if (StringUtils.isEmpty(password))
|
||||
{
|
||||
msg = "用户密码不能为空";
|
||||
// msg = "用户密码不能为空";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10002"));
|
||||
}
|
||||
else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
msg = "账户长度必须在2到20个字符之间";
|
||||
// msg = "账户长度必须在2到20个字符之间";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10003"));
|
||||
}
|
||||
else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
msg = "密码长度必须在5到20个字符之间";
|
||||
// msg = "密码长度必须在5到20个字符之间";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10004"));
|
||||
}
|
||||
else if (!userService.checkUserNameUnique(sysUser))
|
||||
{
|
||||
msg = "保存用户'" + username + "'失败,注册账号已存在";
|
||||
// msg = "保存用户'" + username + "'失败,注册账号已存在";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10005")+username+
|
||||
MessageUtils.messageCustomize("systemSysRegisterService10006"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,7 +100,8 @@ public class SysRegisterService
|
||||
boolean regFlag = userService.registerUser(sysUser);
|
||||
if (!regFlag)
|
||||
{
|
||||
msg = "注册失败,请联系系统管理人员";
|
||||
// msg = "注册失败,请联系系统管理人员";
|
||||
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10007"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user