Нет описания

LoginCtrl.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.sharemao.manager.ctrl;
  2. import java.util.Map;
  3. import javax.servlet.http.HttpSession;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.nianzai.base.mvc.Context;
  6. import com.nianzai.base.mvc.annotation.Controller;
  7. import com.nianzai.base.mvc.annotation.Path;
  8. import com.nianzai.base.mvc.view.TextView;
  9. import com.nianzai.util.Tools;
  10. import com.sharemao.manager.entity.Account;
  11. import com.sharemao.manager.entity.Organize;
  12. import com.sharemao.manager.service.AccountService;
  13. import com.sharemao.manager.service.OrganizeService;
  14. import com.sharemao.manager.service.impl.AccountServiceImpl;
  15. import com.sharemao.manager.service.impl.OrganizeServiceImpl;
  16. import com.sharemao.manager.util.MenuUtil;
  17. import com.sharemao.manager.util.ProjectConstants;
  18. import com.sharemao.manager.util.LanguageUtil;
  19. @Controller
  20. public class LoginCtrl
  21. {
  22. private AccountService accServ=new AccountServiceImpl();
  23. private OrganizeService orgService = new OrganizeServiceImpl();
  24. @Path(value="/login.do")
  25. public TextView index(Context context) {
  26. TextView view=new TextView();
  27. HttpSession session = context.getRequest().getSession();
  28. Map<String,String> para=context.getParas();
  29. String username=para.get("username");
  30. //String verifyCode=para.get("verifyCode");
  31. String pwd=para.get("password");
  32. String lang=para.get("language");
  33. if (!Tools.isEmpty(lang)){
  34. LanguageUtil.init(lang);
  35. }
  36. if(session.isNew())
  37. return new TextView("/index.jsp");
  38. if(Tools.isEmpty(username) || Tools.isEmpty(pwd)) {
  39. //判断用户名和密码是否为空
  40. context.getRequest().setAttribute("error", "请输入用户名或密码");
  41. return new TextView("/index.jsp");
  42. }
  43. // String rand=(String)session.getAttribute("rand");
  44. // if(!rand.equals(verifyCode))
  45. // {
  46. // context.getRequest().setAttribute("error", "验证码不对");
  47. // return new TextView("/index.jsp");
  48. // }
  49. Account account=accServ.getAccount(username, pwd);
  50. //如果账号停用则不能登录
  51. if(account==null) {
  52. context.getRequest().setAttribute("error", "用户名或密码错误");
  53. view.setToPath("/index.jsp");
  54. } else if(account.getOrgstate()==1){
  55. context.getRequest().setAttribute("error", "该代理商已被禁用,当前无法登录");
  56. view.setToPath("/index.jsp");
  57. }else {
  58. session.setAttribute(ProjectConstants.sessionKey, account);
  59. //生成菜单保存在会话中
  60. JSONArray parentArrary=MenuUtil.getParentMenu(account);
  61. Organize org = orgService.getOrgById(account.getOrgid());
  62. context.getRequest().setAttribute("company", org.getCompany());
  63. context.getRequest().getSession().setAttribute("orgid", org.getId());
  64. context.getRequest().setAttribute("logo", org.getLogo());
  65. session.setAttribute("menus",parentArrary);
  66. context.getRequest().setAttribute("langstr", LanguageUtil.lang);
  67. view.setToPath("/view/main.jsp");
  68. }
  69. return view;
  70. }
  71. @Path(value="/logout.do")
  72. public TextView logout(Context context) {
  73. HttpSession session = context.getRequest().getSession();
  74. session.removeAttribute(ProjectConstants.sessionKey);
  75. session.removeAttribute("menus");
  76. return new TextView("/index.jsp");
  77. }
  78. }