UserLoginAction.java~102~
上传用户: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.             Cookie cookies[] = request.getCookies();
  22.             String username = "";
  23.             String passport = "";
  24.            /* if (cookies == null) {
  25.                 username = StringFilter.filter(tl.isNull(request.
  26.                         getParameter(
  27.                                 "usern").trim()));
  28.                 passport = StringFilter.filter(tl.isNull(request.
  29.                         getParameter(
  30.                                 "pwd").trim()));
  31.                 if (request.getParameter("rem") != null)
  32.                     if (request.getParameter("rem").equals("1")) {
  33.                         Cookie cookie = new Cookie("officeoluinfo",
  34.                                 username + "_" + passport);
  35.                         cookie.setMaxAge(360 * 24 * 60 * 60);
  36.                         response.addCookie(cookie);
  37.                     }
  38.             } else {
  39.                 System.out.println("cookie is not null");
  40.             }
  41.             if (cookies != null) {
  42.                 for (int i = 0; i < cookies.length; i++) {
  43.                     Cookie coo = cookies[i];
  44.                     System.out.println(coo.getName());
  45.                     if (coo.getName().equals("officeoluinfo")) {
  46.                         String value = coo.getValue();
  47.                         String[] info = value.split("_");
  48.                         username = info[0];
  49.                         System.out.println("cookie un : " + username);
  50.                         passport = info[1];
  51.                         System.out.println("cookie pwd : " + passport);
  52.                     } else {
  53.                         username = StringFilter.filter(tl.isNull(request.
  54.                                 getParameter(
  55.                                         "usern").trim()));
  56.                         passport = StringFilter.filter(tl.isNull(request.
  57.                                 getParameter(
  58.                                         "pwd").trim()));
  59.                         if (request.getParameter("rem") != null)
  60.                             if (request.getParameter("rem").equals("1")) {
  61.                                Cookie cookie = new Cookie("officeoluinfo",
  62.                                         username + "_" + passport);
  63.                                 cookie.setMaxAge(360 * 24 * 60 * 60);
  64.                                 response.addCookie(cookie);
  65.                             }
  66.                     }
  67.                 }
  68.             }*/
  69.             if (username != null && !username.equals("") && passport != null &&
  70.                 !username.equals("")) {
  71.                 int i = tl.getLogin(username, passport);
  72.                 if (i == 1) {
  73.                     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 =  '" +
  74.                                    username + "' ";
  75.                     //用户部门
  76.                     String uidsql = "select id from [user] where username = '" +
  77.                                     username + "'";
  78.                     //用户id,[user]表
  79.                     String[][] ud = dbc.getArray(udsql);
  80.                     String[][] uid = dbc.getArray(uidsql);
  81.                     if (ud == null) {
  82.                         request.setAttribute("msg", "你不属于某个部门,请修改你的用户部门后再登录!");
  83.                         return mapping.findForward("err");
  84.                     }
  85.                     String popesql =
  86.                             //用户权限
  87.                             /*"select p.popedom from [user] as u inner join usergroup as ug "+
  88.                                                         "on u.id = ug.userid inner join groupmanage as gm on ug.usergroup = gm.usergroup inner join popedomgroup as pg "+
  89.                                                         "on pg.popegroup = gm.popegroup inner join popedom as p on p.id = pg.id inner join deparment as d "+
  90.                             "on ug.depid = d.id and u.username = '"+username+"' order by u.username";
  91.                             */
  92.                             "select p.pope from userpope as up inner join pope as p on up.popeid = p.id and up.userid = '" +
  93.                             uid[0][0] + "'";
  94.                     //System.out.println("UserLoginAction popesql: "+popesql);
  95.                     String[][] uinfo = dbc.getArray(popesql);
  96.                     HttpSession se = request.getSession();
  97.                     se.setAttribute("UD", ud[0][0]);
  98.                     se.setAttribute("UDID", ud[0][1]);
  99.                     se.setAttribute("UN", username);
  100.                     se.setAttribute("UID", uid[0][0]);
  101.                     se.setAttribute("POPE", uinfo[0][0]);
  102.                     se.setAttribute("LOGIN", "OK");
  103.                     return mapping.findForward("succ");
  104.                 } else {
  105.                     request.setAttribute("msg", "用户名或者密码错误!");
  106.                     return mapping.findForward("err");
  107.                 }
  108.             } else {
  109.                 request.setAttribute("msg", "用户名或者密码都不能为空!");
  110.                 return mapping.findForward("err");
  111.             }
  112.         } catch (Exception ex) {
  113.             ex.printStackTrace();
  114.         }
  115.         request.setAttribute("msg", "用户登录出错!请重试!");
  116.         return mapping.findForward("err");
  117.     }
  118. }