Home > Java > javaTutorial > PlayFramework completely implements an APP (7)

PlayFramework completely implements an APP (7)

黄舟
Release: 2016-12-23 16:42:55
Original
1428 people have browsed it

1. Add verification code

application Controller add captcha()

public static void captcha() {
Images.Captcha captcha = Images.captcha();
renderBinary(captcha);
}

 

Add Route

GET /captcha Application.captcha

Visit http://localhost:9000/captcha The verification code image has been implemented. What needs to be done now is to verify that the input information is consistent with the verification code

Modify the captcha() methodPlayFramework completely implements an APP (7)

public static void captcha(String id) {

Images.Captcha captcha = Images.captcha();

String code = captcha.getText("#E4EAFD");

Cache.set(id, code, "10mn");

renderBinary(captcha);

}


 

Modify the show() method

public static void show(Long id) {

Post post = Post.findById(id);

String randomID = Codec.UUID();

render(post, randomID);

}



 

Modify the show.html page

Add the verification code image and verification control below the Comment

for="content">Your message:

" " ;p>

PlayFramework completely implements an APP (7)


 
 
                                                                 Verify

Modify postComment method

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);
}




Modify the show.html page

#{ifErrors}
error">
                                       ${errors[0]}                                                                                                                                  Net (m.sbmmt.com)!



Related labels:
app
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template