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