前天用ExtJS做了个修改密码及验证的小应用,共享!
---ExtJS部分--------------------
Ext.BLANK_IMAGE_URL = 'html/js/ext/resources/images/default/s.gif';
Ext.onReady(function() {
Ext.QuickTips.init();
/**
* 修改用户密码
*/
var pswFormPanel = new Ext.form.FormPanel({
url : 'system/updateUserPsw.action',
labelAlign : 'right',
frame : true,
defaultType : 'textfield',
items : [{
fieldLabel : '您的旧密码',
name : 'PASSWORD',
inputType: 'password',
allowBlank : false,
blankText : '请输入正确的旧密码!',
anchor : '97%'
},{
fieldLabel : '输入新密码',
name : 'ACCPASSWD',
id : 'NEWPASSWORD',
inputType: 'password',
allowBlank : false,
blankText : '密码不能为空!',
minLength:6,
minLengthText:'密码长度最少6位!',
maxLength:20,
maxLengthText:'密码长度最多20位!',
anchor : '97%'
},{
fieldLabel : '确认新密码',
name : 'checkPsw',
inputType: 'password',
allowBlank : false,
blankText : '密码不能为空',
minLength:6,
minLengthText:'密码长度最少6位!',
maxLength:20,
maxLengthText:'密码长度最多20位!',
id : 'repeatPassword',
vtype : 'repeatPassword',
vtypeText : "您两次输入的新密码不一致!",
confirmTo : 'NEWPASSWORD',
anchor : '97%'
}]
});
//密码窗口
this.pswWindow = new Ext.Window({
title : '修改密码',
el : 'pswWin',
layout : 'fit',
width : 360,
height : 175,
minWidth : 300,
minHeight : 200,
buttonAlign : 'center',
closeAction : 'hide',
modal : true,
maximizable : true,
plain : true,
constrain : true,
defaultButton : 0,
border : false,
items : [pswFormPanel],
buttons: [{
text:'提交',
handler : function(){
pswFormPanel.getForm().submit({
success : function(form , action) {
self.pswWindow.hide();
Ext.Msg.alert("提示",action.result.msg);
},
failure : function(form, action) {
if(action.failureType == Ext.form.Action.SERVER_INVALID){
Ext.Msg.alert("错误", "您输入的旧密码有误!");
form.reset();
} else {
Ext.Msg.alert("错误", "您输入的新密码不一致!");
}
}
});
}
}, {
text :'取消',
handler : function() {
self.pswWindow.hide();
}
}]
});
showPswWindow = function(){
self.pswWindow.show();
}
});
Ext.apply(Ext.form.VTypes,{
repeatPassword : function(val,field){
if(field.confirmTo){
var pwd = Ext.get(field.confirmTo);
if(val.trim() != pwd.getValue().trim()){
return false;
}
return true;
}
}
});
---Java部分--------------------
配置文件就不写了。
--action中---------
//修改用户密码
public void updateUserPsw(){
Long userid = StringUtil.toLong(user.get("USERID"));
boolean psw = userService.updatePsw(userid, $map());
this.renderText("{success : " + psw + ",msg:'密码修改成功!'}");
}
--service中---------
/**
* 修改用户密码
* @param userid
*/
public boolean updatePsw(Long userid, Map map);
--imp中---------
public boolean updatePsw(Long userid, Map map) {
map.put("userid", userid);
HashMap psw = (HashMap<?, ?>) this.queryForObject("UserInfo.getUserPswByUserId", map);
if (!psw.get("PASSWORD").toString().trim().equals(UtilMD5.crypt(map.get("PASSWORD").toString().trim()))){
return false;
}
map.put("ACCPASSWD",UtilMD5.crypt(map.get("ACCPASSWD").toString().trim()));
this.update("UserInfo.updateUserPsw",map);
return true;
}
---ibatis部分--------------------
<!-- 获取用户密码 -->
<select id="getUserPswByUserId" resultClass="java.util.HashMap">
SELECT T.PASSWORD FROM S_USER T WHERE USERID = #userid#
</select>
<!-- 修改用户密码 -->
<update id="updateUserPsw">
UPDATE S_USER T
SET T.PASSWORD = #ACCPASSWD#,
T.ACCPASSWD = #ACCPASSWD#
WHERE
T.USERID = #userid#
</update>
---界面效果图如下附件--- -----------------