Skip to content

Commit

Permalink
Implemented sending of mail with activation key.
Browse files Browse the repository at this point in the history
Also added support for feature flags. You can enable/disable them in runtime by opening /togglz URL
under admin account.

Fixed #64 (GH #1)
  • Loading branch information
php-coder committed Aug 16, 2014
1 parent 255369a commit 681913b
Show file tree
Hide file tree
Showing 25 changed files with 616 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ target/
.idea
mystamps.iml

src/main/resources/prod/spring/mail.properties
2 changes: 2 additions & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
0.3 (not released yet)
- implemented sending of mail with activation key
- started using feature flags with Togglz
- added localization support for countries
- added categories to series
- save images to the disk
Expand Down
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
<lombok.version>1.12.6</lombok.version>
<mysql.connector.version>5.1.30</mysql.connector.version>
<selenium.version>2.41.0</selenium.version>
<subethasmtp.version>3.1.7</subethasmtp.version>
<slf4j.version>1.7.7</slf4j.version>
<spring.version>3.2.5.RELEASE</spring.version>
<spring.data.version>1.5.1.RELEASE</spring.data.version>
<spring.security.version>3.1.6.RELEASE</spring.security.version>
<h2.version>1.4.178</h2.version>
<javax.validation.version>1.1.0.Alpha1</javax.validation.version>
<javax.inject.version>1</javax.inject.version>
<javax.mail.version>1.5.2</javax.mail.version>
<javax.persistence.version>1.0.1.Final</javax.persistence.version>
<servlet.api.version>3.0.20100224</servlet.api.version>
<jstl.version>1.2</jstl.version>
Expand All @@ -33,6 +35,7 @@
<tiles.version>2.2.2</tiles.version>
<liquibase.version>3.2.0</liquibase.version>
<liquibase.slf4j.version>1.2.1</liquibase.slf4j.version>
<togglz.version>2.0.1.Final</togglz.version>

<!-- Also don't forget to change version in src/main/java/ru/mystamps/web/config/MvcConfig.java -->
<bootstrap.version>2.3.1</bootstrap.version>
Expand Down Expand Up @@ -97,6 +100,13 @@
<version>${javax.inject.version}</version>
</dependency>

<!-- For MimeMessage class -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>${javax.mail.version}</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down Expand Up @@ -134,6 +144,13 @@
<version>${spring.version}</version>
</dependency>

