|
@@ -12,15 +12,18 @@ import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
|
|
|
import com.github.microservice.core.util.net.IPUtil;
|
|
import com.github.microservice.core.util.net.IPUtil;
|
|
|
import com.zhongshu.card.client.model.login.LoginCommonModel;
|
|
import com.zhongshu.card.client.model.login.LoginCommonModel;
|
|
|
import com.zhongshu.card.client.model.org.*;
|
|
import com.zhongshu.card.client.model.org.*;
|
|
|
|
|
+import com.zhongshu.card.client.model.setting.PlatFormLoginConfig;
|
|
|
import com.zhongshu.card.client.model.wechat.PhoneModel;
|
|
import com.zhongshu.card.client.model.wechat.PhoneModel;
|
|
|
import com.zhongshu.card.client.model.wechat.WechatPhoneNumber;
|
|
import com.zhongshu.card.client.model.wechat.WechatPhoneNumber;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.zhongshu.card.client.type.LoginFromType;
|
|
import com.zhongshu.card.client.type.LoginFromType;
|
|
|
import com.zhongshu.card.client.type.OrganizationState;
|
|
import com.zhongshu.card.client.type.OrganizationState;
|
|
|
import com.zhongshu.card.client.type.UserState;
|
|
import com.zhongshu.card.client.type.UserState;
|
|
|
|
|
+import com.zhongshu.card.client.type.setting.SettingType;
|
|
|
import com.zhongshu.card.server.core.dao.org.*;
|
|
import com.zhongshu.card.server.core.dao.org.*;
|
|
|
import com.zhongshu.card.server.core.domain.org.*;
|
|
import com.zhongshu.card.server.core.domain.org.*;
|
|
|
import com.zhongshu.card.server.core.service.base.RedisService;
|
|
import com.zhongshu.card.server.core.service.base.RedisService;
|
|
|
|
|
+import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
|
|
|
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
|
|
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
@@ -93,6 +96,9 @@ public class IndexService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
OrganizationServiceImpl organizationService;
|
|
OrganizationServiceImpl organizationService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ PlatFormConfigInfoService platFormConfigInfoService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通用用户登录(返回所有权限数据)
|
|
* 通用用户登录(返回所有权限数据)
|
|
|
*
|
|
*
|
|
@@ -287,7 +293,9 @@ public class IndexService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public ResultContent<LoginTokenModel> commonLogin(UserAuthLoginModel userAuthLoginModel) {
|
|
public ResultContent<LoginTokenModel> commonLogin(UserAuthLoginModel userAuthLoginModel) {
|
|
|
|
|
+ // 登录名
|
|
|
String phone = userAuthLoginModel.getLoginValue();
|
|
String phone = userAuthLoginModel.getLoginValue();
|
|
|
|
|
+
|
|
|
userAuthLoginModel.setDeviceIp(IPUtil.getRemoteIp(request));
|
|
userAuthLoginModel.setDeviceIp(IPUtil.getRemoteIp(request));
|
|
|
userAuthLoginModel.setClientId(clientId);
|
|
userAuthLoginModel.setClientId(clientId);
|
|
|
userAuthLoginModel.setClientSecret(clientSecret);
|
|
userAuthLoginModel.setClientSecret(clientSecret);
|
|
@@ -298,6 +306,21 @@ public class IndexService {
|
|
|
if (userAuthLoginModel.getRefreshTokenTimeOut() == null) {
|
|
if (userAuthLoginModel.getRefreshTokenTimeOut() == null) {
|
|
|
userAuthLoginModel.setRefreshTokenTimeOut(31536000L);
|
|
userAuthLoginModel.setRefreshTokenTimeOut(31536000L);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 登录失败信息过期时间
|
|
|
|
|
+ Long lockTime = 2 * 24L * 60 * 60 * 1000L;
|
|
|
|
|
+ // 错误次数
|
|
|
|
|
+ int maxFail = 3;
|
|
|
|
|
+ Object config = platFormConfigInfoService.getInfo(SettingType.LoginConfig);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(config)) {
|
|
|
|
|
+ PlatFormLoginConfig loginConfig = (PlatFormLoginConfig) config;
|
|
|
|
|
+ Integer lockMinute = loginConfig.getLockMinute();
|
|
|
|
|
+ if (lockMinute != null) {
|
|
|
|
|
+ lockTime = lockMinute * 60 * 60 * 1000L;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (loginConfig.getMaxLoginFail() != null) {
|
|
|
|
|
+ maxFail = loginConfig.getMaxLoginFail();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
com.github.microservice.auth.client.content.ResultContent<LoginTokenModel> resultContent = userService.login(userAuthLoginModel);
|
|
com.github.microservice.auth.client.content.ResultContent<LoginTokenModel> resultContent = userService.login(userAuthLoginModel);
|
|
|
if (resultContent.getState() == com.github.microservice.auth.client.content.ResultState.Success) {
|
|
if (resultContent.getState() == com.github.microservice.auth.client.content.ResultState.Success) {
|
|
@@ -305,6 +328,12 @@ public class IndexService {
|
|
|
if (ObjectUtils.isEmpty(userAccount)) {
|
|
if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
return ResultContent.buildFail("账号或密码不正确");
|
|
return ResultContent.buildFail("账号或密码不正确");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ long number = userLoginFailRecordDao.countByUserName(userAccount.getLoginName());
|
|
|
|
|
+ if (number > maxFail) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format("登录失败超过%d次,请稍后再试", maxFail));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 判断用户状态
|
|
// 判断用户状态
|
|
|
if (userAccount.getState() == UserState.Locked) {
|
|
if (userAccount.getState() == UserState.Locked) {
|
|
|
return ResultContent.buildFail(String.format("该账号已被%s,不能登录", userAccount.getState().getRemark()));
|
|
return ResultContent.buildFail(String.format("该账号已被%s,不能登录", userAccount.getState().getRemark()));
|
|
@@ -331,7 +360,8 @@ public class IndexService {
|
|
|
return ResultContent.buildSuccess(resultContent.getContent());
|
|
return ResultContent.buildSuccess(resultContent.getContent());
|
|
|
} else {
|
|
} else {
|
|
|
// 记录登录失败信息
|
|
// 记录登录失败信息
|
|
|
- userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone).ttl(new Date(dbHelper.getTime() + 2 * 24L * 60 * 60 * 1000L)).build());
|
|
|
|
|
|
|
+ userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone)
|
|
|
|
|
+ .ttl(new Date(dbHelper.getTime() + lockTime)).build());
|
|
|
String msg = resultContent.getMsg();
|
|
String msg = resultContent.getMsg();
|
|
|
if (StringUtils.isEmpty(msg)) {
|
|
if (StringUtils.isEmpty(msg)) {
|
|
|
msg = "账号或密码不正确.";
|
|
msg = "账号或密码不正确.";
|