|
@@ -29,6 +29,7 @@ import cn.com.qmth.examcloud.commons.web.security.AccessUserOps;
|
|
import cn.com.qmth.examcloud.commons.web.security.AccessUserOpsForRedis;
|
|
import cn.com.qmth.examcloud.commons.web.security.AccessUserOpsForRedis;
|
|
import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.base.enums.AccountType;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.ThirdPartyAccessDao;
|
|
import cn.com.qmth.examcloud.core.basic.dao.ThirdPartyAccessDao;
|
|
@@ -47,7 +48,9 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.UserOpsLog;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserScope;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserScope;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserType;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserType;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -82,6 +85,9 @@ public class UserServiceImpl implements UserService{
|
|
ThirdPartyAccessDao thirdPartyAccessDao;
|
|
ThirdPartyAccessDao thirdPartyAccessDao;
|
|
|
|
|
|
RedisTemplate redisTemplate;
|
|
RedisTemplate redisTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ AuthService authService;
|
|
|
|
|
|
AccessUserOps accessUserOps;
|
|
AccessUserOps accessUserOps;
|
|
|
|
|
|
@@ -247,13 +253,11 @@ public class UserServiceImpl implements UserService{
|
|
*/
|
|
*/
|
|
public UserInfo login(String loginName,
|
|
public UserInfo login(String loginName,
|
|
String password)throws Exception{
|
|
String password)throws Exception{
|
|
- User user = userRepo.findByLoginName(loginName);
|
|
|
|
- if(user == null){
|
|
|
|
- throw new RuntimeException("该用户不存在");
|
|
|
|
- }else if(!user.getPassword().equals(password)){
|
|
|
|
- throw new RuntimeException("密码错误");
|
|
|
|
- }else if(!user.getEnable()){
|
|
|
|
- throw new RuntimeException("该用户被禁用");
|
|
|
|
|
|
+ User user = userRepo.findByLoginName(loginName);
|
|
|
|
+ if (user == null) {
|
|
|
|
+ throw new RuntimeException("该用户不存在");
|
|
|
|
+ } else if (!user.getEnable()) {
|
|
|
|
+ throw new RuntimeException("该用户被禁用");
|
|
}
|
|
}
|
|
return loginProcess(user);
|
|
return loginProcess(user);
|
|
|
|
|
|
@@ -270,27 +274,29 @@ public class UserServiceImpl implements UserService{
|
|
String loginName,
|
|
String loginName,
|
|
String password)throws Exception{
|
|
String password)throws Exception{
|
|
User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
|
|
User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
|
|
- if(user == null){
|
|
|
|
- throw new RuntimeException("该用户不存在");
|
|
|
|
- }else if(!user.getPassword().equals(password)){
|
|
|
|
- throw new RuntimeException("密码错误");
|
|
|
|
- }else if(!user.getEnable()){
|
|
|
|
- throw new RuntimeException("该用户被禁用");
|
|
|
|
- }
|
|
|
|
|
|
+ if (user == null) {
|
|
|
|
+ throw new RuntimeException("该用户不存在");
|
|
|
|
+ } else if (!user.getEnable()) {
|
|
|
|
+ throw new RuntimeException("该用户被禁用");
|
|
|
|
+ }
|
|
return loginProcess(user);
|
|
return loginProcess(user);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 登录处理
|
|
* 登录处理
|
|
|
|
+ * 重新定义 by wangwei
|
|
* @param user
|
|
* @param user
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public UserInfo loginProcess(User user) throws Exception {
|
|
public UserInfo loginProcess(User user) throws Exception {
|
|
- String token = AccessCtrlUtil.buildToken();
|
|
|
|
- initUserLogin(user);
|
|
|
|
- createAccessUser(token, user, null);
|
|
|
|
- createUserLogin(token, user);
|
|
|
|
- return getUserInfo(user, token);
|
|
|
|
|
|
+ LoginInfo loginInfo=new LoginInfo();
|
|
|
|
+ loginInfo.setAccountType(AccountType.COMMON_LOGIN_NAME.getCode());
|
|
|
|
+ loginInfo.setAccountValue(user.getLoginName());
|
|
|
|
+ loginInfo.setPassword(user.getPassword());
|
|
|
|
+ loginInfo.setRootOrgId(String.valueOf(user.getRootOrgId()));
|
|
|
|
+ cn.com.qmth.examcloud.commons.web.security.bean.User loginUser = authService.login(loginInfo);
|
|
|
|
+ String userToken = loginUser.getUserToken();
|
|
|
|
+ return getUserInfo(user, userToken);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -345,6 +351,7 @@ public class UserServiceImpl implements UserService{
|
|
* 初始化用户登录
|
|
* 初始化用户登录
|
|
* @param user
|
|
* @param user
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public void initUserLogin(User user){
|
|
public void initUserLogin(User user){
|
|
//判断是否已登录,若已登录则强制已登录用户退出
|
|
//判断是否已登录,若已登录则强制已登录用户退出
|
|
UserLogin userLogin= userLoginRepo.findFirstByUserId(user.getId());
|
|
UserLogin userLogin= userLoginRepo.findFirstByUserId(user.getId());
|
|
@@ -369,6 +376,7 @@ public class UserServiceImpl implements UserService{
|
|
* @param token
|
|
* @param token
|
|
* @param user
|
|
* @param user
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public void createUserLogin(String token,User user){
|
|
public void createUserLogin(String token,User user){
|
|
UserLogin userLogin = new UserLogin();
|
|
UserLogin userLogin = new UserLogin();
|
|
userLogin.setLoginTime(new Date());
|
|
userLogin.setLoginTime(new Date());
|
|
@@ -382,6 +390,7 @@ public class UserServiceImpl implements UserService{
|
|
* @param token
|
|
* @param token
|
|
* @param user
|
|
* @param user
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public void createAccessUser(String token,User user,Long studentId)throws Exception{
|
|
public void createAccessUser(String token,User user,Long studentId)throws Exception{
|
|
AccessUser accessUser = new AccessUser();
|
|
AccessUser accessUser = new AccessUser();
|
|
Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());
|
|
Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());
|