diff options
author | Vitaly Takmazov | 2018-05-18 15:33:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-07-24 14:35:02 +0300 |
commit | 8a0fbbd35c13054a947ea0d27ca117542bc452b9 (patch) | |
tree | 4266fbfaac3f1e268e780bc1cfa3cdc23ccd955c /juick-www/src/main/java/com/juick/www/controllers/SignUp.java | |
parent | 3fa18888d5ca53b59c778de3f829870614d05c27 (diff) |
JPA WIP
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers/SignUp.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/SignUp.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java index 02a8006b..11f02169 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java +++ b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java @@ -16,6 +16,7 @@ */ package com.juick.www.controllers; +import com.juick.User; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.UserUtils; @@ -95,7 +96,7 @@ public class SignUp { @RequestParam(required = false) String username, @RequestParam(required = false) String password) { com.juick.User visitor = UserUtils.getCurrentUser(); - int uid = 0; + User signedUser = visitor; if (hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) { throw new HttpBadRequestException(); @@ -107,20 +108,20 @@ public class SignUp { if (username.length() > 32) { throw new HttpBadRequestException(); } - uid = userService.checkPassword(username, password); + signedUser = userService.checkPassword(username, password); } else { - uid = visitor.getUid(); + signedUser = visitor; } - if (uid <= 0) { + if (signedUser.isAnonymous()) { throw new HttpForbiddenException(); } - if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, uid)) - && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, uid)) - && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, uid)) - && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid)) - && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, uid))) { + if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, signedUser)) + && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, signedUser)) + && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, signedUser)) + && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, signedUser)) + && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, signedUser.getUid()))) { throw new HttpBadRequestException(); } @@ -131,22 +132,22 @@ public class SignUp { // CHECK USERNAME - uid = userService.createUser(username, password); - if (uid <= 0) { + signedUser = userService.createUser(username, password); + if (signedUser.isAnonymous()) { throw new HttpBadRequestException(); } - if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, uid)) - && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, uid)) - && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, uid)) - && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid)) - && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, uid))) { + if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, signedUser)) + && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, signedUser)) + && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, signedUser)) + && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, signedUser)) + && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, signedUser.getUid()))) { throw new HttpBadRequestException(); } } if (visitor.isAnonymous()) { - hash = userService.getHashByUID(uid); + hash = userService.getHashForUser(signedUser); Cookie c = new Cookie("hash", hash); c.setMaxAge(365 * 24 * 60 * 60); response.addCookie(c); |