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 ...
随机推荐
- 把DATATABLE,DS中的内容用HTML的方式显示
前几天,在搞一个数据显示的时候,因为是不固定的列的,所以需要动态创建列,这里面就运用一下,直接把数据库的Table显示在Html上,有两种方法,但是都有相应的缺点,第一个,如果内容太多,长度不好控制, ...
- EntityFramework 分页问题探讨之 OrderBy
应用场景 最近被应用程序中页面加载慢的问题所折磨,看似容易的问题,其实并不容易(已经持续两天时间了),经过"侦查",发现了两个"嫌疑犯": EntityFram ...
- Java:IDEA下使用JUNIT
JUnit单元测试--IntelliJ IDEA (本文转载自华行天下) 单元测试的基本使用 一.环境配置 使用idea IDE 进行单元测试,首先需要安装JUnit 插件. 1.安装JUnit插件步 ...
- MyEclipse打不开jsp文件 报错“Failed to create the part's controls"
本来写好了一套网站html代码,需要移植到myeclipse的jsp页面中,当复制代码完毕后,也是可以运行的并不报错,但一直有弹框提示有空指针,当关闭页面后再次打开就歇菜了,提示 我预感到这可能是my ...
- Kooboo CMS - Html.FrontHtml.Position 详解
DataContract 数据契约 http://www.cnblogs.com/Gavinzhao/archive/2010/06/01/1748736.html https://msdn.micr ...
- TCP滑动窗口机制
我们可以大概看一下上图的模型: 首先是AB之间三次握手建立TCP连接.在报文的交互过程中,A将自己的缓冲区大小(窗口大小)3发送给B,B同理,这样双方就知道了对端的窗口大小. A开始发送数据,A连续发 ...
- c#动态加载卸载DLL的方法
这篇文章介绍了c#动态加载卸载DLL的方法,有需要的朋友可以参考一下 c#中通过反射可以方便的动态加载dll程序集,但是如果你需要对dll进行更新,却发现.net类库没有提供卸载dll程序集的方法.在 ...
- 数据结构:单链表结构字符串(python版)
#!/urs/bin/env python # -*- coding:utf-8 -*- #异常类 class stringTypeError(TypeError): pass #节点类 class ...
- powershell脚本,命令行参数传值,并绑定变量的例子
这是小技巧文章,所以文章不长.但原创唯一,非常重要.我搜了下,还真没有人发 powershell怎样 [命令行 参数 绑定],所以我决定写成博客. 搜索关键字如下: powershell 命令行 参数 ...
- php实现设计模式之 单例模式
<?php /*单例模式:作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统全局地提供这个实例.(创建型模式) * * */ class singleton{ pr ...