package com.bysj.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.bysj.dao.AdminDAO;
import com.bysj.domain.Admin;

@Controller @Scope("prototype")
public class ChangePasswordAction {
	
	private String oldPassword;
	private String newPassword;
	private String newPassword2;

	@Resource AdminDAO adminDAO; 	
	
	public String getOldPassword() {
		return oldPassword;
	}


	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}


	public String getNewPassword() {
		return newPassword;
	}


	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}


	public String getNewPassword2() {
		return newPassword2;
	}


	public void setNewPassword2(String newPassword2) {
		this.newPassword2 = newPassword2;
	}


	/*修改密码*/
	public String execute() {
		ActionContext ctx = ActionContext.getContext(); 
		if(oldPassword.equals("")) {
			ctx.put("error",  java.net.URLEncoder.encode("旧密码必须输入!"));
			return "error";
		}
		if(newPassword.equals("")) {
			ctx.put("error",  java.net.URLEncoder.encode("新密码必须输入!"));
			return "error";
		}
		if(!newPassword2.equals(newPassword)) {
			ctx.put("error",  java.net.URLEncoder.encode("两次密码输入不一致!"));
			return "error";
		}
		String username = (String)ctx.getSession().get("username"); 
		Admin admin = adminDAO.GetAdmin(username); 
		if(!admin.getPassword().equals(oldPassword)) {
			ctx.put("error",  java.net.URLEncoder.encode("旧密码不正确!"));
			return "error";
		}
		
		try { 
			adminDAO.ChangePassword(username,newPassword);
			ctx.put("message",  java.net.URLEncoder.encode("密码修改成功!"));
			return "change_success";
		} catch (Exception e) {
			e.printStackTrace();
			ctx.put("error",  java.net.URLEncoder.encode("密码更新失败!"));
			return "error";
		}  
		
	}

}
最近下载更多
AOAO1234  LV2 2024年12月23日
2716804680  LV9 2023年12月6日
ziv5466123  LV7 2023年6月26日
stonerose66  LV1 2023年6月23日
北方菜  LV11 2023年4月16日
2017143155  LV12 2022年11月14日
gch666  LV6 2022年6月8日
hebe灬  LV5 2022年5月21日
isfrand  LV4 2022年4月19日
丁春秋  LV2 2022年3月15日
最近浏览更多
AOAO1234  LV2 2024年12月23日
momomo228  LV2 2024年11月22日
LoveSummer  LV6 2024年10月31日
zhangjishao 2024年10月15日
暂无贡献等级
angaochong  LV5 2024年10月10日
krispeng  LV14 2024年8月25日
cy5201 2024年6月24日
暂无贡献等级
2267068802  LV1 2024年6月12日
郑郭辉 2024年6月3日
暂无贡献等级
pi-nang  LV2 2024年3月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友