From 0b9c0c402ccf06e52b3eaebc8859f0dc9357bc49 Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <daniel.gerhardt@mni.thm.de>
Date: Mon, 12 May 2014 00:06:19 +0200
Subject: [PATCH] Make account activation page configurable

Added support for an activation webpage and renamed dialog config param
for consistency.
---
 .../arsnova/controller/LoginController.java   | 20 +++++++++--
 .../de/thm/arsnova/services/UserService.java  | 34 +++++++++++++++----
 src/main/webapp/arsnova.properties.example    |  6 ++--
 src/test/resources/arsnova.properties.example |  6 ++--
 4 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java
index 6c1699af3..080c69a5c 100644
--- a/src/main/java/de/thm/arsnova/controller/LoginController.java
+++ b/src/main/java/de/thm/arsnova/controller/LoginController.java
@@ -74,36 +74,52 @@ public class LoginController extends AbstractController {
 
 	@Value("${customization.path}")
 	private String customizationPath;
+
 	@Value("${security.guest.enabled}")
 	private String guestEnabled;
+
 	@Value("${security.guest.lecturer.enabled}")
 	private String guestLecturerEnabled;
+
 	@Value("${security.user-db.enabled}")
 	private String dbAuthEnabled;
+
 	@Value("${security.user-db.title:ARSnova}")
 	private String dbAuthTitle;
-	@Value("${security.user-db.login-dialog}")
+
+	@Value("${security.user-db.login-dialog-path}")
 	private String dbAuthDialog;
+
 	@Value("${security.user-db.image:}")
 	private String dbAuthImage;
+
 	@Value("${security.ldap.enabled}")
 	private String ldapEnabled;
+
 	@Value("${security.ldap.title:LDAP}")
 	private String ldapTitle;
-	@Value("${security.ldap.login-dialog}")
+
+	@Value("${security.ldap.login-dialog-path}")
 	private String ldapDialog;
+
 	@Value("${security.ldap.image:}")
 	private String ldapImage;
+
 	@Value("${security.cas.enabled}")
 	private String casEnabled;
+
 	@Value("${security.cas.title:CAS}")
 	private String casTitle;
+
 	@Value("${security.cas.image:}")
 	private String casImage;
+
 	@Value("${security.facebook.enabled}")
 	private String facebookEnabled;
+
 	@Value("${security.google.enabled}")
 	private String googleEnabled;
+
 	@Value("${security.twitter.enabled}")
 	private String twitterEnabled;
 
diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java
index f441801af..ea8d922bc 100644
--- a/src/main/java/de/thm/arsnova/services/UserService.java
+++ b/src/main/java/de/thm/arsnova/services/UserService.java
@@ -1,5 +1,6 @@
 package de.thm.arsnova.services;
 
+import java.io.UnsupportedEncodingException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -42,6 +43,7 @@ import org.springframework.security.crypto.keygen.KeyGenerators;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.util.UriUtils;
 
 import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationToken;
 
@@ -82,21 +84,27 @@ public class UserService implements IUserService {
 	@Autowired
 	private JavaMailSender mailSender;
 
+	@Value("${root-url}")
+	private String rootUrl;
+
+	@Value("${customization.path}")
+	private String customizationPath;
+
 	@Value("${security.user-db.allowed-email-domains}")
 	private String allowedEmailDomains;
 
-	@Value("${security.arsnova-url}")
-	private String arsnovaUrl;
+	@Value("${security.user-db.activation-path}")
+	private String activationPath;
 
 	@Value("${mail.sender.address}")
 	private String regMailSenderAddress;
-	
+
 	@Value("${mail.sender.name}")
 	private String regMailSenderName;
-	
+
 	@Value("${security.user-db.registration-mail.subject}")
 	private String regMailSubject;
-	
+
 	@Value("${security.user-db.registration-mail.body}")
 	private String regMailBody;
 
@@ -381,7 +389,21 @@ public class UserService implements IUserService {
 	}
 
 	public void sendActivationEmail(DbUser dbUser) {
-		String activationUrl = MessageFormat.format("{0}/user/{1}/activate?key={2}", arsnovaUrl, dbUser.getUsername(), dbUser.getActivationKey());
+		String activationUrl;
+		try {
+			activationUrl = MessageFormat.format(
+				"{0}{1}/{2}?username={3}&key={4}",
+				rootUrl,
+				customizationPath,
+				activationPath,
+				UriUtils.encodeQueryParam(dbUser.getUsername(), "UTF-8"),
+				dbUser.getActivationKey()
+			);
+		} catch (UnsupportedEncodingException e1) {
+			LOGGER.error(e1.getMessage());
+
+			return;
+		}
 		MimeMessage msg = mailSender.createMimeMessage();
 		MimeMessageHelper helper = new MimeMessageHelper(msg, "UTF-8");
 		try {
diff --git a/src/main/webapp/arsnova.properties.example b/src/main/webapp/arsnova.properties.example
index cbbb75105..76a0efbc0 100644
--- a/src/main/webapp/arsnova.properties.example
+++ b/src/main/webapp/arsnova.properties.example
@@ -1,3 +1,4 @@
+root-url=http://localhost:8080
 customization.path=/customization
 mobile.path=/mobile
 presenter.path=/presenter
@@ -15,7 +16,8 @@ security.guest.lecturer.enabled=true
 
 security.user-db.enabled=true
 security.user-db.title=ARSnova
-security.user-db.login-dialog=login-arsnova.html
+security.user-db.login-dialog-path=account.html
+security.user-db.activation-path=account.html
 security.user-db.image=
 security.user-db.allowed-email-domains=*
 security.user-db.registration-mail.subject=ARSnova Registration
@@ -23,7 +25,7 @@ security.user-db.registration-mail.body=Welcome to ARSnova!\n\nPlease confirm yo
 
 security.ldap.enabled=true
 security.ldap.title=LDAP
-security.ldap.login-dialog=login-ldap.html
+security.ldap.login-dialog-path=login-ldap.html
 security.user-db.image=
 security.ldap.url=ldap://example.com:33389/dc=example,dc=com
 security.ldap.user-dn-pattern=uid={0},ou=arsnova
diff --git a/src/test/resources/arsnova.properties.example b/src/test/resources/arsnova.properties.example
index cbbb75105..76a0efbc0 100644
--- a/src/test/resources/arsnova.properties.example
+++ b/src/test/resources/arsnova.properties.example
@@ -1,3 +1,4 @@
+root-url=http://localhost:8080
 customization.path=/customization
 mobile.path=/mobile
 presenter.path=/presenter
@@ -15,7 +16,8 @@ security.guest.lecturer.enabled=true
 
 security.user-db.enabled=true
 security.user-db.title=ARSnova
-security.user-db.login-dialog=login-arsnova.html
+security.user-db.login-dialog-path=account.html
+security.user-db.activation-path=account.html
 security.user-db.image=
 security.user-db.allowed-email-domains=*
 security.user-db.registration-mail.subject=ARSnova Registration
@@ -23,7 +25,7 @@ security.user-db.registration-mail.body=Welcome to ARSnova!\n\nPlease confirm yo
 
 security.ldap.enabled=true
 security.ldap.title=LDAP
-security.ldap.login-dialog=login-ldap.html
+security.ldap.login-dialog-path=login-ldap.html
 security.user-db.image=
 security.ldap.url=ldap://example.com:33389/dc=example,dc=com
 security.ldap.user-dn-pattern=uid={0},ou=arsnova
-- 
GitLab