aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www/controllers')
-rw-r--r--src/main/java/com/juick/www/controllers/SignUp.java39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/main/java/com/juick/www/controllers/SignUp.java b/src/main/java/com/juick/www/controllers/SignUp.java
index 3b052e18..9516ddf7 100644
--- a/src/main/java/com/juick/www/controllers/SignUp.java
+++ b/src/main/java/com/juick/www/controllers/SignUp.java
@@ -19,6 +19,7 @@ package com.juick.www.controllers;
import com.juick.model.User;
import com.juick.util.HttpBadRequestException;
import com.juick.util.HttpForbiddenException;
+import com.juick.util.UsernameTakenException;
import com.juick.www.WebApp;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
@@ -103,14 +104,18 @@ public class SignUp {
User current;
if (hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) {
- throw new HttpBadRequestException();
+ modelMap.addAttribute("result", "Invalid request");
+ modelMap.addAttribute("visitor", visitor);
+ return "views/signup_result";
}
if (action.charAt(0) == 'l') {
if (visitor.isAnonymous()) {
if (username.length() > 32) {
- throw new HttpBadRequestException();
+ modelMap.addAttribute("result", "Invalid request");
+ modelMap.addAttribute("visitor", visitor);
+ return "views/signup_result";
}
current = userService.checkPassword(username, password).orElseThrow(HttpForbiddenException::new);
} else {
@@ -118,7 +123,9 @@ public class SignUp {
}
if (current.getUid() <= 0) {
- throw new HttpForbiddenException();
+ modelMap.addAttribute("result", "Invalid request");
+ modelMap.addAttribute("visitor", visitor);
+ return "views/signup_result";
}
if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, current.getUid()))
@@ -132,20 +139,29 @@ public class SignUp {
emailService.deleteAuthCode(hash);
} else {
if (type.equals("xmpp")) {
- modelMap.addAttribute("visitor", visitor);
modelMap.addAttribute("result", "XMPP support is disabled for new users");
- return "views/settings_result";
+ } else {
+ modelMap.addAttribute("result", "Invalid request");
}
- throw new HttpBadRequestException();
+ modelMap.addAttribute("visitor", visitor);
+ return "views/signup_result";
}
}
} else { // Create new account
if (username.length() < 2 || username.length() > 16 || !username.matches("^[a-zA-Z0-9\\-]+$") || password.length() < 6 || password.length() > 32) {
- throw new HttpBadRequestException();
+ modelMap.addAttribute("visitor", visitor);
+ modelMap.addAttribute("result", "Bad username or password");
+ return "views/signup_result";
}
- current = userService.createUser(username, password).orElseThrow(HttpBadRequestException::new);
+ try {
+ current = userService.createUser(username, password).orElseThrow(HttpBadRequestException::new);
+ } catch(UsernameTakenException e) {
+ modelMap.addAttribute("visitor", visitor);
+ modelMap.addAttribute("result", e.getMessage());
+ return "views/signup_result";
+ }
if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, current.getUid()))
&& !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, current.getUid()))
@@ -156,11 +172,12 @@ public class SignUp {
emailService.deleteAuthCode(hash);
} else {
if (type.equals("xmpp")) {
- modelMap.addAttribute("visitor", visitor);
modelMap.addAttribute("result", "XMPP support is disabled for new users");
- return "views/settings_result";
+ } else {
+ modelMap.addAttribute("result", "Invalid request");
}
- throw new HttpBadRequestException();
+ modelMap.addAttribute("visitor", visitor);
+ return "views/signup_result";
}
}
}