|
|
@@ -6,16 +6,16 @@ import com.github.microservice.auth.client.model.UserAuthLoginModel;
|
|
|
import com.github.microservice.auth.client.model.UserTokenModel;
|
|
|
import com.github.microservice.auth.client.service.UserService;
|
|
|
import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
+import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
|
|
|
import com.github.microservice.core.util.net.IPUtil;
|
|
|
import com.zhongshu.card.client.model.org.LoginParam;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.utils.type.LoginFromType;
|
|
|
import com.zhongshu.card.client.utils.type.OrganizationState;
|
|
|
import com.zhongshu.card.client.utils.type.UserState;
|
|
|
-import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
-import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
-import com.zhongshu.card.server.core.dao.org.UserLoginFailRecordDao;
|
|
|
-import com.zhongshu.card.server.core.dao.org.UserLoginRecordDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.*;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserLoginFailRecord;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserLoginRecord;
|
|
|
@@ -71,6 +71,7 @@ public class IndexService {
|
|
|
|
|
|
@Autowired
|
|
|
OrganizationUserDao organizationUserDao;
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
|
|
|
/**
|
|
|
* 登录--web
|
|
|
@@ -80,9 +81,62 @@ public class IndexService {
|
|
|
*/
|
|
|
public ResultContent login(LoginParam param) {
|
|
|
String phone = param.getLoginValue();
|
|
|
+ UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
+ BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
|
+ ResultContent resultContent = commonLogin(userAuthLoginModel);
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ return resultContent;
|
|
|
+ }
|
|
|
+ // web 端的登录用户数据验证
|
|
|
+ UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
+ if (param.getLoginFromType() == LoginFromType.Platform) {
|
|
|
+ // web平台端登录
|
|
|
+ // 判断用户是否加入了平台端
|
|
|
+ Organization platformOrg = organizationDao.findTopByAuthType(AuthType.Platform);
|
|
|
+ if (ObjectUtils.isEmpty(platformOrg)) {
|
|
|
+ return ResultContent.buildFail("平台端数据未初始化,登录失败");
|
|
|
+ }
|
|
|
+ long number = organizationUserDao.countByUserAndStateAndAuthType(userAccount, UserState.Normal, AuthType.Platform);
|
|
|
+ if (number <= 0) {
|
|
|
+ return ResultContent.buildFail(String.format("用户不属于平台端用户,登录失败:%s", phone));
|
|
|
+ }
|
|
|
+ } else if (param.getLoginFromType() == LoginFromType.School) {
|
|
|
+ // 校园端web登录
|
|
|
+ long number = organizationUserDao.countByUserAndStateAndAuthType(userAccount, UserState.Normal, AuthType.School);
|
|
|
+ if (number <= 0) {
|
|
|
+ return ResultContent.buildFail(String.format("用户未加入学校,登录失败:%s", phone));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultContent;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 小程序端账号密码登录
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent xcxLogin(LoginParam param) {
|
|
|
+ String phone = param.getLoginValue();
|
|
|
UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
|
+ ResultContent resultContent = commonLogin(userAuthLoginModel);
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ return resultContent;
|
|
|
+ }
|
|
|
+ // 商户端
|
|
|
+ if (param.getLoginFromType() == LoginFromType.Shop) {
|
|
|
+ UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
+ long number = organizationUserDao.countByUserAndStateAndAuthType(userAccount, UserState.Normal, AuthType.Shop);
|
|
|
+ if (number <= 0) {
|
|
|
+ return ResultContent.buildFail(String.format("用户不属于任何商户,登录失败:%s", phone));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent commonLogin(UserAuthLoginModel userAuthLoginModel) {
|
|
|
+ String phone = userAuthLoginModel.getLoginValue();
|
|
|
userAuthLoginModel.setDeviceIp(IPUtil.getRemoteIp(request));
|
|
|
userAuthLoginModel.setClientId(clientId);
|
|
|
userAuthLoginModel.setClientSecret(clientSecret);
|
|
|
@@ -103,17 +157,11 @@ public class IndexService {
|
|
|
return ResultContent.buildFail("用户已被注销,登录失败");
|
|
|
}
|
|
|
|
|
|
- if (param.getLoginValue() == null) {
|
|
|
- long orgNumber = organizationUserDao.countByUserAndState(userAccount, OrganizationState.Normal);
|
|
|
- if (orgNumber <= 0) {
|
|
|
- return ResultContent.buildFail("用户未加入任何机构,不能登录");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 记录已登录过
|
|
|
userAccount.setIsLogined(Boolean.TRUE);
|
|
|
userCountDao.save(userAccount);
|
|
|
|
|
|
+ // 用户登录日志
|
|
|
UserLoginRecord record = new UserLoginRecord();
|
|
|
record.setPhone(userAccount.getPhone());
|
|
|
record.setUid(userAccount.getUserId());
|
|
|
@@ -122,17 +170,17 @@ public class IndexService {
|
|
|
userLoginRecordDao.save(record);
|
|
|
|
|
|
// 删除失败记录
|
|
|
- userLoginFailRecordDao.deleteByUserName(param.getLoginValue());
|
|
|
+ userLoginFailRecordDao.deleteByUserName(phone);
|
|
|
return ResultContent.buildSuccess(resultContent.getContent());
|
|
|
+ } else {
|
|
|
+ // 记录登录失败信息
|
|
|
+ userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone).ttl(new Date(dbHelper.getTime() + 2 * 24L * 60 * 60 * 1000L)).build());
|
|
|
+ String msg = resultContent.getMsg();
|
|
|
+ if (StringUtils.isEmpty(msg)) {
|
|
|
+ msg = "账号或密码不正确.";
|
|
|
+ }
|
|
|
+ return ResultContent.buildFail(msg);
|
|
|
}
|
|
|
- // 记录登录失败信息
|
|
|
- userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(param.getLoginValue())
|
|
|
- .ttl(new Date(dbHelper.getTime() + 2 * 24L * 60 * 60 * 1000L)).build());
|
|
|
- String msg = resultContent.getMsg();
|
|
|
- if (StringUtils.isEmpty(msg)) {
|
|
|
- msg = "账号或密码不正确.";
|
|
|
- }
|
|
|
- return ResultContent.buildFail(msg);
|
|
|
}
|
|
|
|
|
|
/**
|