aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com/juick')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Login.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Settings.java28
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/SignUp.java35
5 files changed, 39 insertions, 38 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Login.java b/juick-www/src/main/java/com/juick/www/controllers/Login.java
index cb7df833..783430b2 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Login.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Login.java
@@ -44,7 +44,7 @@ public class Login {
}
@GetMapping("/login/success")
public String getSuccessLogin(ModelMap model) {
- model.addAttribute("hash", userService.getHashByUID(UserUtils.getCurrentUser().getUid()));
+ model.addAttribute("hash", userService.getHashForUser(UserUtils.getCurrentUser()));
return "views/login_success";
}
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
index f416cb86..dc0729e0 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
@@ -456,7 +456,7 @@ public class MessagesWWW {
return "redirect:/login";
}
String title = "PM: Inbox";
- List<com.juick.Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid());
+ List<com.juick.Message> msgs = pmQueriesService.getLastPMInbox(visitor);
fillUserModel(model, visitor, visitor);
model.addAttribute("title", title);
model.addAttribute("visitor", visitor);
@@ -473,7 +473,7 @@ public class MessagesWWW {
return "redirect:/login";
}
String title = "PM: Sent";
- List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid());
+ List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor);
if (WebUtils.isNotUserName(uname)) {
uname = StringUtils.EMPTY;
@@ -549,7 +549,7 @@ public class MessagesWWW {
"<meta property=\"og:title\" content=\"" + msg.getUser().getName() + " at Juick\" />\n" +
"<meta property=\"og:description\" content=\"" + cardDescription + "\" />\n" +
"<meta name=\"Description\" content=\"" + cardDescription + "\" />\n";
- String twitterName = crosspostService.getTwitterName(msg.getUser().getUid());
+ String twitterName = crosspostService.getTwitterName(msg.getUser());
if (StringUtils.isNotEmpty(twitterName)) {
headers += "<meta name=\"twitter:creator\" content=\"@" + twitterName + "\" />\n";
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index a464add2..a88698af 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -161,7 +161,7 @@ public class NewMessage {
params.add("body", rid == 0 ? String.format("#%d %s", mid, body) : String.format("#%d/%d %s", mid, rid, body));
- params.add("hash", userService.getHashByUID(visitor.getUid()));
+ params.add("hash", userService.getHashForUser(visitor));
if (StringUtils.isNotEmpty(attachmentFName.toString())) {
params.add("img", attachmentFName.toASCIIString());
}
@@ -203,7 +203,7 @@ public class NewMessage {
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
params.add("body", String.format("@%s %s", userTo.getName(), body));
- params.add("hash", userService.getHashByUID(visitor.getUid()));
+ params.add("hash", userService.getHashForUser(visitor));
URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/post").build().toUri();
ResponseEntity<CommandResult> result = rest.postForEntity(
postUri,
@@ -240,7 +240,7 @@ public class NewMessage {
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
params.add("body", body);
- params.add("hash", userService.getHashByUID(visitor.getUid()));
+ params.add("hash", userService.getHashForUser(visitor));
if (StringUtils.isNotEmpty(attachmentFName.toString())) {
params.add("img", attachmentFName.toASCIIString());
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
index f9527423..702f52af 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
@@ -96,20 +96,20 @@ public class Settings {
model.addAttribute("visitor", visitor);
model.addAttribute("tags", tagService.getPopularTags());
model.addAttribute("auths", userService.getAuthCodes(visitor));
- model.addAttribute("email_active", emailService.getNotificationsEmail(visitor.getUid()));
+ model.addAttribute("email_active", emailService.getNotificationsEmail(visitor));
model.addAttribute("ehash", userService.getEmailHash(visitor));
model.addAttribute("emails", userService.getEmails(visitor));
model.addAttribute("jids", userService.getAllJIDs(visitor));
List<String> hours = IntStream.rangeClosed(0, 23).boxed()
.map(i -> StringUtils.leftPad(String.format("%d", i), 2, "0")).collect(Collectors.toList());
model.addAttribute("hours", hours);
- model.addAttribute("fbstatus", crosspostService.getFbCrossPostStatus(visitor.getUid()));
- model.addAttribute("twitter_name", crosspostService.getTwitterName(visitor.getUid()));
- model.addAttribute("telegram_name", crosspostService.getTelegramName(visitor.getUid()));
+ model.addAttribute("fbstatus", crosspostService.getFbCrossPostStatus(visitor));
+ model.addAttribute("twitter_name", crosspostService.getTwitterName(visitor));
+ model.addAttribute("telegram_name", crosspostService.getTelegramName(visitor));
model.addAttribute("notify_options", subscriptionService.getNotifyOptions(visitor));
model.addAttribute("userinfo", userService.getUserInfo(visitor));
if (page.equals("auth-email")) {
- if (emailService.verifyAddressByCode(visitor.getUid(), request.getParameter("code"))) {
+ if (emailService.verifyAddressByCode(visitor, request.getParameter("code"))) {
;
model.addAttribute("result", "OK!");
} else {
@@ -140,7 +140,7 @@ public class Settings {
case "password":
if (userService.updatePassword(visitor, request.getParameter("password"))) {
result = "<p>Password has been changed.</p>";
- String hash = userService.getHashByUID(visitor.getUid());
+ String hash = userService.getHashForUser(visitor);
Cookie c = new Cookie("hash", hash);
c.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(c);
@@ -186,9 +186,9 @@ public class Settings {
}
break;
case "email-add":
- if (!emailService.verifyAddressByCode(visitor.getUid(), request.getParameter("account"))) {
+ if (!emailService.verifyAddressByCode(visitor, request.getParameter("account"))) {
String authCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
- if (emailService.addVerificationCode(visitor.getUid(), request.getParameter("account"), authCode)) {
+ if (emailService.addVerificationCode(visitor, request.getParameter("account"), authCode)) {
Session session = Session.getDefaultInstance(System.getProperties());
try {
MimeMessage message = new MimeMessage(session);
@@ -210,14 +210,14 @@ public class Settings {
}
break;
case "email-del":
- if (emailService.deleteEmail(visitor.getUid(), request.getParameter("account"))) {
+ if (emailService.deleteEmail(visitor, request.getParameter("account"))) {
result = "<p>Deleted. <a href=\"/settings\">Back</a>.</p>";
} else {
result = "<p>An error occured while deleting.</p>";
}
break;
case "email-subscr":
- if (emailService.setNotificationsEmail(visitor.getUid(), request.getParameter("account"))) {
+ if (emailService.setNotificationsEmail(visitor, request.getParameter("account"))) {
result = String.format("<p>Saved! Will send notifications to <strong>%s</strong>." +
"</p><p><a href=\"/settings\">Back</a></p>", request.getParameter("account"));
} else {
@@ -225,7 +225,7 @@ public class Settings {
}
break;
case "twitter-del":
- crosspostService.deleteTwitterToken(visitor.getUid());
+ crosspostService.deleteTwitterToken(visitor);
for (Cookie cookie : request.getCookies()) {
if (cookie.getName().equals("request_token")) {
cookie.setMaxAge(0);
@@ -246,15 +246,15 @@ public class Settings {
result = "<p><a href=\"/settings\">Back</a></p>";
break;
case "facebook-disable":
- crosspostService.disableFBCrosspost(visitor.getUid());
+ crosspostService.disableFBCrosspost(visitor);
result = "<p><a href=\"/settings\">Back</a></p>";
break;
case "facebook-enable":
- crosspostService.enableFBCrosspost(visitor.getUid());
+ crosspostService.enableFBCrosspost(visitor);
result = "<p><a href=\"/settings\">Back</a></p>";
break;
case "vk-del":
- crosspostService.deleteVKUser(visitor.getUid());
+ crosspostService.deleteVKUser(visitor);
result = "<p><a href=\"/settings\">Back</a></p>";
break;
default:
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);