一、取消登录验证码
rap每隔一段时间会登录 session 失效,然后重新登录,半天左右时间可能要反复登录好几次。虽然登录时,chrome 是可以记住用户名密码的,但还要再输入验证码,并且验证码难以辨认经常输错。考虑到是本地部署 rap,对验证码的需求不大,因此修改三处代码关闭掉验证码验证。
(1)修改com.taobao.rigel.rap.account.web.action.AccountAction的doLogin方法,注释掉如下代码即可:
/* 去掉验证码限制
* String kaptchaExpected = (String)session.get(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
if(getKaptcha() == null || !getKaptcha().equals(kaptchaExpected)) {
setErrMsg("验证码错误");
return ERROR;
}
*/
(2)修改\src\main\webapp\tcom\template.rap.vm,注释掉如下代码:
<--
<input name="kaptcha" class="form-control" type="text" value="" placeholder="请输入验证码" style="width:200px;margin-top:10px;">
<img src="/Kaptcha.jpg" onclick="this.src='/Kaptcha.jpg?' + Math.random()" style="margin-top: 5px;">
-->
(3)修改\src\main\webapp\account\login.vm,注释掉如下代码:
<--
<div class="form-group">
<label for="kaptcha">验证码</label>
<input name="kaptcha" class="form-control" type="text" value="" placeholder="请输入验证码"/>
<img src="/Kaptcha.jpg" onclick="this.src='/Kaptcha.jpg?' + Math.random()" style="margin-top: 5px;">
</div>
-->
上述修改完成重新发布即可。
二、延长session过期时间
rap的默认session过期时间过短,导致一天要登录多次rap,经常在保存接口数据的时候提示登录失效要重新登录,比较影响工作效率,因此修改几处配置延长session过期时间(我这里是设置为7天)。
(1)修改com.taobao.rigel.rap.common.listener.SessionListener的sessionCreated方法:
增加代码event.getSession().setMaxInactiveInterval(86400*7)
public void sessionCreated(HttpSessionEvent event) {
ServletContext context = event.getSession().getServletContext();
//设置session过期时间
event.getSession().setMaxInactiveInterval(86400*7);//秒钟
// online users count processing
String key = ContextManager.KEY_COUNT_OF_ONLINE_USER_LIST;
if (context.getAttribute(key) == null) {
context.setAttribute(key, 0);
}
int curCountOfOnlineuserList = (Integer) context.getAttribute(key);
context.setAttribute(key, curCountOfOnlineuserList + 1);
}
(2)修改src\main\webapp\WEB-INF\web.xml,把session-timeout时间修改为10080分钟。
<session-config>
<session-timeout>10080</session-timeout>
</session-config>
(3)修改Tomcat/conf/web.xml,把session-timeout时间修改为10080分钟。
<session-config>
<session-timeout>10080</session-timeout>
</session-config>
上述修改完成重新发布即可。