diff options
author | Vitaly Takmazov | 2018-03-14 10:04:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-14 10:04:40 +0300 |
commit | b2f3afebc7de684d1d49042f5f79a9cbf9c1f2f2 (patch) | |
tree | b7d5c7ca5b728751fa16d0085486b305da87d61d | |
parent | b1e8980ed1460340fe4e8db2ce0d7ee1d213854a (diff) |
refactor email settings
7 files changed, 12 insertions, 59 deletions
diff --git a/juick-server-core/src/main/java/com/juick/server/helpers/EmailOpts.java b/juick-server-core/src/main/java/com/juick/server/helpers/EmailOpts.java deleted file mode 100644 index b8af8f88..00000000 --- a/juick-server-core/src/main/java/com/juick/server/helpers/EmailOpts.java +++ /dev/null @@ -1,41 +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.server.helpers; - -import org.apache.commons.lang3.StringUtils; - -/** - * Created by vitalyster on 09.02.2016. - */ -public class EmailOpts { - private String email; - private String subscriptionHour; - - public EmailOpts(String email, int subscriptionHour) { - this.email = email; - this.subscriptionHour = StringUtils.leftPad(String.format("%d", subscriptionHour), 2, "0"); - } - - public String getSubscriptionHour() { - return subscriptionHour; - } - - public String getEmail() { - return email; - } -}
\ No newline at end of file diff --git a/juick-server-core/src/main/java/com/juick/service/EmailService.java b/juick-server-core/src/main/java/com/juick/service/EmailService.java index ac63f4da..2440bcb4 100644 --- a/juick-server-core/src/main/java/com/juick/service/EmailService.java +++ b/juick-server-core/src/main/java/com/juick/service/EmailService.java @@ -27,6 +27,7 @@ public interface EmailService { boolean addVerificationCode(Integer userId, String account, String code); boolean addEmail(Integer userId, String email); boolean deleteEmail(Integer userId, String account); + String getNotificationsEmail(Integer userId); boolean setNotificationsEmail(Integer userId, String account); List<String> getEmails(Integer userId, boolean active); } diff --git a/juick-server-core/src/main/java/com/juick/service/UserService.java b/juick-server-core/src/main/java/com/juick/service/UserService.java index 6ca6fb98..115c7dfc 100644 --- a/juick-server-core/src/main/java/com/juick/service/UserService.java +++ b/juick-server-core/src/main/java/com/juick/service/UserService.java @@ -19,7 +19,6 @@ package com.juick.service; import com.juick.User; import com.juick.server.helpers.Auth; -import com.juick.server.helpers.EmailOpts; import com.juick.server.helpers.UserInfo; import java.util.Collection; @@ -123,8 +122,6 @@ public interface UserService { List<String> getEmails(User user); - EmailOpts getEmailOpts(User user); - String getEmailHash(User user); int deleteLoginForUser(String name); diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java index 1921354a..0cccc915 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java @@ -68,6 +68,14 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService { .addValue("email", account)) > 0; } + @Transactional(readOnly = true) + @Override + public String getNotificationsEmail(Integer userId) { + List<String> list = getJdbcTemplate().queryForList( + "SELECT email FROM emails WHERE user_id=? AND subscr_hour IS NOT NULL", String.class, userId); + return list.isEmpty() ? StringUtils.EMPTY : list.get(0); + } + @Override public boolean setNotificationsEmail(Integer userId, String account) { getJdbcTemplate().update("UPDATE emails SET subscr_hour=NULL WHERE user_id=?", userId); diff --git a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java index 770819ec..3f7cebf6 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java @@ -20,13 +20,11 @@ package com.juick.service; import com.juick.User; import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.Auth; -import com.juick.server.helpers.EmailOpts; import com.juick.server.helpers.UserInfo; import com.juick.server.util.HashUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.dao.DuplicateKeyException; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; @@ -34,7 +32,6 @@ import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import javax.inject.Inject; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -629,15 +626,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public EmailOpts getEmailOpts(final User user) { - List<EmailOpts> list = getJdbcTemplate().query( - "SELECT email,subscr_hour FROM emails WHERE user_id=? AND subscr_hour IS NOT NULL", - (rs, num) -> new EmailOpts(rs.getString(1), rs.getInt(2)), user.getUid()); - return list.isEmpty() ? new EmailOpts("", 0) : list.get(0); - } - - @Transactional(readOnly = true) - @Override public String getEmailHash(final User user) { List<String> list = getJdbcTemplate().queryForList( "SELECT hash FROM mail WHERE user_id = ?", 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 a1d58ada..141c9e2c 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 @@ -94,7 +94,7 @@ public class Settings { model.addAttribute("visitor", visitor); model.addAttribute("tags", tagService.getPopularTags()); model.addAttribute("auths", userService.getAuthCodes(visitor)); - model.addAttribute("eopts", userService.getEmailOpts(visitor)); + model.addAttribute("email_active", emailService.getNotificationsEmail(visitor.getUid())); model.addAttribute("ehash", userService.getEmailHash(visitor)); model.addAttribute("emails", userService.getEmails(visitor)); model.addAttribute("jids", userService.getAllJIDs(visitor)); @@ -121,7 +121,7 @@ public class Settings { protected String doPost(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) MultipartFile avatar, ModelMap model) - throws IOException, ServletException { + throws IOException { com.juick.User visitor = UserUtils.getCurrentUser(); if (visitor.getUid() == 0) { throw new HttpBadRequestException(); diff --git a/juick-www/src/main/resources/templates/views/settings_main.html b/juick-www/src/main/resources/templates/views/settings_main.html index ef46542d..65fbc984 100644 --- a/juick-www/src/main/resources/templates/views/settings_main.html +++ b/juick-www/src/main/resources/templates/views/settings_main.html @@ -88,7 +88,7 @@ Sent to <select name="account"> <option value="">Disabled</option> {% for email in emails %} - <option value="{{ email }}" {% if eopts.email == email %} selected="selected" {% endif %}> + <option value="{{ email }}" {% if email_active == email %} selected="selected" {% endif %}> {{ email }} </option> {% endfor %} |