Merge pull request #160 from Doha2012/master

modify need captcha
This commit is contained in:
Eugen 2015-03-10 21:42:18 +02:00
commit 2c9dece9ce
2 changed files with 27 additions and 7 deletions

View File

@ -24,6 +24,8 @@ public class User {
private Date tokenExpiration; private Date tokenExpiration;
private boolean needCaptcha;
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<Post> posts; private List<Post> posts;
@ -71,6 +73,14 @@ public class User {
this.tokenExpiration = tokenExpiration; this.tokenExpiration = tokenExpiration;
} }
public boolean isCaptchaNeeded() {
return needCaptcha;
}
public void setNeedCaptcha(boolean needCaptcha) {
this.needCaptcha = needCaptcha;
}
public List<Post> getPosts() { public List<Post> getPosts() {
return posts; return posts;
} }

View File

@ -71,8 +71,8 @@ public class RedditController {
@RequestMapping("/post") @RequestMapping("/post")
public final String showSubmissionForm(final Model model) { public final String showSubmissionForm(final Model model) {
final String needsCaptchaResult = needsCaptcha(); final boolean isCaptchaNeeded = getCurrentUser().isCaptchaNeeded();
if (needsCaptchaResult.equalsIgnoreCase("true")) { if (isCaptchaNeeded) {
final String iden = getNewCaptcha(); final String iden = getNewCaptcha();
model.addAttribute("iden", iden); model.addAttribute("iden", iden);
} }
@ -81,8 +81,8 @@ public class RedditController {
@RequestMapping("/postSchedule") @RequestMapping("/postSchedule")
public final String showSchedulePostForm(final Model model) { public final String showSchedulePostForm(final Model model) {
final String needsCaptchaResult = needsCaptcha(); final boolean isCaptchaNeeded = getCurrentUser().isCaptchaNeeded();
if (needsCaptchaResult.equalsIgnoreCase("true")) { if (isCaptchaNeeded) {
model.addAttribute("msg", "Sorry, You do not have enought karma"); model.addAttribute("msg", "Sorry, You do not have enought karma");
return "submissionResponse"; return "submissionResponse";
} }
@ -92,7 +92,7 @@ public class RedditController {
@RequestMapping(value = "/schedule", method = RequestMethod.POST) @RequestMapping(value = "/schedule", method = RequestMethod.POST)
public final String schedule(final Model model, @RequestParam final Map<String, String> formParams) throws ParseException { public final String schedule(final Model model, @RequestParam final Map<String, String> formParams) throws ParseException {
logger.info("User scheduling Post with these parameters: " + formParams.entrySet()); logger.info("User scheduling Post with these parameters: " + formParams.entrySet());
final User user = userReopsitory.findByAccessToken(redditRestTemplate.getAccessToken().getValue()); final User user = getCurrentUser();
final Post post = new Post(); final Post post = new Post();
post.setUser(user); post.setUser(user);
post.setSent(false); post.setSent(false);
@ -116,7 +116,7 @@ public class RedditController {
@RequestMapping("/posts") @RequestMapping("/posts")
public final String getScheduledPosts(final Model model) { public final String getScheduledPosts(final Model model) {
final User user = userReopsitory.findByAccessToken(redditRestTemplate.getAccessToken().getValue()); final User user = getCurrentUser();
final List<Post> posts = postReopsitory.findByUser(user); final List<Post> posts = postReopsitory.findByUser(user);
model.addAttribute("posts", posts); model.addAttribute("posts", posts);
return "postListView"; return "postListView";
@ -160,6 +160,10 @@ public class RedditController {
// === private // === private
private User getCurrentUser() {
return userReopsitory.findByAccessToken(redditRestTemplate.getAccessToken().getValue());
}
private final MultiValueMap<String, String> constructParams(final Map<String, String> formParams) { private final MultiValueMap<String, String> constructParams(final Map<String, String> formParams) {
final MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>(); final MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
param.add(RedditApiConstants.API_TYPE, "json"); param.add(RedditApiConstants.API_TYPE, "json");
@ -211,9 +215,15 @@ public class RedditController {
user.setAccessToken(token.getValue()); user.setAccessToken(token.getValue());
user.setRefreshToken(token.getRefreshToken().getValue()); user.setRefreshToken(token.getRefreshToken().getValue());
user.setTokenExpiration(token.getExpiration()); user.setTokenExpiration(token.getExpiration());
userReopsitory.save(user);
} }
final String needsCaptchaResult = needsCaptcha();
if (needsCaptchaResult.equalsIgnoreCase("true")) {
user.setNeedCaptcha(true);
} else {
user.setNeedCaptcha(false);
}
userReopsitory.save(user);
} }
} }