|
@@ -9,6 +9,8 @@ import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
|
|
|
+import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Example;
|
|
@@ -31,6 +33,7 @@ import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.UserRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.UserRoleRepo;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
|
* 用户服务类
|
|
@@ -88,7 +91,7 @@ public class UserService {
|
|
|
* @return
|
|
|
*/
|
|
|
public UserInfo login(String loginName,
|
|
|
- String password){
|
|
|
+ String password)throws Exception{
|
|
|
User user = userRepo.findByLoginName(loginName);
|
|
|
return loginProcess(user,password);
|
|
|
|
|
@@ -102,8 +105,8 @@ public class UserService {
|
|
|
* @return
|
|
|
*/
|
|
|
public UserInfo login(long orgId,
|
|
|
- String loginName,
|
|
|
- String password){
|
|
|
+ String loginName,
|
|
|
+ String password)throws Exception{
|
|
|
User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
|
|
|
return loginProcess(user,password);
|
|
|
}
|
|
@@ -114,12 +117,13 @@ public class UserService {
|
|
|
* @param password
|
|
|
* @return
|
|
|
*/
|
|
|
- public UserInfo loginProcess(User user,
|
|
|
- String password){
|
|
|
+ public UserInfo loginProcess(User user, String password)throws Exception{
|
|
|
if(user == null){
|
|
|
throw new RuntimeException("该用户不存在");
|
|
|
}else if(!user.getPassword().equals(password)){
|
|
|
throw new RuntimeException("密码错误");
|
|
|
+ }else if(!user.getEnable()){
|
|
|
+ throw new RuntimeException("该用户被禁用");
|
|
|
}else{
|
|
|
String token = AccessCtrlUtil.buildToken();
|
|
|
createAccessUser(token,user,null);
|
|
@@ -171,9 +175,19 @@ public class UserService {
|
|
|
userInfo.setToken(token);
|
|
|
userInfo.setType(user.getType().toString());
|
|
|
userInfo.setUserRoles(user.getUserRoles());
|
|
|
+ userInfo.setRoleNames(getRoleNames(user.getUserRoles()));
|
|
|
return userInfo;
|
|
|
}
|
|
|
|
|
|
+ public List<String> getRoleNames(List<UserRole> userRoles){
|
|
|
+
|
|
|
+ List<String> roleNameList = userRoles.stream()
|
|
|
+ .map(userRole -> RoleMeta.valueOf(userRole.getRoleCode()).getCnName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return roleNameList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 登出
|
|
|
* @param accessUser
|