Commit b0a2102c by Jan Hrabal

wip

parent f11ab61f
...@@ -38,3 +38,4 @@ boot-react-common/.project ...@@ -38,3 +38,4 @@ boot-react-common/.project
boot-react-common/.apt_generated boot-react-common/.apt_generated
boot-react-common/.settings boot-react-common/.settings
boot-react-common/target boot-react-common/target
/.idea/
...@@ -212,8 +212,8 @@ CREATE TABLE ATTACHMENT ( ...@@ -212,8 +212,8 @@ CREATE TABLE ATTACHMENT (
CREATE INDEX ATTACHMENT_IDX ON ATTACHMENT(UNIT_ID, OBJECT_TYPE, OBJECT_ID); CREATE INDEX ATTACHMENT_IDX ON ATTACHMENT(UNIT_ID, OBJECT_TYPE, OBJECT_ID);
-- SIMPLE TEMPLATES -- TEMPLATES
CREATE TABLE SIMPLE_TEMPLATE ( CREATE TABLE TEMPLATE (
ID INT8 NOT NULL, ID INT8 NOT NULL,
CODE VARCHAR(250), CODE VARCHAR(250),
NAME VARCHAR(100), NAME VARCHAR(100),
...@@ -226,7 +226,7 @@ CREATE TABLE SIMPLE_TEMPLATE ( ...@@ -226,7 +226,7 @@ CREATE TABLE SIMPLE_TEMPLATE (
CONSTRAINT PK_SIMPLE_TEMPLATE PRIMARY KEY(ID) CONSTRAINT PK_SIMPLE_TEMPLATE PRIMARY KEY(ID)
); );
CREATE INDEX SIMPLE_TEMPLATE_CODE_IDX ON SIMPLE_TEMPLATE(CODE); CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE);
CREATE INDEX SIMPLE_TEMPLATE_CODE_LOCALE_IDX ON SIMPLE_TEMPLATE(CODE, LOCALE); CREATE INDEX TEMPLATE_CODE_LOCALE_IDX ON TEMPLATE(CODE, LOCALE);
-- TODO -- TODO
\ No newline at end of file
package com.jh.boot; package com.jh.boot;
import com.jh.boot.template.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.jh.boot.email.LocalEmailService; import com.jh.boot.email.LocalEmailService;
import com.jh.boot.security.utils.TemplateEmailAuthServiceListener; import com.jh.boot.security.utils.TemplateEmailAuthServiceListener;
import com.jh.boot.template.HibernateTemplateLoader;
import com.jh.boot.template.HibernateLoaderTemplateService;
import com.jh.boot.template.TemplateEngine;
import com.jh.boot.template.TemplateLoader;
import com.jh.boot.template.TemplateService;
import com.jh.boot.template.handlebars.HandlebarsTemplateEngine; import com.jh.boot.template.handlebars.HandlebarsTemplateEngine;
public class JhBootApplication { public class JhBootApplication {
...@@ -46,5 +42,10 @@ public class JhBootApplication { ...@@ -46,5 +42,10 @@ public class JhBootApplication {
return new HibernateLoaderTemplateService(); return new HibernateLoaderTemplateService();
} }
@Bean
public TemplateValuesConfig templateValuesConfig() {
return new TemplateValuesConfig();
}
} }
...@@ -5,7 +5,7 @@ import com.jh.boot.security.model.ResetPasswordToken; ...@@ -5,7 +5,7 @@ import com.jh.boot.security.model.ResetPasswordToken;
public interface AuthServiceListener { public interface AuthServiceListener {
default void registerUser(AppUser user) { default void registerUser(AppUser user, String password) {
} }
......
...@@ -83,7 +83,7 @@ public class AppUserAuthService implements AuthService { ...@@ -83,7 +83,7 @@ public class AppUserAuthService implements AuthService {
AppUser appUser = appUserRepository.registerUser(login, password); AppUser appUser = appUserRepository.registerUser(login, password);
if (authListeners != null) { if (authListeners != null) {
authListeners.forEach(al -> al.registerUser(appUser)); authListeners.forEach(al -> al.registerUser(appUser, password));
} }
} }
......
package com.jh.boot.security.utils; package com.jh.boot.security.utils;
import java.net.URISyntaxException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
...@@ -29,10 +30,10 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener { ...@@ -29,10 +30,10 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Value("${template.email.signup.subject:email.signup.subject}") @Value("${template.email.signup.subject:email.signup.subject}")
private String signupSubjectCode; private String signupSubjectCode;
@Value("${template.email.signup.text:template.email.signup.text}") @Value("${template.email.signup.text:email.signup.text}")
private String signupTemplateCode; private String signupTemplateCode;
@Value("${template.email.signup.html:template.email.signup.html}") @Value("${template.email.signup.html:email.signup.html}")
private String signupTemplateHtmlCode; private String signupTemplateHtmlCode;
@Value("${template.email.password.subject:email.password.subject}") @Value("${template.email.password.subject:email.password.subject}")
...@@ -44,18 +45,24 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener { ...@@ -44,18 +45,24 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Value("${template.email.password.html:email.password.html}") @Value("${template.email.password.html:email.password.html}")
private String passwordTemplateHtmlCode; private String passwordTemplateHtmlCode;
@Value("${hostname.base:http://localhost:3000}")
private String hostnameBase;
@Override @Override
public void registerUser(AppUser user) { public void registerUser(AppUser user, String password) {
sendEmail(signupSubjectCode, signupTemplateCode, signupTemplateHtmlCode, user, Collections.singletonMap("user", user)); Map<String, Object> data = new HashMap<>();
data.put("login", user.getEmail());
data.put("password", password);
data.put("loginPath", relativePath("/login"));
sendEmail(signupSubjectCode, signupTemplateCode, signupTemplateHtmlCode, user, data);
} }
@Override @Override
public void generateResetToken(AppUser user, ResetPasswordToken token) { public void generateResetToken(AppUser user, ResetPasswordToken token) {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("user", user); data.put("resetPasswordUrl", relativePath("/resetPassword") + "?token=" + token.getToken());
data.put("token", token.getToken());
sendEmail(passwordSubjectCode, passwordTemplateCode, passwordTemplateHtmlCode, user, data); sendEmail(passwordSubjectCode, passwordTemplateCode, passwordTemplateHtmlCode, user, data);
} }
...@@ -82,4 +89,14 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener { ...@@ -82,4 +89,14 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
emailService.sendEmail(email); emailService.sendEmail(email);
} }
protected String relativePath(String path) {
java.net.URI uri = null;
try {
uri = new java.net.URI (hostnameBase);
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot resolve URI", e);
}
return uri.resolve(path).toString();
}
} }
...@@ -40,8 +40,8 @@ public class HibernateLoaderTemplateService implements TemplateService { ...@@ -40,8 +40,8 @@ public class HibernateLoaderTemplateService implements TemplateService {
engine.evaluate(sw, content, values); engine.evaluate(sw, content, values);
content = sw.toString(); content = sw.toString();
if (t.getLayout() != null) { if (t.getLayoutCode() != null) {
t = loader.loadTemplate(t.getLayout(), locale); t = loader.loadTemplate(t.getLayoutCode(), locale);
if (t != null) { if (t != null) {
values.put("__layout_content__", content); values.put("__layout_content__", content);
} }
......
...@@ -13,8 +13,8 @@ public class Template extends AbstractIdEntity { ...@@ -13,8 +13,8 @@ public class Template extends AbstractIdEntity {
@Column(name = "CODE") @Column(name = "CODE")
private String code; private String code;
@Column(name = "LAYOUT") @Column(name = "LAYOUT_CODE")
private String layout; private String layoutCode;
@Column(name = "TEMPLATE") @Column(name = "TEMPLATE")
private String template; private String template;
...@@ -39,12 +39,12 @@ public class Template extends AbstractIdEntity { ...@@ -39,12 +39,12 @@ public class Template extends AbstractIdEntity {
this.code = code; this.code = code;
} }
public String getLayout() { public String getLayoutCode() {
return layout; return layoutCode;
} }
public void setLayout(String name) { public void setLayoutCode(String name) {
this.layout = name; this.layoutCode = name;
} }
public String getTemplate() { public String getTemplate() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment