5.3的版本中新增用户是默认有密码时限的设置,但登录后没有提供密码时限的校验提示用户修改密码
如果需要在登录后进行密码时限校验提示用户修改密码,参考如下实现:
1.在/BIZ/SA/OPM/system/system.process.m中loginAction执行后事件,获取action返回接口中的密码时限(天)和密码修改时间
再获取当前时间与密码修改时间之间相差的天数,如果大于密码时限的天数可以用session中设置一个值
public static void systemProcessAfterLoginAction() {
List users = (List) ContextHelper.getActionContext().getActionResult();//获取action的返回结果
Integer sPasswordTimeLimit = (Integer) users.get(8);//获取密码时限(天)
if(Utils.isNotNull(sPasswordTimeLimit) && sPasswordTimeLimit != -1){//判断密码时限不为空切不等于-1
Date sPasswordModifyTime = (Date) users.get(9);//获取密码修改时间
Date newDate = new Date();
long nd = 1000 * 24 * 60 * 60;
long diff = newDate.getTime() - sPasswordModifyTime.getTime();// 获得当前时间和密码修改时间两个时间的毫秒时间差异
long day = diff / nd;// 计算差多少天
if(day>sPasswordTimeLimit){//相差天数大于密码时限天数给session赋值
HttpSession session = ContextHelper.getSessionContext().getSession();
session.setAttribute("needModifyPassword", true);
}
}
}
需要注意在BIZ层的构建路径中把apache-tomcat\lib\servlet-api.jar导入,在java中引用
import javax.servlet.http.HttpSession;
2.把存储到session中的信息放到Context中,便于前端登录后获取判断
参考如何将自己需要的信息写到Context上下文中
如下:
public static Object getSysParams() {
Map hashMap = (HashMap<String, String>) ContextHelper.getSysParams(); //平台默认的context中的信息
HttpSession session = ContextHelper.getSessionContext().getSession();
hashMap.put("needModifyPassword", session.getAttribute("needModifyPassword"));//把自己要的信息put到map中
return hashMap;
}
3.通过扩展空间修改/UI2/portal/base/base.js
(1).添加引用
var WindowDialog = require("$UI/system/components/justep/windowDialog/windowDialog");
(2).在Model.prototype.loginDialogReceive = function(event) {函数中获取context中的信息判断打开修改密码的弹出框
Model.prototype.loginDialogReceive = function(event) {
this.beforeLogin();
this.setPortalContext(event.data);
this.afterLogin();
var needModifyPassword = this.getContext().getSystemParameter("needModifyPassword");
if(needModifyPassword){
if (confirm("您的密码已经过期,请按确定健进入密码修改窗。"))
var changePasswordDialog = new WindowDialog({
src : "$UI/portal/base/login/changePassword.w",
parentNode : root,
process : "/portal/process/message/messageProcess",
activity : "mainActivity",
title : '修改密码',
showTitle : false,
status : 'normal',
});
changePasswordDialog.open();
}
};
$UI/portal/base/login/changePassword.w的定义是直接复制的/UI2/portal/base/changePassword下的changePassword.w和对应的js文件
对/UI2/portal_X/base/login/changePassword.js文件中的修改
(1).添加引用
var MsgDialog = require("$UI/system/components/justep/messageDialog/messageDialog");
(2).代码修改
var result = this.changePassword(newValue, oldValue);
if(result.flag === false)
justep.Util.hint(result.message, {type: 'danger', parent: this.getRootNode()});
else
justep.Util.hint("密码修改成功!", {type: 'success', parent: this.getRootNode()});
修改为:
var result = this.changePassword(newValue, oldValue);
if (result.flag === false)
justep.Util.hint(result.message, {
type : 'danger',
parent : this.getRootNode()
});
else {
var me = this;
this.msg = new MsgDialog({
parentNode : me.getRootNode(),
type : 'OK',
message : "密码修改成功,后续请使用新密码登录!",
title:'修改密码提示'
});
this.msg.on('onOK', function(event) {
me.close();
}, me);
this.msg.show();
}
评一波