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下方添加验证码图片,和验证控件
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}
${errors[0]}
#{/ifErrors}
以上就是PlayFramework完整实现一个APP(七)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版