Play Framework 完整实现一个APP(七)
1.添加验证码
Application Controller添加captcha()
public static void captcha() {
Images.Captcha captcha = Images.captcha();
renderBinary(captcha);
}
添加Route
GET /captcha Application.captcha
访问 http://localhost:9000/captcha
验证码图片已经实现了,现在需要做的是验证输入信息与验证码一致
修改captcha()方法
public static void captcha(String id) {
Images.Captcha captcha = Images.captcha();
String code = captcha.getText("#E4EAFD");
Cache.set(id, code, "10mn");
renderBinary(captcha);
}
修改show()方法
public static void show(Long id) {
Post post = Post.findById(id);
String randomID = Codec.UUID();
render(post, randomID);
}
修改show.html页面
在Comment下方添加验证码图片,和验证控件
<p>
<label for="content">Your message: </label>
<textarea name="content" id="content">${params.content}</textarea>
</p>
<p>
<label for="code">Please type the code below: </label>
<img src="@{Application.catcha(randomId)}">
<br />
<input type="text" name="code" id="code" size="18" value="" />
<input type="hidden" name="randomId" value="${randomId}" />
</p>
<p>
<input type="submit" value="Submit your comment" />
</p>
2.验证
修改postComment 方法
public static void postComment(
Long postId,
@Required(message="Author is required") String author,
@Required(message="A message is required") String content,
@Required(message="Please type the code") String code,
String randomId) {
Post post = Post.findById(postId);
validation.equals(code, Cache.get(randomId)).message("Invalid code. Please type it again"); if(validation.hasErrors()) {
render("Application/show.html", post);
} post.addComment(author, content);
flash.success("Thanks for posting %s", author);
Cache.delete(randomId);
show(postId);
}
修改show.html页面
#{ifErrors}
<p class="error">
${errors[0]}
</p>
#{/ifErrors}
..
Play Framework 完整实现一个APP(七)的更多相关文章
- Play Framework 完整实现一个APP(十一)
添加权限控制 1.导入Secure module,该模块提供了一个controllers.Secure控制器. /conf/application.conf # Import the secure m ...
- Play Framework 完整实现一个APP(五)
程序以及基本可用了,需要继续完善页面 1.创建页面模板 创建文件 app/views/tags/display.html *{ Display a post in one of these modes ...
- Play Framework 完整实现一个APP(二)
1.开发DataModel 在app\moders 下新建User.java package models; import java.util.*; import javax.persistence. ...
- Play Framework 完整实现一个APP(十四)
添加测试 ApplicationTest.java @Test public void testAdminSecurity() { Response response = GET("/adm ...
- Play Framework 完整实现一个APP(十三)
添加用户编辑区 1.修改Admin.index() public static void index() { List<Post> posts = Post.find("auth ...
- Play Framework 完整实现一个APP(十二)
1.定制CRUD管理页面 > play crud:ov --layout 替换生成文件内容 app/views/CRUD/layout.html #{extends 'admin.html' / ...
- Play Framework 完整实现一个APP(十)
1.定制Comment列表 新增加Comment list页面,执行命令行 > play crud:ov --template Comments/list 会生成/app/views/Comme ...
- Play Framework 完整实现一个APP(九)
添加增删改查操作 1.开启CRUD Module 在/conf/application.conf 中添加 # Import the crud module module.crud=${play.pat ...
- Play Framework 完整实现一个APP(八)
创建Tag标签 1.创建Model @Entity @Table(name = "blog_tag") public class Tag extends Model impleme ...
随机推荐
- tomcat匹配请求流程(原创)
tomcat8.0.36 配置Connector属性allowTrace为true时,允许TRACE方法,默认禁止. tomcat8.0.36有一个BUG,该BUG在8.0.37里被修复,就是一个解析 ...
- html5 meta(移动端)介绍及使用
随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择.然而,每一款手机有不同的分辨率,不同屏幕 ...
- Java 图的遍历-LeetCode200
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- 微信小程序小技巧系列《二》show内容展示,上传文件编码问题
作者:gou-tian 来自:github show内容展示 尝试用微信小程序的template组件实现.同时,尝试页面间转跳时传参,在目标页面引入模板文件实现 写的更少,做的更多 篇幅有限详细代码此 ...
- (二十)WebGIS中图层树功能的设计和实现
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 在GIS的桌面工具中,比如arcgis desktop或者S ...
- PHP数组及简单函数
PHP函数: 1.简单函数 四要素:返回类型,函数名,参数列表,函数体 function Show() { echo "hello"; } Show(); 运行结果:hellow ...
- JS代码实现的聊天框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【JUC】JDK1.8源码分析之CountDownLatch(五)
一.前言 分析完了CyclicBarrier后,下面分析CountDownLatch,CountDownLatch用于同步一个或多个任务,强制他们等待由其他任务执行的一组操作完成.CountDownL ...
- 测试为什么Low
你从来没有因为一个歌手不会写曲填词而说歌手很Low! 你从来没有因为一个演员不会摄影.唱歌而说演员很Low! 你从来没有因为一个记者不会摄影,拍照而说记者很Low! 你从来没有因为一个美食家不会烧菜, ...
- Halcon11与VS2010联合开发
刚开始学习Halcon,需要使用Halcon与C++联合开发软件,查了网上的资料都是Halcon10的,我用的是Halcon11和VS2010的开发环境,实践了一下发现有一些问题,于是把自己的配置的过 ...