Ofbiz登陆添加验证码功能

本文首先感谢网上的Ofbiz的博客文章!!! 

从controller.xml中
<request-map uri="login">
<security https="true" auth="false"/>
<event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="login"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="login"/>
</request-map>

因此:
<view-map name="login" type="screen" page="component://party/widget/partymgr/CommonScreens.xml#login"/>

CommonScreens.xml文件中

<screen name="login">
<section>
<widgets>
<decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
<decorator-section name="body">
<platform-specific>
<html><html-template location="component://common/webcommon/login.ftl"/></html>
</platform-specific>
</decorator-section>
</decorator-screen>
</widgets>
</section>
</screen>


Login.flt中


<img align=absbottom vspace=2 border=0 src="<@ofbizUrl>/CreateImage?Image=${encryRandom}&Rgb=255|0|0</@ofbizUrl>" title="验证码图片"></p>

<#assign random = Static["org.ofbiz.webapp.control.Picture"].getRandom()>
<#assign encryRandom = Static["org.ofbiz.webapp.control.Picture"].manage(random)>


controller.xml文件中

<!--pht-->
<request-map uri="CreateImage">
<event type="java" path="org.ofbiz.webapp.control.CreateImage" invoke="make"/>
<response name="success" type="none"/>
<response name="error" type="none"/>
</request-map>

LoginWorker.java 类中的login方法:

String attach = null;
String get_attach = null;
if (attach == null)
attach = request.getParameter("attach");
if (get_attach == null)
get_attach = request.getParameter("get_attach");
if (get_attach == null) {
String errMsg = "系统错误,请再次登录!";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
String tmp = Picture.discrypt(get_attach);
if (!attach.equals(tmp)) {
String errMsg = "请输入正确的验证码!";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

因此在login.flt 中:
<#assign attach = Static["org.ofbiz.webapp.control.Picture"].discrypt(encryRandom)>
<input type="text" class="inputBox" name="attach" value="${attach}" size="4"/>





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值