<!-- For mail classes -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
Expand Down Expand Up @@ -266,6 +283,39 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
<version>${togglz.version}</version>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring</artifactId>
<version>${togglz.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-security</artifactId>
<version>${togglz.version}</version>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-slf4j</artifactId>
<version>${togglz.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-console</artifactId>
<version>${togglz.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
Expand Down Expand Up @@ -323,6 +373,27 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-testing</artifactId>
<version>${togglz.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp</artifactId>
<version>${subethasmtp.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>${javax.mail.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
Expand Down Expand Up @@ -468,6 +539,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${war.plugin.version}</version>
<configuration>
<packagingExcludes>WEB-INF/classes/prod/spring/mail.properties.example</packagingExcludes>
</configuration>
</plugin>

<plugin>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ru/mystamps/web/Url.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Slava Semushin <slava.semushin@gmail.com>
*/
public final class Url {
public static final String PUBLIC_URL = "http://my-stamps.ru";

// defined at pom.xml (and used by functional tests only)
public static final String SITE = "http://127.0.0.1:8081";
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/ru/mystamps/web/config/ApplicationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package ru.mystamps.web.config;

import javax.inject.Inject;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -25,26 +27,42 @@

import ru.mystamps.web.support.spring.security.SecurityConfig;

import org.togglz.core.manager.TogglzConfig;

import ru.mystamps.web.support.togglz.FeatureConfig;

@Configuration
@Import({
DbConfig.class,
LiquibaseConfig.class,
MailConfig.class,
SecurityConfig.class,
ServicesConfig.class,
StrategiesConfig.class
})
public class ApplicationContext {

@Inject
private DataSourceConfig dataSourceConfig;

@Bean(name = "messageSource")
public MessageSource getMessageSource() {
ReloadableResourceBundleMessageSource messageSource =
new ReloadableResourceBundleMessageSource();

messageSource.setBasename("classpath:ru/mystamps/i18n/SpringSecurityMessages");
messageSource.setBasenames(
"classpath:ru/mystamps/i18n/SpringSecurityMessages",
"classpath:ru/mystamps/i18n/MailTemplates"
);
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(false);

return messageSource;
}

@Bean
public TogglzConfig getTogglzConfig() {
return new FeatureConfig(dataSourceConfig.getDataSource());
}

}
47 changes: 47 additions & 0 deletions src/main/java/ru/mystamps/web/config/MailConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2009-2014 Slava Semushin <slava.semushin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package ru.mystamps.web.config;

import javax.inject.Inject;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
@PropertySource("classpath:${spring.profiles.active}/spring/mail.properties")
public class MailConfig {

@Inject
private Environment env;

@Bean
public JavaMailSender getMailSender() {
JavaMailSenderImpl mailer = new JavaMailSenderImpl();
mailer.setHost(env.getRequiredProperty("mail.smtp.host"));
mailer.setPort(env.getRequiredProperty("mail.smtp.port", Integer.class));
mailer.setUsername(env.getRequiredProperty("mail.smtp.login"));
mailer.setPassword(env.getRequiredProperty("mail.smtp.password"));

return mailer;
}

}
24 changes: 24 additions & 0 deletions src/main/java/ru/mystamps/web/config/ServicesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import javax.inject.Inject;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import ru.mystamps.web.dao.*; // NOCHECKSTYLE: AvoidStarImportCheck, NOPMD: UnusedImports
import ru.mystamps.web.service.*; // NOCHECKSTYLE: AvoidStarImportCheck, NOPMD: UnusedImports
Expand Down Expand Up @@ -59,6 +61,15 @@ public class ServicesConfig {
@Inject
private ImageDao imageDao;

@Inject
private MailConfig mailConfig;

@Inject
private Environment env;

@Inject
private MessageSource messageSource;

@Bean
public CountryService getCountryService() {
return new CountryServiceImpl(countryDao);
Expand All @@ -79,6 +90,18 @@ public ImageService getImageService() {
return new ImageServiceImpl(strategiesConfig.getImagePersistenceStrategy(), imageDao);
}

@Bean
public MailService getMailService() {
boolean isProductionEnvironment = env.acceptsProfiles("prod");
boolean enableTestMode = !isProductionEnvironment;

return new MailServiceImpl(
mailConfig.getMailSender(),
messageSource,
env.getRequiredProperty("mail.robot.email"),
enableTestMode);
}

@Bean
public SeriesService getSeriesService() {
return new SeriesServiceImpl(seriesDao, getImageService());
Expand All @@ -94,6 +117,7 @@ public UserService getUserService() {
return new UserServiceImpl(
userDao,
usersActivationDao,
getMailService(),
securityConfig.getPasswordEncoder()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package ru.mystamps.web.controller;

import java.util.Locale;

import javax.validation.Valid;

import org.springframework.beans.propertyeditors.StringTrimmerEditor;
Expand Down Expand Up @@ -69,13 +71,14 @@ public RegisterAccountForm showRegistrationForm() {
public String processRegistrationForm(
@Valid RegisterAccountForm form,
BindingResult result,
RedirectAttributes redirectAttributes) {
RedirectAttributes redirectAttributes,
Locale userLocale) {

if (result.hasErrors()) {
return null;
}

userService.addRegistrationRequest(form);
userService.addRegistrationRequest(form, userLocale);

redirectAttributes.addFlashAttribute("justRegisteredUser", true);

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ru/mystamps/web/entity/UsersActivation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package ru.mystamps.web.entity;

import java.util.Date;
import java.util.Locale;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -35,6 +36,7 @@ public class UsersActivation {

public static final int ACTIVATION_KEY_LENGTH = 10;
public static final int EMAIL_LENGTH = 255;
public static final int LANG_LENGTH = 2;

@Id
@Column(name = "act_key", length = ACTIVATION_KEY_LENGTH)
Expand All @@ -43,7 +45,14 @@ public class UsersActivation {
@Column(length = EMAIL_LENGTH, nullable = false)
private String email;

@Column(length = LANG_LENGTH, nullable = false)
private String lang;

@Column(name = "created_at", nullable = false)
private Date createdAt;

public Locale getLocale() {
return new Locale(lang);
}

}
24 changes: 24 additions & 0 deletions src/main/java/ru/mystamps/web/service/MailService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2009-2014 Slava Semushin <slava.semushin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package ru.mystamps.web.service;

import ru.mystamps.web.entity.UsersActivation;

public interface MailService {
void sendActivationKeyToUser(UsersActivation activation);
}
Loading

0 comments on commit 681913b

Please sign in to comment.