/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.yuntong.action.actionform.Y_UpdatePwdForm;
import com.yuntong.business.vo.Y_UserInfoVO;
import com.yuntong.encrypt.MD5;
import com.yuntong.service.Y_IUserManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 04-21-2007
 * 修改用户密码
 * XDoclet definition:
 * @struts.action path="/y_UpdatePwd" name="y_UpdatePwdForm" scope="request" validate="true"
 * @struts.action-forward name="go" path="/Y_XGMM_1.jsp" redirect="true"
 */
public class Y_UpdatePwdAction extends DispatchAction {
	private Y_IUserManagerService userManagerService; 
	public Y_IUserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(Y_IUserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Y_UpdatePwdForm y_UpdatePwdForm = (Y_UpdatePwdForm) form;
		String pwd1=y_UpdatePwdForm.getPwd1();
		String pwd2= y_UpdatePwdForm.getPwd2();
		String pwd3=y_UpdatePwdForm.getPwd3();
		HttpSession session=request.getSession();
		Y_UserInfoVO vo=new Y_UserInfoVO();
		vo =(Y_UserInfoVO) session.getAttribute("userLoginInfo");
		String userPwd=vo.getUserPwd();
		//得到当前用户编号
		int userId=vo.getUserId();
		//判断老密码
		if(!MD5.MD5Encrypt(pwd1).equals(userPwd)){
			session.setAttribute("Y_pwdinfo", "当前密码输入错误！！");
			return mapping.findForward("go");
		}
		//判断密码确认
		if(!pwd2.equals(pwd3)){
			session.setAttribute("Y_pwdinfo", "两此输入密码不一致！！");
			return mapping.findForward("go");
		}
		//修改密码		
		userManagerService.updateUserPwd(userId, MD5.MD5Encrypt(pwd3));
		session.setAttribute("Y_pwdinfo", "修改成功！！");
		return  mapping.findForward("go");
	}
}