package com.rouger.weboa.organization.view;import java.util.*;
import javax.servlet.http.*;import org.apache.log4j.*;
import org.apache.struts.action.*;
import com.rouger.weboa.organization.bean.*;
import com.rouger.weboa.organization.dao.*;
import com.rouger.weboa.organization.ldap.Ldap;
import com.rouger.weboa.util.DtreeUtil;
import com.rouger.weboa.util.DateUtil;
import com.rouger.weboa.util.MD5;
import UserSchedule.UserUnite;public class LoginAction extends Action {
static Logger log = Logger.getLogger(LoginAction.class.getName()); public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception { // DateUtil dateutil = new DateUtil();
// String strDate = dateutil.getToday();
// if(strDate.compareTo("2005-8-1") > 0)
// {
// request.setAttribute("loginInfo", "系统已经过期!");
// return (actionMapping.findForward("tologin"));
// } String jspPage = "tologin";
HttpSession session = request.getSession();
LoginForm loginForm = (LoginForm) actionForm;
TblUserDAO t = DAOFactory.getInstance().getTblUserDAO();
boolean result = false;
String loginInfo = "";
String passInfo = "";
String flag = "tologin";
flag = loginForm.getFlag(); log.debug("flag:=" + flag);
if (flag == null) {
flag = "tologin"; }
/**
* @todo:转入登陆界面
* zhuwen
*/
if (flag.equals("tologin")) {
jspPage = "tologin";
}
boolean isLogon = false;
/**
* 取消了部门与角色的关联
* @auther zhuwen
* @todo:用户登录
*/
if (flag.equals("login")) {
//password进行MD5转换
String p=new MD5().getMD5ofStr(loginForm.getPassword()); int count = t.CheckPassword(loginForm.getLoginname(), p);
TblUser tblUser = new TblUser();
tblUser = t.getByLoginName(loginForm.getLoginname());
TblUserInfo tblUserInfo = new TblUserInfo();
TblUserInfoDAO tblUserInfoDAO = DAOFactory.getInstance()
.getTblUserInfoDAO();
if (count > 0) {
session.setAttribute("tblUser", tblUser);
request.setAttribute("tblUser", tblUser);
session.setAttribute("loginname", loginForm.getLoginname());
session.setAttribute("password", loginForm.getPassword());
tblUserInfo = tblUserInfoDAO.select(tblUser.getUserId()
.toString());
session.setAttribute("userName", tblUserInfo.getUserName());
session.setAttribute("useId", tblUserInfo.getUserId()
.toString());
session.setAttribute("tblUserInfo", tblUserInfo);
//用户登录时,保存其角色集合 zhuwen 20041108
TblUserRoleDAO tblUserRoleDAO = DAOFactory.getInstance()
.getTblUserRoleDAO();
//根据用户取得角色
List roles = tblUserRoleDAO.getListByUser(tblUser);
//取得用户所属的部门
TblUdrelationDAO tblUdrelationDAO = DAOFactory.getInstance()
.getTblUdrelationDAO();
//List depats = tblUdrelationDAO.getListByUserId(tblUser.getUserId());
TblUhrelationDAO tblUhrelationDAO = DAOFactory.getInstance()
.getTblUhrelationDAO();
/* 这段代码由陈新华修改,原来的depats中对象不一致,现修改 */
List listbak = tblUdrelationDAO.getListByUserId(tblUser
.getUserId().toString());
List depats = new ArrayList();
if (listbak.size() > 0) {
for (int i = 0; i < listbak.size(); i++) {
depats.add(i, ((TblUdrelation) listbak.get(i))
.getTblDepat());
}
}
List headships = tblUhrelationDAO.getListByUserId(tblUser
.getUserId().toString());
//取出有职务的用户的部门
if (headships.size() > 0) {
for (java.util.Iterator it = headships.iterator(); it
.hasNext();) {
TblDepat tblDepat = new TblDepat();
TblHeadShip tblHeadShip = new TblHeadShip();
TblUhrelation tblUhrelation = new TblUhrelation();
tblUhrelation = (TblUhrelation) it.next();
tblHeadShip = tblUhrelation.getTblHeadShip();
tblDepat = tblHeadShip.getTblDepat();
depats.add(tblDepat);
}
}
session.setAttribute("depats", depats);
TblDepat tblDepat;
String deptName;
String defInteface;
//得到对应的默认主页面
for (int m = 0; depats.size() > m; m++) {
tblDepat = new TblDepat();
tblDepat = (TblDepat) depats.get(m);
deptName = tblDepat.getDeptName();
defInteface = tblDepat.getDefInteface();
session.setAttribute("defInteface", defInteface);
// out.print(defInteface);
// out.print(deptName);
break;
} session.setAttribute("roles", roles);
result = true;
jspPage = "success";
} else {
result = false;
}
if (result == false) {
loginInfo = "用户名或密码错误,请重新输入";
}
request.setAttribute("loginInfo", loginInfo);
}
/**
* @todo:修改密码
* zhuwen
*/
if (flag.equals("tomodifypass")) {
if (session.getAttribute("tblUser") == null) {
jspPage = "tologin";
} else {
jspPage = "tomodifypass";
}
} if (flag.equals("modifypass")) {
TblUser x = new TblUser();
x = (TblUser) session.getAttribute("tblUser");
TblUserInfo y = new TblUserInfo();
y = (TblUserInfo) session.getAttribute("tblUserInfo"); result = false;
if (!x.getPassword().equals(new MD5().getMD5ofStr(loginForm.getPassword()))) {
passInfo = "原密码输入有误,请重新输入";
result = true;
}
if (!loginForm.getPass1().equals(loginForm.getPass2())) {
passInfo = "新密码两次输入不一致,请重新输入";
result = true;
}
if (result) {
request.setAttribute("passInfo", passInfo);
jspPage = "tomodifypass";
} else {
/**
* @todo 如果OA系统已与邮件服务器配置好连接,刚增加用户至AD,
* @author zhuwen
*/
DtreeUtil dTreeUtil = new DtreeUtil();
String isLdap = dTreeUtil.getIni("ldap", "isLdap");
//Ldap ldap = new Ldap();
//if (isLdap.equals("1")) {
// ldap.updatePassword(y, x);
//} //进行MD5加密
String p=new MD5().getMD5ofStr(loginForm.getPass1()); x.setPassword(p);
t.update(x);
passInfo = "密码重置成功,下次请用新口令登录";
request.setAttribute("passInfo", passInfo);
jspPage = "modifypass"; //060704更新exoa中的相同用户密码
UserUnite un = new UserUnite();
un.updateOutDBPassword(x.getLoginname(),x.getPassword()); //更新NOTES邮件用户密码
un.updateNotesPassword(x.getLoginname(),loginForm.getPass1());
}
}
/**
* 退出系统
*/
if (flag.equals("exit")) {
session.removeAttribute("tblUser");
session.removeAttribute("loginname");
session.removeAttribute("password");
session.removeAttribute("userName");
session.removeAttribute("tblUserInfo");
session.removeAttribute("depats");
session.removeAttribute("roles");
jspPage = "exit";
} return (actionMapping.findForward(jspPage));
}
}
import javax.servlet.http.*;import org.apache.log4j.*;
import org.apache.struts.action.*;
import com.rouger.weboa.organization.bean.*;
import com.rouger.weboa.organization.dao.*;
import com.rouger.weboa.organization.ldap.Ldap;
import com.rouger.weboa.util.DtreeUtil;
import com.rouger.weboa.util.DateUtil;
import com.rouger.weboa.util.MD5;
import UserSchedule.UserUnite;public class LoginAction extends Action {
static Logger log = Logger.getLogger(LoginAction.class.getName()); public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception { // DateUtil dateutil = new DateUtil();
// String strDate = dateutil.getToday();
// if(strDate.compareTo("2005-8-1") > 0)
// {
// request.setAttribute("loginInfo", "系统已经过期!");
// return (actionMapping.findForward("tologin"));
// } String jspPage = "tologin";
HttpSession session = request.getSession();
LoginForm loginForm = (LoginForm) actionForm;
TblUserDAO t = DAOFactory.getInstance().getTblUserDAO();
boolean result = false;
String loginInfo = "";
String passInfo = "";
String flag = "tologin";
flag = loginForm.getFlag(); log.debug("flag:=" + flag);
if (flag == null) {
flag = "tologin"; }
/**
* @todo:转入登陆界面
* zhuwen
*/
if (flag.equals("tologin")) {
jspPage = "tologin";
}
boolean isLogon = false;
/**
* 取消了部门与角色的关联
* @auther zhuwen
* @todo:用户登录
*/
if (flag.equals("login")) {
//password进行MD5转换
String p=new MD5().getMD5ofStr(loginForm.getPassword()); int count = t.CheckPassword(loginForm.getLoginname(), p);
TblUser tblUser = new TblUser();
tblUser = t.getByLoginName(loginForm.getLoginname());
TblUserInfo tblUserInfo = new TblUserInfo();
TblUserInfoDAO tblUserInfoDAO = DAOFactory.getInstance()
.getTblUserInfoDAO();
if (count > 0) {
session.setAttribute("tblUser", tblUser);
request.setAttribute("tblUser", tblUser);
session.setAttribute("loginname", loginForm.getLoginname());
session.setAttribute("password", loginForm.getPassword());
tblUserInfo = tblUserInfoDAO.select(tblUser.getUserId()
.toString());
session.setAttribute("userName", tblUserInfo.getUserName());
session.setAttribute("useId", tblUserInfo.getUserId()
.toString());
session.setAttribute("tblUserInfo", tblUserInfo);
//用户登录时,保存其角色集合 zhuwen 20041108
TblUserRoleDAO tblUserRoleDAO = DAOFactory.getInstance()
.getTblUserRoleDAO();
//根据用户取得角色
List roles = tblUserRoleDAO.getListByUser(tblUser);
//取得用户所属的部门
TblUdrelationDAO tblUdrelationDAO = DAOFactory.getInstance()
.getTblUdrelationDAO();
//List depats = tblUdrelationDAO.getListByUserId(tblUser.getUserId());
TblUhrelationDAO tblUhrelationDAO = DAOFactory.getInstance()
.getTblUhrelationDAO();
/* 这段代码由陈新华修改,原来的depats中对象不一致,现修改 */
List listbak = tblUdrelationDAO.getListByUserId(tblUser
.getUserId().toString());
List depats = new ArrayList();
if (listbak.size() > 0) {
for (int i = 0; i < listbak.size(); i++) {
depats.add(i, ((TblUdrelation) listbak.get(i))
.getTblDepat());
}
}
List headships = tblUhrelationDAO.getListByUserId(tblUser
.getUserId().toString());
//取出有职务的用户的部门
if (headships.size() > 0) {
for (java.util.Iterator it = headships.iterator(); it
.hasNext();) {
TblDepat tblDepat = new TblDepat();
TblHeadShip tblHeadShip = new TblHeadShip();
TblUhrelation tblUhrelation = new TblUhrelation();
tblUhrelation = (TblUhrelation) it.next();
tblHeadShip = tblUhrelation.getTblHeadShip();
tblDepat = tblHeadShip.getTblDepat();
depats.add(tblDepat);
}
}
session.setAttribute("depats", depats);
TblDepat tblDepat;
String deptName;
String defInteface;
//得到对应的默认主页面
for (int m = 0; depats.size() > m; m++) {
tblDepat = new TblDepat();
tblDepat = (TblDepat) depats.get(m);
deptName = tblDepat.getDeptName();
defInteface = tblDepat.getDefInteface();
session.setAttribute("defInteface", defInteface);
// out.print(defInteface);
// out.print(deptName);
break;
} session.setAttribute("roles", roles);
result = true;
jspPage = "success";
} else {
result = false;
}
if (result == false) {
loginInfo = "用户名或密码错误,请重新输入";
}
request.setAttribute("loginInfo", loginInfo);
}
/**
* @todo:修改密码
* zhuwen
*/
if (flag.equals("tomodifypass")) {
if (session.getAttribute("tblUser") == null) {
jspPage = "tologin";
} else {
jspPage = "tomodifypass";
}
} if (flag.equals("modifypass")) {
TblUser x = new TblUser();
x = (TblUser) session.getAttribute("tblUser");
TblUserInfo y = new TblUserInfo();
y = (TblUserInfo) session.getAttribute("tblUserInfo"); result = false;
if (!x.getPassword().equals(new MD5().getMD5ofStr(loginForm.getPassword()))) {
passInfo = "原密码输入有误,请重新输入";
result = true;
}
if (!loginForm.getPass1().equals(loginForm.getPass2())) {
passInfo = "新密码两次输入不一致,请重新输入";
result = true;
}
if (result) {
request.setAttribute("passInfo", passInfo);
jspPage = "tomodifypass";
} else {
/**
* @todo 如果OA系统已与邮件服务器配置好连接,刚增加用户至AD,
* @author zhuwen
*/
DtreeUtil dTreeUtil = new DtreeUtil();
String isLdap = dTreeUtil.getIni("ldap", "isLdap");
//Ldap ldap = new Ldap();
//if (isLdap.equals("1")) {
// ldap.updatePassword(y, x);
//} //进行MD5加密
String p=new MD5().getMD5ofStr(loginForm.getPass1()); x.setPassword(p);
t.update(x);
passInfo = "密码重置成功,下次请用新口令登录";
request.setAttribute("passInfo", passInfo);
jspPage = "modifypass"; //060704更新exoa中的相同用户密码
UserUnite un = new UserUnite();
un.updateOutDBPassword(x.getLoginname(),x.getPassword()); //更新NOTES邮件用户密码
un.updateNotesPassword(x.getLoginname(),loginForm.getPass1());
}
}
/**
* 退出系统
*/
if (flag.equals("exit")) {
session.removeAttribute("tblUser");
session.removeAttribute("loginname");
session.removeAttribute("password");
session.removeAttribute("userName");
session.removeAttribute("tblUserInfo");
session.removeAttribute("depats");
session.removeAttribute("roles");
jspPage = "exit";
} return (actionMapping.findForward(jspPage));
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货