|
@@ -16,7 +16,9 @@ import cn.com.qmth.mps.enums.Role;
|
|
import cn.com.qmth.mps.service.AuthService;
|
|
import cn.com.qmth.mps.service.AuthService;
|
|
import cn.com.qmth.mps.service.UserService;
|
|
import cn.com.qmth.mps.service.UserService;
|
|
import cn.com.qmth.mps.util.ActiveDataUtil;
|
|
import cn.com.qmth.mps.util.ActiveDataUtil;
|
|
|
|
+import cn.com.qmth.mps.util.ByteUtil;
|
|
import cn.com.qmth.mps.util.HttpUtil;
|
|
import cn.com.qmth.mps.util.HttpUtil;
|
|
|
|
+import cn.com.qmth.mps.util.SHA256;
|
|
import cn.com.qmth.mps.vo.AdminLoginVo;
|
|
import cn.com.qmth.mps.vo.AdminLoginVo;
|
|
import net.sf.json.JSONObject;
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
@@ -45,21 +47,21 @@ public class AuthServiceImpl implements AuthService {
|
|
if(jo.containsKey("errmsg")) {
|
|
if(jo.containsKey("errmsg")) {
|
|
throw new StatusException("登录失败,"+jo.getString("errmsg"));
|
|
throw new StatusException("登录失败,"+jo.getString("errmsg"));
|
|
}
|
|
}
|
|
- UserEntity userE=userService.getByLoginName(phone);
|
|
|
|
- if(userE==null) {
|
|
|
|
|
|
+ UserEntity userEntity=userService.getByLoginName(phone);
|
|
|
|
+ if(userEntity==null) {
|
|
throw new StatusException("该手机号不存在");
|
|
throw new StatusException("该手机号不存在");
|
|
}
|
|
}
|
|
- if(!userE.getEnable()) {
|
|
|
|
|
|
+ if(!userEntity.getEnable()) {
|
|
throw new StatusException("该用户已禁用");
|
|
throw new StatusException("该用户已禁用");
|
|
}
|
|
}
|
|
- if(!userE.getRoleId().equals(Role.SECTION_LEADER.getId())) {
|
|
|
|
|
|
+ if(!userEntity.getRoleId().equals(Role.SECTION_LEADER.getId())) {
|
|
throw new StatusException("该用户不是科组长");
|
|
throw new StatusException("该用户不是科组长");
|
|
}
|
|
}
|
|
User user = new User();
|
|
User user = new User();
|
|
- user.setName(userE.getName());
|
|
|
|
- user.setSchoolId(userE.getSchoolId());
|
|
|
|
- user.setId(userE.getId());
|
|
|
|
- user.setRole(Role.getById(userE.getRoleId()));
|
|
|
|
|
|
+ user.setName(userEntity.getName());
|
|
|
|
+ user.setSchoolId(userEntity.getSchoolId());
|
|
|
|
+ user.setId(userEntity.getId());
|
|
|
|
+ user.setRole(Role.getById(userEntity.getRoleId()));
|
|
user.setAccessToken(FastUUID.get());
|
|
user.setAccessToken(FastUUID.get());
|
|
user.buildKey();
|
|
user.buildKey();
|
|
ActiveDataUtil.userLogin(user);
|
|
ActiveDataUtil.userLogin(user);
|
|
@@ -71,6 +73,45 @@ public class AuthServiceImpl implements AuthService {
|
|
vo.setRole(user.getRole());
|
|
vo.setRole(user.getRole());
|
|
return vo;
|
|
return vo;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public AdminLoginVo loginAdmin(String loginName, String password) {
|
|
|
|
+ UserEntity userEntity=userService.getByLoginName(loginName);
|
|
|
|
+ if(userEntity==null) {
|
|
|
|
+ throw new StatusException("账号不存在");
|
|
|
|
+ }
|
|
|
|
+ if(!userEntity.getEnable()) {
|
|
|
|
+ throw new StatusException("该用户已禁用");
|
|
|
|
+ }
|
|
|
|
+ if(userEntity.getRoleId().equals(Role.SECTION_LEADER.getId())) {
|
|
|
|
+ throw new StatusException("科组长无权限登录");
|
|
|
|
+ }
|
|
|
|
+ byte[] bytes = SHA256.encode(password);
|
|
|
|
+ String encodePassword = ByteUtil.toHexAscii(bytes);
|
|
|
|
+ if (!encodePassword.equals(userEntity.getPassword())) {
|
|
|
|
+ throw new StatusException("密码错误");
|
|
|
|
+ }
|
|
|
|
+ User user = new User();
|
|
|
|
+ user.setName(userEntity.getName());
|
|
|
|
+ user.setSchoolId(userEntity.getSchoolId());
|
|
|
|
+ user.setId(userEntity.getId());
|
|
|
|
+ user.setRole(Role.getById(userEntity.getRoleId()));
|
|
|
|
+ user.setAccessToken(FastUUID.get());
|
|
|
|
+ user.buildKey();
|
|
|
|
+ ActiveDataUtil.userLogin(user);
|
|
|
|
+ AdminLoginVo vo=new AdminLoginVo();
|
|
|
|
+ vo.setAccessToken(user.getAccessToken());
|
|
|
|
+ vo.setName(user.getName());
|
|
|
|
+ vo.setSessionId(user.getSessionId());
|
|
|
|
+ vo.setSchoolId(user.getSchoolId());
|
|
|
|
+ vo.setRole(user.getRole());
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void logout(User user) {
|
|
|
|
+ ActiveDataUtil.userLogout(user.getId());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|