UserLoginAction.java~103~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:6k
源码类别:
OA系统
开发平台:
Java
- package officeol.mc.actions;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.Action;
- import java.io.*;
- import officeol.mc.tools.*;
- import javax.servlet.http.HttpSession;
- import javax.servlet.http.Cookie;
- public class UserLoginAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- try {
- request.setCharacterEncoding("GBK");
- DBConn dbc = new DBConn();
- Tool tl = new Tool();
- PopedomCheck pc = new PopedomCheck();
- Cookie cookies[] = request.getCookies();
- String username = username = StringFilter.filter(tl.isNull(request.
- getParameter(
- "usern").trim()));
- String passport = StringFilter.filter(tl.isNull(request.
- getParameter(
- "pwd").trim()));
- /* if (cookies == null) {
- username = StringFilter.filter(tl.isNull(request.
- getParameter(
- "usern").trim()));
- passport = StringFilter.filter(tl.isNull(request.
- getParameter(
- "pwd").trim()));
- if (request.getParameter("rem") != null)
- if (request.getParameter("rem").equals("1")) {
- Cookie cookie = new Cookie("officeoluinfo",
- username + "_" + passport);
- cookie.setMaxAge(360 * 24 * 60 * 60);
- response.addCookie(cookie);
- }
- } else {
- System.out.println("cookie is not null");
- }
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- Cookie coo = cookies[i];
- System.out.println(coo.getName());
- if (coo.getName().equals("officeoluinfo")) {
- String value = coo.getValue();
- String[] info = value.split("_");
- username = info[0];
- System.out.println("cookie un : " + username);
- passport = info[1];
- System.out.println("cookie pwd : " + passport);
- } else {
- username = StringFilter.filter(tl.isNull(request.
- getParameter(
- "usern").trim()));
- passport = StringFilter.filter(tl.isNull(request.
- getParameter(
- "pwd").trim()));
- if (request.getParameter("rem") != null)
- if (request.getParameter("rem").equals("1")) {
- Cookie cookie = new Cookie("officeoluinfo",
- username + "_" + passport);
- cookie.setMaxAge(360 * 24 * 60 * 60);
- response.addCookie(cookie);
- }
- }
- }
- }*/
- if (username != null && !username.equals("") && passport != null &&
- !username.equals("")) {
- int i = tl.getLogin(username, passport);
- if (i == 1) {
- 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 = '" +
- username + "' ";
- //用户部门
- String uidsql = "select id from [user] where username = '" +
- username + "'";
- //用户id,[user]表
- String[][] ud = dbc.getArray(udsql);
- String[][] uid = dbc.getArray(uidsql);
- if (ud == null) {
- request.setAttribute("msg", "你不属于某个部门,请修改你的用户部门后再登录!");
- return mapping.findForward("err");
- }
- String popesql =
- //用户权限
- /*"select p.popedom from [user] as u inner join usergroup as ug "+
- "on u.id = ug.userid inner join groupmanage as gm on ug.usergroup = gm.usergroup inner join popedomgroup as pg "+
- "on pg.popegroup = gm.popegroup inner join popedom as p on p.id = pg.id inner join deparment as d "+
- "on ug.depid = d.id and u.username = '"+username+"' order by u.username";
- */
- "select p.pope from userpope as up inner join pope as p on up.popeid = p.id and up.userid = '" +
- uid[0][0] + "'";
- //System.out.println("UserLoginAction popesql: "+popesql);
- String[][] uinfo = dbc.getArray(popesql);
- HttpSession se = request.getSession();
- se.setAttribute("UD", ud[0][0]);
- se.setAttribute("UDID", ud[0][1]);
- se.setAttribute("UN", username);
- se.setAttribute("UID", uid[0][0]);
- se.setAttribute("POPE", uinfo[0][0]);
- se.setAttribute("LOGIN", "OK");
- return mapping.findForward("succ");
- } else {
- request.setAttribute("msg", "用户名或者密码错误!");
- return mapping.findForward("err");
- }
- } else {
- request.setAttribute("msg", "用户名或者密码都不能为空!");
- return mapping.findForward("err");
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- request.setAttribute("msg", "用户登录出错!请重试!");
- return mapping.findForward("err");
- }
- }