1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package com.yihu.hos.system.service;
- import com.yihu.hos.common.constants.ContextAttributes;
- import com.yihu.hos.system.model.SystemUser;
- import com.yihu.hos.system.service.intf.ISystemManager;
- import com.yihu.hos.system.service.intf.IUserManager;
- import com.yihu.hos.tenant.model.TenantSession;
- import com.yihu.hos.web.framework.model.ActionResult;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import javax.servlet.http.HttpSession;
- /**
- * Created by HZP on 2016/02/26.
- */
- @Service("systemManager")
- public class SystemManager implements ISystemManager {
- @Autowired
- private IUserManager userManager;
- @Value("${spring.administrators}")
- private String saasAdmin;
- /*
- 登录操作
- */
- @Override
- public ActionResult loginAction(HttpSession session,String user,String password) throws Exception
- {
- ActionResult result = null;
- TenantSession tenantSession = (TenantSession)session.getAttribute(ContextAttributes.TENANT_SESSION);
- //特殊账户
- if(user.equals("admin") && password.equals("JKZL"))
- {
- SystemUser userInfo = new SystemUser();
- userInfo.setLoginCode("admin");
- userInfo.setUserName("管理员");
- session.setAttribute("userInfo",userInfo);
- tenantSession.setUserCode("admin");//设置租户code
- tenantSession.setRole("admin");//标识为管理员账号
- session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
- result = new ActionResult(true,"登录成功!");
- result.setData(tenantSession);
- return result;
- }
- //根据用户名/密码到总平台校验
- SystemUser userInfo = userManager.getUserByLoginCode(user);
- if(userInfo==null)
- {
- result = new ActionResult(false,"登录失败!用户不存在!");
- return result;
- }
- else{
- String saltValue =userInfo.getSaltValue();
- String userPassword = userInfo.getPassword();
- if(userPassword.equals(DigestUtils.md5Hex(password + saltValue)))
- {
- if (saasAdmin.equals(user)){
- tenantSession.setRole("admin");//标识为管理员账号
- }
- tenantSession.setUserCode(user);
- session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
- session.setAttribute("userInfo",userInfo);
- result = new ActionResult(true,"登录成功!");
- result.setData(tenantSession);
- return result;
- }
- else{
- result = new ActionResult(false,"登录失败!密码错误!");
- return result;
- }
- }
- }
- }
|