| | |
| | | import com.ltkj.hosp.domain.TjCustomer; |
| | | import com.ltkj.hosp.service.IDictHospService; |
| | | import com.ltkj.hosp.service.ITjCustomerService; |
| | | import com.ltkj.system.service.ISysDeptService; |
| | | import com.ltkj.system.service.ISysMenuService; |
| | | import com.ltkj.system.service.SysParametersDisposeService; |
| | | import com.ltkj.system.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | |
| | | import com.ltkj.framework.manager.AsyncManager; |
| | | import com.ltkj.framework.manager.factory.AsyncFactory; |
| | | import com.ltkj.framework.security.context.AuthenticationContextHolder; |
| | | import com.ltkj.system.service.ISysUserService; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | private ISysDeptService deptService; |
| | | @Autowired |
| | | private SysParametersDisposeService parametersDisposeService; |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | // 是否允许账户多终端同时登录(true允许 false不允许) |
| | | @Value("${token.soloLogin}") |
| | |
| | | */ |
| | | public String login(String username, String password, Boolean type,String code,String uuid) { |
| | | |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | String aSwitch = configService.selectConfigByKey("captcha_switch"); |
| | | if(null !=aSwitch && aSwitch.equalsIgnoreCase("Y")){ |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | } |
| | | } |
| | | |
| | | // 用户验证 |
| | | Authentication authentication = null; |
| | | try { |
| | | //登录密码解密 |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, RsaUtils.decryptByPrivateKey(password)); |
| | | //UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); |
| | | String s = RsaUtils.decryptByPrivateKey(password); |
| | | // String s = password; |
| | | if(username.equals("10001")){ |
| | | s=username+s; |
| | | } |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username,s); |
| | | AuthenticationContextHolder.setContext(authenticationToken); |
| | | // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername |
| | | authentication = authenticationManager.authenticate(authenticationToken); |
| | |
| | | if(!SecurityUtils.isAdmin(user.getUserId())){ |
| | | if(dictHosp.getSecretKey() != null && dictHosp.getExpirationTime() != null){ |
| | | if (!SecurityUtils.matchesMallMerchantSecretKey(secret,dictHosp.getHospAreaId(),dictHosp.getHospAreaName(), |
| | | dictHosp.getExpirationTime(),dictHosp.getSecretKey())) { |
| | | dictHosp.getExpirationTime(),dictHosp.getSecretKey()) || new Date().after(DateUtil.endOfDay(dictHosp.getExpirationTime()))) { |
| | | throw new SecretKeyException("商家已过期请续费使用"); |
| | | } |
| | | long between = DateUtil.between(new Date(), DateUtil.endOfDay(dictHosp.getExpirationTime()), DateUnit.DAY); |
| | |
| | | */ |
| | | public String Cuslogin(String username, String password, Boolean type,String code,String uuid) { |
| | | |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | String aSwitch = configService.selectConfigByKey("captcha_switch"); |
| | | if(null !=aSwitch && aSwitch.equalsIgnoreCase("Y")){ |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | } |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | } |
| | | |
| | | |
| | | LoginUser loginUser = loadCusByCusname(username, password); |
| | | if (loginUser == null) { |
| | | return "用户名或密码错误"; |
| | |
| | | List<TjCustomer> customerList = customerService.list(wq); |
| | | if (null == customerList || customerList.size() == 0) { |
| | | //throw new ServiceException("登录用户:" + username + " 不存在"); |
| | | throw new ServiceException("账户或密码错误,请检查!"); |
| | | throw new ServiceException("账号或密码错误,请检查!"); |
| | | } |
| | | for (TjCustomer tjCustomer : customerList) { |
| | | try { |