aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/User.java27
-rw-r--r--src/main/java/com/juick/model/UserInfo.java60
-rw-r--r--src/main/java/com/juick/server/XMPPConnection.java4
-rw-r--r--src/main/java/com/juick/server/api/Users.java14
-rw-r--r--src/main/java/com/juick/server/configuration/SecurityConfig.java2
-rw-r--r--src/main/java/com/juick/server/www/controllers/AnythingFilter.java2
-rw-r--r--src/main/java/com/juick/server/www/controllers/Settings.java12
-rw-r--r--src/main/java/com/juick/service/UserService.java5
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java37
9 files changed, 58 insertions, 105 deletions
diff --git a/src/main/java/com/juick/User.java b/src/main/java/com/juick/User.java
index 7221e416..78d47139 100644
--- a/src/main/java/com/juick/User.java
+++ b/src/main/java/com/juick/User.java
@@ -53,6 +53,9 @@ public class User {
private URI uri;
private Instant seen;
private boolean verified;
+ private String country;
+ private String url;
+ private String description;
public User() {
tokens = new ArrayList<>();
@@ -232,4 +235,28 @@ public class User {
public void setVerified(boolean verified) {
this.verified = verified;
}
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
}
diff --git a/src/main/java/com/juick/model/UserInfo.java b/src/main/java/com/juick/model/UserInfo.java
deleted file mode 100644
index ca5d75e0..00000000
--- a/src/main/java/com/juick/model/UserInfo.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.model;
-
-/**
- * Created by vt on 03/09/16.
- */
-public class UserInfo {
- private String fullName;
- private String country;
- private String url;
- private String description;
-
- public String getFullName() {
- return fullName;
- }
-
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-}
diff --git a/src/main/java/com/juick/server/XMPPConnection.java b/src/main/java/com/juick/server/XMPPConnection.java
index f77b2354..dfbe92d5 100644
--- a/src/main/java/com/juick/server/XMPPConnection.java
+++ b/src/main/java/com/juick/server/XMPPConnection.java
@@ -22,7 +22,6 @@ import com.juick.formatters.PlainTextFormatter;
import com.juick.server.www.WebApp;
import com.juick.service.component.*;
import com.juick.model.CommandResult;
-import com.juick.model.UserInfo;
import com.juick.server.xmpp.iq.MessageQuery;
import com.juick.server.xmpp.s2s.BasicXmppSession;
import com.juick.server.xmpp.s2s.StanzaListener;
@@ -35,7 +34,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ApplicationEventPublisher;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
import rocks.xmpp.core.session.XmppSession;
@@ -164,7 +162,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
}
User user = userService.getUserByName(iq.getTo().getLocal());
if (!user.isAnonymous()) {
- UserInfo info = userService.getUserInfo(user);
+ User info = userService.getUserInfo(user);
VCard userVCard = new VCard();
userVCard.setFormattedName(info.getFullName());
userVCard.setNickname(user.getName());
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index 0e0fee85..5c6efe0c 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -19,7 +19,6 @@ package com.juick.server.api;
import com.juick.User;
import com.juick.model.ApplicationStatus;
-import com.juick.model.UserInfo;
import com.juick.server.util.*;
import com.juick.server.www.WebApp;
import com.juick.service.*;
@@ -96,7 +95,7 @@ public class Users {
me.setRead(userService.getUserFriends(visitor.getUid()));
me.setReaders(userService.getUserReaders(visitor.getUid()));
me.setAvatar(webApp.getAvatarUrl(visitor));
- return me;
+ return (SecureUser)userService.getUserInfo(me);
}
@PostMapping("/api/me/upload")
public void updateInfo(@RequestParam MultipartFile avatar) throws IOException {
@@ -111,9 +110,6 @@ public class Users {
public List<User> doGetUserRead(
@RequestParam String uname) {
User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
int uid = 0;
if (uname == null) {
uid = visitor.getUid();
@@ -138,9 +134,6 @@ public class Users {
public List<User> doGetUserReaders(
@RequestParam String uname) {
User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
int uid = 0;
if (uname == null) {
uid = visitor.getUid();
@@ -162,7 +155,7 @@ public class Users {
}
@GetMapping("/api/info/{uname}")
- public UserInfo getUserInfo(@PathVariable String uname) {
+ public User getUserInfo(@PathVariable String uname) {
User user = userService.getUserByName(uname);
if (!user.isBanned()) {
user.setRead(doGetUserRead(uname));
@@ -177,9 +170,6 @@ public class Users {
public String getHash() {
return getAuthHash();
}
- public UserInfo getUserInfo() {
- return userService.getUserInfo(this);
- }
public List<String> getJIDs() {
return userService.getAllJIDs(this);
}
diff --git a/src/main/java/com/juick/server/configuration/SecurityConfig.java b/src/main/java/com/juick/server/configuration/SecurityConfig.java
index f53cc531..16b61172 100644
--- a/src/main/java/com/juick/server/configuration/SecurityConfig.java
+++ b/src/main/java/com/juick/server/configuration/SecurityConfig.java
@@ -98,7 +98,7 @@ public class SecurityConfig {
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers("/api/", "/api/messages", "/api/messages/discussions", "/api/users", "/api/thread", "/api/tags", "/api/tlgmbtwbhk", "/api/fbwbhk",
- "/api/skypebotendpoint", "/api/_fblogin", "/api/_vklogin", "/api/_tglogin", "/api/_google", "/api/signup", "/api/inbox", "/api/u/**", "/.well-known/webfinger", "/.well-known/x-nodeinfo2", "/rss/**", "/api/events").permitAll()
+ "/api/skypebotendpoint", "/api/_fblogin", "/api/_vklogin", "/api/_tglogin", "/api/_google", "/api/signup", "/api/inbox", "/api/u/**", "/.well-known/webfinger", "/.well-known/x-nodeinfo2", "/rss/**", "/api/events", "/api/info/**").permitAll()
.anyRequest().hasRole("USER")
.and()
.anonymous().principal(JuickUser.ANONYMOUS_USER).authorities(JuickUser.ANONYMOUS_AUTHORITY)
diff --git a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java b/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
index cdbeafc0..57b298eb 100644
--- a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
+++ b/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
@@ -60,7 +60,7 @@ public class AnythingFilter extends OncePerRequestFilter {
} else {
com.juick.User user = userService.getUserByName(anything);
if (!user.isAnonymous()) {
- ((HttpServletResponse) servletResponse).sendRedirect("/" + user.getName() + "/?before=" + before);
+ servletResponse.sendRedirect("/" + user.getName() + "/?before=" + before);
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/server/www/controllers/Settings.java
index fc84b410..d5a21d09 100644
--- a/src/main/java/com/juick/server/www/controllers/Settings.java
+++ b/src/main/java/com/juick/server/www/controllers/Settings.java
@@ -18,7 +18,6 @@ package com.juick.server.www.controllers;
import com.juick.User;
import com.juick.model.NotifyOpts;
-import com.juick.model.UserInfo;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpUtils;
import com.juick.server.util.UserUtils;
@@ -156,16 +155,15 @@ public class Settings {
}
break;
case "about":
- UserInfo info = new UserInfo();
- info.setFullName(request.getParameter("fullname"));
- info.setCountry(request.getParameter("country"));
- info.setUrl(request.getParameter("url"));
- info.setDescription(request.getParameter("descr"));
+ visitor.setFullName(request.getParameter("fullname"));
+ visitor.setCountry(request.getParameter("country"));
+ visitor.setUrl(request.getParameter("url"));
+ visitor.setDescription(request.getParameter("descr"));
String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir).getHost();
if (StringUtils.isNotEmpty(avatarTmpPath)) {
imagesService.saveAvatar(avatarTmpPath, visitor.getUid());
}
- if (userService.updateUserInfo(visitor, info)) {
+ if (userService.updateUserInfo(visitor)) {
result = String.format("<p>Your info is updated.</p><p><a href='/%s/'>Back to blog</a>.</p>", visitor.getName());
}
break;
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 832f978a..3a51dffb 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -20,7 +20,6 @@ package com.juick.service;
import com.juick.Message;
import com.juick.User;
import com.juick.model.Auth;
-import com.juick.model.UserInfo;
import javax.annotation.Nonnull;
import java.time.Instant;
@@ -75,9 +74,9 @@ public interface UserService {
int setUserOptionInt(int uid, String option, int value);
- UserInfo getUserInfo(User user);
+ User getUserInfo(User user);
- boolean updateUserInfo(User user, UserInfo info);
+ boolean updateUserInfo(User info);
boolean getCanMedia(int uid);
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index 93904139..95a13f65 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -21,7 +21,6 @@ import com.juick.Message;
import com.juick.User;
import com.juick.model.AnonymousUser;
import com.juick.model.Auth;
-import com.juick.model.UserInfo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -375,29 +374,31 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional(readOnly = true)
@Override
- public UserInfo getUserInfo(final User user) {
- List<UserInfo> list = getJdbcTemplate().query(
- "SELECT fullname, country, url, descr FROM usersinfo WHERE user_id = ?",
- ((rs, rowNum) -> {
- UserInfo info = new UserInfo();
- info.setFullName(rs.getString(1));
- info.setCountry(rs.getString(2));
- info.setUrl(rs.getString(3));
- info.setDescription(rs.getString(4));
- return info;
- }),
- user.getUid());
-
- return list.isEmpty() ? new UserInfo() : list.get(0);
+ public User getUserInfo(final User user) {
+ try {
+ getJdbcTemplate().queryForObject(
+ "SELECT fullname, country, url, descr FROM usersinfo WHERE user_id = ?",
+ ((rs, rowNum) -> {
+ user.setFullName(rs.getString(1));
+ user.setCountry(rs.getString(2));
+ user.setUrl(rs.getString(3));
+ user.setDescription(rs.getString(4));
+ return user;
+ }),
+ user.getUid());
+ } catch (EmptyResultDataAccessException e) {
+ return user;
+ }
+ return user;
}
@Transactional
@Override
- public boolean updateUserInfo(final User user, final UserInfo info) {
+ public boolean updateUserInfo(final User info) {
try {
return getJdbcTemplate().update(
"INSERT INTO usersinfo(user_id, fullname, country, url, descr) VALUES (?, ?, ?, ?, ?)",
- user.getUid(),
+ info.getUid(),
info.getFullName(),
info.getCountry(),
info.getUrl(),
@@ -408,7 +409,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
info.getCountry(),
info.getUrl(),
info.getDescription(),
- user.getUid()) > 0;
+ info.getUid()) > 0;
}
}