Commit b0a2102c by Jan Hrabal

wip

parent f11ab61f
......@@ -27,8 +27,8 @@ hs_err_pid*
.settings
target
node_modules
/bin/
/tmp/
/bin/
/tmp/
/src/main/resources/resources/app.css
/src/main/resources/resources/app.js
......@@ -38,3 +38,4 @@ boot-react-common/.project
boot-react-common/.apt_generated
boot-react-common/.settings
boot-react-common/target
/.idea/
......@@ -212,8 +212,8 @@ CREATE TABLE ATTACHMENT (
CREATE INDEX ATTACHMENT_IDX ON ATTACHMENT(UNIT_ID, OBJECT_TYPE, OBJECT_ID);
-- SIMPLE TEMPLATES
CREATE TABLE SIMPLE_TEMPLATE (
-- TEMPLATES
CREATE TABLE TEMPLATE (
ID INT8 NOT NULL,
CODE VARCHAR(250),
NAME VARCHAR(100),
......@@ -226,7 +226,7 @@ CREATE TABLE SIMPLE_TEMPLATE (
CONSTRAINT PK_SIMPLE_TEMPLATE PRIMARY KEY(ID)
);
CREATE INDEX SIMPLE_TEMPLATE_CODE_IDX ON SIMPLE_TEMPLATE(CODE);
CREATE INDEX SIMPLE_TEMPLATE_CODE_LOCALE_IDX ON SIMPLE_TEMPLATE(CODE, LOCALE);
CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE);
CREATE INDEX TEMPLATE_CODE_LOCALE_IDX ON TEMPLATE(CODE, LOCALE);
-- TODO
\ No newline at end of file
package com.jh.boot;
import com.jh.boot.template.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import com.jh.boot.email.LocalEmailService;
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;
public class JhBootApplication {
......@@ -45,6 +41,11 @@ public class JhBootApplication {
public TemplateService templateService() {
return new HibernateLoaderTemplateService();
}
@Bean
public TemplateValuesConfig templateValuesConfig() {
return new TemplateValuesConfig();
}
}
......@@ -5,7 +5,7 @@ import com.jh.boot.security.model.ResetPasswordToken;
public interface AuthServiceListener {
default void registerUser(AppUser user) {
default void registerUser(AppUser user, String password) {
}
......
......@@ -83,7 +83,7 @@ public class AppUserAuthService implements AuthService {
AppUser appUser = appUserRepository.registerUser(login, password);
if (authListeners != null) {
authListeners.forEach(al -> al.registerUser(appUser));
authListeners.forEach(al -> al.registerUser(appUser, password));
}
}
......
package com.jh.boot.security.utils;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
......@@ -29,10 +30,10 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Value("${template.email.signup.subject:email.signup.subject}")
private String signupSubjectCode;
@Value("${template.email.signup.text:template.email.signup.text}")
@Value("${template.email.signup.text:email.signup.text}")
private String signupTemplateCode;
@Value("${template.email.signup.html:template.email.signup.html}")
@Value("${template.email.signup.html:email.signup.html}")
private String signupTemplateHtmlCode;
@Value("${template.email.password.subject:email.password.subject}")
......@@ -43,19 +44,25 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Value("${template.email.password.html:email.password.html}")
private String passwordTemplateHtmlCode;
@Value("${hostname.base:http://localhost:3000}")
private String hostnameBase;
@Override
public void registerUser(AppUser user) {
sendEmail(signupSubjectCode, signupTemplateCode, signupTemplateHtmlCode, user, Collections.singletonMap("user", user));
public void registerUser(AppUser user, String password) {
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
public void generateResetToken(AppUser user, ResetPasswordToken token) {
Map<String, Object> data = new HashMap<>();
data.put("user", user);
data.put("token", token.getToken());
data.put("resetPasswordUrl", relativePath("/resetPassword") + "?token=" + token.getToken());
sendEmail(passwordSubjectCode, passwordTemplateCode, passwordTemplateHtmlCode, user, data);
}
......@@ -82,4 +89,14 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
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 {
engine.evaluate(sw, content, values);
content = sw.toString();
if (t.getLayout() != null) {
t = loader.loadTemplate(t.getLayout(), locale);
if (t.getLayoutCode() != null) {
t = loader.loadTemplate(t.getLayoutCode(), locale);
if (t != null) {
values.put("__layout_content__", content);
}
......
......@@ -13,8 +13,8 @@ public class Template extends AbstractIdEntity {
@Column(name = "CODE")
private String code;
@Column(name = "LAYOUT")
private String layout;
@Column(name = "LAYOUT_CODE")
private String layoutCode;
@Column(name = "TEMPLATE")
private String template;
......@@ -39,12 +39,12 @@ public class Template extends AbstractIdEntity {
this.code = code;
}
public String getLayout() {
return layout;
public String getLayoutCode() {
return layoutCode;
}
public void setLayout(String name) {
this.layout = name;
public void setLayoutCode(String name) {
this.layoutCode = name;
}
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