| @@ -222,6 +222,14 @@ public class HomeController extends BaseController { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| } | } | ||||
| if (user == null) { | |||||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if (user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
| logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
| } | |||||
| boolean isLogin = false; | boolean isLogin = false; | ||||
| try { | try { | ||||
| @@ -328,6 +336,14 @@ public class HomeController extends BaseController { | |||||
| List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone); | List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone); | ||||
| if(userList.size() == 1) { | if(userList.size() == 1) { | ||||
| MallUserInfoVo user = userList.get(0); | MallUserInfoVo user = userList.get(0); | ||||
| if (user == null) { | |||||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if (user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
| logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
| } | |||||
| // check 验证码正确 | // check 验证码正确 | ||||
| boolean isValidCode = false; | boolean isValidCode = false; | ||||
| try { | try { | ||||
| @@ -336,6 +352,7 @@ public class HomeController extends BaseController { | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
| } | } | ||||
| if(isValidCode) { | if(isValidCode) { | ||||
| // 验证码正确,直接登录 | // 验证码正确,直接登录 | ||||
| try { | try { | ||||
| Subject subject = SecurityUtils.getSubject(); | Subject subject = SecurityUtils.getSubject(); | ||||
| @@ -10,6 +10,7 @@ import com.iformall.domain.po.MallUserAction; | |||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.vo.MallUserInfoVo; | import com.iformall.domain.vo.MallUserInfoVo; | ||||
| import com.iformall.enums.EnumMallUserAction; | import com.iformall.enums.EnumMallUserAction; | ||||
| import com.iformall.enums.EnumMallUserStatus; | |||||
| import com.iformall.enums.EnumUserAdmin; | import com.iformall.enums.EnumUserAdmin; | ||||
| import com.iformall.service.MallUserActionService; | import com.iformall.service.MallUserActionService; | ||||
| import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
| @@ -123,6 +124,14 @@ public class WechatLoginController extends BaseController { | |||||
| Map<String, Object> ret = new HashMap<>(); | Map<String, Object> ret = new HashMap<>(); | ||||
| // 唯一用户 | // 唯一用户 | ||||
| MallUserInfo user = userList.get(0); | MallUserInfo user = userList.get(0); | ||||
| if (user == null) { | |||||
| ret.put("code", ErrorCode.USER_IS_EMPTY.getCode()); | |||||
| ret.put("message", ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| } | |||||
| if (user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
| ret.put("code", ErrorCode.USER_IS_LOCKED.getCode()); | |||||
| ret.put("message", ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| } | |||||
| boolean isLogin = false; | boolean isLogin = false; | ||||
| try { | try { | ||||
| Subject subject = SecurityUtils.getSubject(); | Subject subject = SecurityUtils.getSubject(); | ||||
| @@ -272,6 +281,12 @@ public class WechatLoginController extends BaseController { | |||||
| log.info("KEY: " + openKey + " deleted"); | log.info("KEY: " + openKey + " deleted"); | ||||
| MallUserInfo userInfo = mallUserInfoService.getByUsername(userName); | MallUserInfo userInfo = mallUserInfoService.getByUsername(userName); | ||||
| if (userInfo == null) { | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if (userInfo.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(userInfo.getStatus())) { | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
| } | |||||
| if(userInfo.getWebOpenId().equals(openId)) { | if(userInfo.getWebOpenId().equals(openId)) { | ||||
| boolean isLogin = false; | boolean isLogin = false; | ||||
| try { | try { | ||||
| @@ -1,23 +1,13 @@ | |||||
| package com.iformall.shiro; | package com.iformall.shiro; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.enums.EnumLoginType; | import com.iformall.enums.EnumLoginType; | ||||
| import com.iformall.enums.EnumMallUserStatus; | |||||
| import com.iformall.service.MallUserInfoService; | |||||
| import org.apache.shiro.authc.AuthenticationInfo; | import org.apache.shiro.authc.AuthenticationInfo; | ||||
| import org.apache.shiro.authc.AuthenticationToken; | import org.apache.shiro.authc.AuthenticationToken; | ||||
| import org.apache.shiro.authc.DisabledAccountException; | |||||
| import org.apache.shiro.authc.UnknownAccountException; | |||||
| import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | ||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import javax.annotation.Resource; | |||||
| @Configuration | @Configuration | ||||
| public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | ||||
| @Resource | |||||
| private MallUserInfoService userService; | |||||
| @Override | @Override | ||||
| public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) { | public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) { | ||||
| @@ -26,14 +16,6 @@ public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | |||||
| if(tk.getType().equals(EnumLoginType.NOPASSWD)){ | if(tk.getType().equals(EnumLoginType.NOPASSWD)){ | ||||
| // 获取用户的输入的账号. | // 获取用户的输入的账号. | ||||
| String username = (String)tk.getPrincipal(); | String username = (String)tk.getPrincipal(); | ||||
| MallUserInfo user = userService.getByUsername(username); | |||||
| if(user == null) { | |||||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| } | |||||
| // 用户被禁用 | |||||
| if(user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| boolean matches = super.doCredentialsMatch(authcToken, info); | boolean matches = super.doCredentialsMatch(authcToken, info); | ||||