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

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