Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
b0a2102c
Commit
b0a2102c
authored
Oct 08, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
f11ab61f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
25 deletions
+45
-25
.gitignore
.gitignore
+1
-0
init.sql
sql/init.sql
+5
-4
JhBootApplication.java
src/main/java/com/jh/boot/JhBootApplication.java
+6
-5
AuthServiceListener.java
src/main/java/com/jh/boot/security/AuthServiceListener.java
+1
-1
AppUserAuthService.java
...java/com/jh/boot/security/service/AppUserAuthService.java
+1
-1
TemplateEmailAuthServiceListener.java
...boot/security/utils/TemplateEmailAuthServiceListener.java
+23
-6
HibernateLoaderTemplateService.java
.../com/jh/boot/template/HibernateLoaderTemplateService.java
+2
-2
Template.java
src/main/java/com/jh/boot/template/Template.java
+6
-6
No files found.
.gitignore
View file @
b0a2102c
...
@@ -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/
sql/init.sql
View file @
b0a2102c
...
@@ -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
src/main/java/com/jh/boot/JhBootApplication.java
View file @
b0a2102c
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
();
}
}
}
src/main/java/com/jh/boot/security/AuthServiceListener.java
View file @
b0a2102c
...
@@ -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
)
{
}
}
...
...
src/main/java/com/jh/boot/security/service/AppUserAuthService.java
View file @
b0a2102c
...
@@ -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
));
}
}
}
}
...
...
src/main/java/com/jh/boot/security/utils/TemplateEmailAuthServiceListener.java
View file @
b0a2102c
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
();
}
}
}
src/main/java/com/jh/boot/template/HibernateLoaderTemplateService.java
View file @
b0a2102c
...
@@ -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
.
getLayout
Code
()
!=
null
)
{
t
=
loader
.
loadTemplate
(
t
.
getLayout
(),
locale
);
t
=
loader
.
loadTemplate
(
t
.
getLayout
Code
(),
locale
);
if
(
t
!=
null
)
{
if
(
t
!=
null
)
{
values
.
put
(
"__layout_content__"
,
content
);
values
.
put
(
"__layout_content__"
,
content
);
}
}
...
...
src/main/java/com/jh/boot/template/Template.java
View file @
b0a2102c
...
@@ -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
layout
Code
;
@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
getLayout
Code
()
{
return
layout
;
return
layout
Code
;
}
}
public
void
setLayout
(
String
name
)
{
public
void
setLayout
Code
(
String
name
)
{
this
.
layout
=
name
;
this
.
layout
Code
=
name
;
}
}
public
String
getTemplate
()
{
public
String
getTemplate
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment