SystemManager.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.yihu.hos.system.service;
  2. import com.yihu.hos.common.constants.ContextAttributes;
  3. import com.yihu.hos.system.model.SystemUser;
  4. import com.yihu.hos.system.service.intf.ISystemManager;
  5. import com.yihu.hos.system.service.intf.IUserManager;
  6. import com.yihu.hos.tenant.model.TenantSession;
  7. import com.yihu.hos.web.framework.model.ActionResult;
  8. import org.apache.commons.codec.digest.DigestUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.stereotype.Service;
  12. import javax.servlet.http.HttpSession;
  13. /**
  14. * Created by HZP on 2016/02/26.
  15. */
  16. @Service("systemManager")
  17. public class SystemManager implements ISystemManager {
  18. @Autowired
  19. private IUserManager userManager;
  20. @Value("${spring.administrators}")
  21. private String saasAdmin;
  22. /*
  23. 登录操作
  24. */
  25. @Override
  26. public ActionResult loginAction(HttpSession session,String user,String password) throws Exception
  27. {
  28. ActionResult result = null;
  29. TenantSession tenantSession = (TenantSession)session.getAttribute(ContextAttributes.TENANT_SESSION);
  30. //特殊账户
  31. if(user.equals("admin") && password.equals("JKZL"))
  32. {
  33. SystemUser userInfo = new SystemUser();
  34. userInfo.setLoginCode("admin");
  35. userInfo.setUserName("管理员");
  36. session.setAttribute("userInfo",userInfo);
  37. tenantSession.setUserCode("admin");//设置租户code
  38. tenantSession.setRole("admin");//标识为管理员账号
  39. session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
  40. result = new ActionResult(true,"登录成功!");
  41. result.setData(tenantSession);
  42. return result;
  43. }
  44. //根据用户名/密码到总平台校验
  45. SystemUser userInfo = userManager.getUserByLoginCode(user);
  46. if(userInfo==null)
  47. {
  48. result = new ActionResult(false,"登录失败!用户不存在!");
  49. return result;
  50. }
  51. else{
  52. String saltValue =userInfo.getSaltValue();
  53. String userPassword = userInfo.getPassword();
  54. if(userPassword.equals(DigestUtils.md5Hex(password + saltValue)))
  55. {
  56. if (saasAdmin.equals(user)){
  57. tenantSession.setRole("admin");//标识为管理员账号
  58. }
  59. tenantSession.setUserCode(user);
  60. session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
  61. session.setAttribute("userInfo",userInfo);
  62. result = new ActionResult(true,"登录成功!");
  63. result.setData(tenantSession);
  64. return result;
  65. }
  66. else{
  67. result = new ActionResult(false,"登录失败!密码错误!");
  68. return result;
  69. }
  70. }
  71. }
  72. }