WANG 6 жил өмнө
parent
commit
1d1999dc20

+ 121 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/Auth2Controller.java

@@ -0,0 +1,121 @@
+package cn.com.qmth.examcloud.core.basic.api.controller;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.google.common.collect.Maps;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.base.enums.AccountType;
+import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
+import cn.com.qmth.examcloud.core.basic.service.AuthService;
+import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 废弃登陆. 保留原因:第三方接口鉴权
+ *
+ * @author WANGWEI
+ * @date 2018年11月19日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Transactional
+@RestController
+@RequestMapping("/api/ecs_core/user")
+public class Auth2Controller extends ControllerSupport {
+
+	@Autowired
+	UserRepo userRepo;
+
+	@Autowired
+	AuthService authService;
+
+	/**
+	 * 系统遗留,谨慎修改
+	 *
+	 * @author WANGWEI
+	 * @param loginName
+	 * @param password
+	 * @return
+	 */
+	@ApiOperation(value = "登录1", notes = "登录")
+	@PostMapping("/login")
+	public Map<String, Object> login1(@RequestParam String loginName, @RequestParam String password,
+			@RequestParam(required = false) Long rootOrgId) {
+		return login(loginName, password, rootOrgId);
+	}
+
+	/**
+	 * 系统遗留,谨慎修改
+	 *
+	 * @author WANGWEI
+	 * @param rootOrgId
+	 * @param loginName
+	 * @param password
+	 * @return
+	 */
+	@ApiOperation(value = "登录2", notes = "登录")
+	@PostMapping("/login/{rootOrgId}")
+	public Map<String, Object> login2(@PathVariable long rootOrgId, @RequestParam String loginName,
+			@RequestParam String password) {
+		return login(loginName, password, rootOrgId);
+	}
+
+	/**
+	 * 废弃的登陆
+	 *
+	 * @author WANGWEI
+	 * @param loginName
+	 * @param password
+	 * @param rootOrgId
+	 * @return
+	 */
+	private Map<String, Object> login(String loginName, String password, Long rootOrgId) {
+
+		UserEntity user = null;
+		if (null != rootOrgId) {
+			user = userRepo.findByRootOrgIdAndLoginName(rootOrgId, loginName);
+		} else {
+			List<UserEntity> userList = userRepo.findByLoginName(loginName);
+			if (CollectionUtils.isNotEmpty(userList)) {
+				user = null;
+			}
+			if (1 == userList.size()) {
+				user = userList.get(0);
+			} else if (1 < userList.size()) {
+				throw new StatusException("B-001003", "不同顶级机构下存在相同登录名");
+			}
+		}
+
+		if (user == null) {
+			throw new StatusException("B-001001", "该用户不存在");
+		} else if (!user.getEnable()) {
+			throw new StatusException("B-001002", "该用户被禁用");
+		}
+
+		LoginInfo loginInfo = new LoginInfo();
+		loginInfo.setAccountType(AccountType.COMMON_LOGIN_NAME.name());
+		loginInfo.setAccountValue(user.getLoginName());
+		loginInfo.setPassword(user.getPassword());
+		loginInfo.setRootOrgId(user.getRootOrgId());
+		User loginUser = authService.login(loginInfo);
+
+		Map<String, Object> ret = Maps.newHashMap();
+		ret.put("userId", loginUser.getUserId());
+		ret.put("token", loginUser.getKey() + ":" + loginUser.getToken());
+		return ret;
+	}
+
+}

+ 0 - 82
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -43,7 +43,6 @@ import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserDomain;
 import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserFormDomain;
 import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
-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.RoleRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
@@ -52,8 +51,6 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserRoleRelationEntity;
-import cn.com.qmth.examcloud.core.basic.service.AuthService;
-import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
 import cn.com.qmth.examcloud.core.basic.service.impl.UserServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
@@ -77,9 +74,6 @@ public class UserController extends ControllerSupport {
 	@Autowired
 	RoleRepo roleRepo;
 
-	@Autowired
-	AuthService authService;
-
 	@Autowired
 	UserRoleRelationRepo userRoleRelationRepo;
 
@@ -561,80 +555,4 @@ public class UserController extends ControllerSupport {
 		}
 	}
 
-	/**
-	 * 系统遗留,谨慎修改
-	 *
-	 * @author WANGWEI
-	 * @param loginName
-	 * @param password
-	 * @return
-	 */
-	@ApiOperation(value = "登录1", notes = "登录")
-	@PostMapping("/login")
-	public Map<String, Object> login1(@RequestParam String loginName, @RequestParam String password,
-			@RequestParam(required = false) Long rootOrgId) {
-		return login(loginName, password, rootOrgId);
-	}
-
-	/**
-	 * 系统遗留,谨慎修改
-	 *
-	 * @author WANGWEI
-	 * @param rootOrgId
-	 * @param loginName
-	 * @param password
-	 * @return
-	 */
-	@ApiOperation(value = "登录2", notes = "登录")
-	@PostMapping("/login/{rootOrgId}")
-	public Map<String, Object> login2(@PathVariable long rootOrgId, @RequestParam String loginName,
-			@RequestParam String password) {
-		return login(loginName, password, rootOrgId);
-	}
-
-	/**
-	 * 废弃的登陆
-	 *
-	 * @author WANGWEI
-	 * @param loginName
-	 * @param password
-	 * @param rootOrgId
-	 * @return
-	 */
-	private Map<String, Object> login(String loginName, String password, Long rootOrgId) {
-
-		UserEntity user = null;
-		if (null != rootOrgId) {
-			user = userRepo.findByRootOrgIdAndLoginName(rootOrgId, loginName);
-		} else {
-			List<UserEntity> userList = userRepo.findByLoginName(loginName);
-			if (CollectionUtils.isNotEmpty(userList)) {
-				user = null;
-			}
-			if (1 == userList.size()) {
-				user = userList.get(0);
-			} else if (1 < userList.size()) {
-				throw new StatusException("B-001003", "不同顶级机构下存在相同登录名");
-			}
-		}
-
-		if (user == null) {
-			throw new StatusException("B-001001", "该用户不存在");
-		} else if (!user.getEnable()) {
-			throw new StatusException("B-001002", "该用户被禁用");
-		}
-
-		LoginInfo loginInfo = new LoginInfo();
-		loginInfo.setAccountType(AccountType.COMMON_LOGIN_NAME.name());
-		loginInfo.setAccountValue(user.getLoginName());
-		loginInfo.setPassword(user.getPassword());
-		loginInfo.setRootOrgId(user.getRootOrgId());
-		User loginUser = authService.login(loginInfo);
-
-		Map<String, Object> ret = Maps.newHashMap();
-		ret.put("userId", loginUser.getUserId());
-		ret.put("token", loginUser.getKey() + ":" + loginUser.getToken());
-		return ret;
-	}
-
 }