UserLoginAction.java
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:6k
源码类别:

OA系统

开发平台:

Java

  1. package officeol.mc.actions;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.Action;
  8. import java.io.*;
  9. import officeol.mc.tools.*;
  10. import javax.servlet.http.HttpSession;
  11. import javax.servlet.http.Cookie;
  12. public class UserLoginAction extends Action {
  13.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  14.                                  HttpServletRequest request,
  15.                                  HttpServletResponse response) {
  16.         try {
  17.             request.setCharacterEncoding("GBK");
  18.             DBConn dbc = new DBConn();
  19.             Tool tl = new Tool();
  20.             PopedomCheck pc = new PopedomCheck();
  21.             String username = username = StringFilter.filter(tl.isNull(request.
  22.                         getParameter(
  23.                                 "usern").trim()));
  24.                String passport = StringFilter.filter(tl.isNull(request.
  25.                         getParameter(
  26.                                 "pwd").trim()));
  27.            /*Cookie cookies[] = request.getCookies();
  28.              if (cookies == null) {
  29.                 username = StringFilter.filter(tl.isNull(request.
  30.                         getParameter(
  31.                                 "usern").trim()));
  32.                 passport = StringFilter.filter(tl.isNull(request.
  33.                         getParameter(
  34.                                 "pwd").trim()));
  35.                 if (request.getParameter("rem") != null)
  36.                     if (request.getParameter("rem").equals("1")) {
  37.                         Cookie cookie = new Cookie("officeoluinfo",
  38.                                 username + "_" + passport);
  39.                         cookie.setMaxAge(360 * 24 * 60 * 60);
  40.                         response.addCookie(cookie);
  41.                     }
  42.             } else {
  43.                 System.out.println("cookie is not null");
  44.             }
  45.             if (cookies != null) {
  46.                 for (int i = 0; i < cookies.length; i++) {
  47.                     Cookie coo = cookies[i];
  48.                     System.out.println(coo.getName());
  49.                     if (coo.getName().equals("officeoluinfo")) {
  50.                         String value = coo.getValue();
  51.                         String[] info = value.split("_");
  52.                         username = info[0];
  53.                         System.out.println("cookie un : " + username);
  54.                         passport = info[1];
  55.                         System.out.println("cookie pwd : " + passport);
  56.                     } else {
  57.                         username = StringFilter.filter(tl.isNull(request.
  58.                                 getParameter(
  59.                                         "usern").trim()));
  60.                         passport = StringFilter.filter(tl.isNull(request.
  61.                                 getParameter(
  62.                                         "pwd").trim()));
  63.                         if (request.getParameter("rem") != null)
  64.                             if (request.getParameter("rem").equals("1")) {
  65.                                Cookie cookie = new Cookie("officeoluinfo",
  66.                                         username + "_" + passport);
  67.                                 cookie.setMaxAge(360 * 24 * 60 * 60);
  68.                                 response.addCookie(cookie);
  69.                             }
  70.                     }
  71.                 }
  72.             }*/
  73.             if (username != null && !username.equals("") && passport != null &&
  74.                 !username.equals("")) {
  75.                 int i = tl.getLogin(username, passport);
  76.                 if (i == 1) {
  77.                     String udsql = "select d.deparname,d.id from [user] as u inner join userdepar as ud on u.id = ud.userid inner join deparment as d on ud.deparid = d.id and u.username =  '" +
  78.                                    username + "' ";
  79.                     //用户部门
  80.                     String uidsql = "select id from [user] where username = '" +
  81.                                     username + "'";
  82.                     //用户id,[user]表
  83.                     String[][] ud = dbc.getArray(udsql);
  84.                     String[][] uid = dbc.getArray(uidsql);
  85.                     if (ud == null) {
  86.                         request.setAttribute("msg", "你不属于某个部门,请修改你的用户部门后再登录!");
  87.                         return mapping.findForward("err");
  88.                     }
  89.                     String popesql =
  90.                             //用户权限
  91.                             /*"select p.popedom from [user] as u inner join usergroup as ug "+
  92.                                                         "on u.id = ug.userid inner join groupmanage as gm on ug.usergroup = gm.usergroup inner join popedomgroup as pg "+
  93.                                                         "on pg.popegroup = gm.popegroup inner join popedom as p on p.id = pg.id inner join deparment as d "+
  94.                             "on ug.depid = d.id and u.username = '"+username+"' order by u.username";
  95.                             */
  96.                             "select p.pope from userpope as up inner join pope as p on up.popeid = p.id and up.userid = '" +
  97.                             uid[0][0] + "'";
  98.                     //System.out.println("UserLoginAction popesql: "+popesql);
  99.                     String[][] uinfo = dbc.getArray(popesql);
  100.                     HttpSession se = request.getSession();
  101.                     se.setAttribute("UD", ud[0][0]);
  102.                     se.setAttribute("UDID", ud[0][1]);
  103.                     se.setAttribute("UN", username);
  104.                     se.setAttribute("UID", uid[0][0]);
  105.                     se.setAttribute("POPE", uinfo[0][0]);
  106.                     se.setAttribute("LOGIN", "OK");
  107.                     return mapping.findForward("succ");
  108.                 } else {
  109.                     request.setAttribute("msg", "用户名或者密码错误!");
  110.                     return mapping.findForward("err");
  111.                 }
  112.             } else {
  113.                 request.setAttribute("msg", "用户名或者密码都不能为空!");
  114.                 return mapping.findForward("err");
  115.             }
  116.         } catch (Exception ex) {
  117.             ex.printStackTrace();
  118.         }
  119.         request.setAttribute("msg", "用户登录出错!请重试!");
  120.         return mapping.findForward("err");
  121.     }
  122. }