wangwei 7 سال پیش
والد
کامیت
7df8cf16f8

+ 28 - 19
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/UserServiceImpl.java

@@ -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.entity.AccessUser;
 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.StudentRepo;
 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.enums.UserScope;
 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.bean.LoginInfo;
 import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
 
 /**
@@ -82,6 +85,9 @@ public class UserServiceImpl  implements UserService{
     ThirdPartyAccessDao thirdPartyAccessDao;
 
     RedisTemplate redisTemplate;
+    
+	@Autowired
+	AuthService authService;
 
     AccessUserOps accessUserOps;
 
@@ -247,13 +253,11 @@ public class UserServiceImpl  implements UserService{
      */
     public UserInfo login(String loginName,
                           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);
 
@@ -270,27 +274,29 @@ public class UserServiceImpl  implements UserService{
                           String loginName,
                           String password)throws Exception{
         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);
     }
 
     /**
      * 登录处理
+     * 重新定义 by wangwei 
      * @param user
      * @return
      */
 	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
      */
+	@Deprecated
     public void initUserLogin(User user){
         //判断是否已登录,若已登录则强制已登录用户退出
         UserLogin userLogin= userLoginRepo.findFirstByUserId(user.getId());
@@ -369,6 +376,7 @@ public class UserServiceImpl  implements UserService{
      * @param token
      * @param user
      */
+    @Deprecated
     public void createUserLogin(String token,User user){
         UserLogin userLogin = new UserLogin();
         userLogin.setLoginTime(new Date());
@@ -382,6 +390,7 @@ public class UserServiceImpl  implements UserService{
      * @param token
      * @param user
      */
+    @Deprecated
     public void createAccessUser(String token,User user,Long studentId)throws Exception{
         AccessUser accessUser = new AccessUser();
         Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());