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
e4d42a34
You need to sign in or sign up before continuing.
Commit
e4d42a34
authored
Oct 08, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tmps
parent
202efda9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
19 deletions
+58
-19
data.sql
sql/data.sql
+7
-7
TemplateEmailAuthServiceListener.java
...boot/security/utils/TemplateEmailAuthServiceListener.java
+1
-8
HibernateLoaderTemplateService.java
.../com/jh/boot/template/HibernateLoaderTemplateService.java
+13
-2
HibernateTemplateLoader.java
...in/java/com/jh/boot/template/HibernateTemplateLoader.java
+10
-2
HibernateTemplateRepository.java
...ava/com/jh/boot/template/HibernateTemplateRepository.java
+27
-0
No files found.
sql/data.sql
View file @
e4d42a34
...
...
@@ -5,13 +5,13 @@ insert into APP_USER (ID, EMAIL, FIRST_NAME, LAST_NAME, PASSWORD, PASSWORD_SALT,
insert
into
APP_USER_ROLE
(
USER_ID
,
ROLE_ID
)
values
(
1
,
1
);
-- default templates
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
1
,
'email.layout'
,
'{{template_content}}'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
2
,
'email.signup.subject'
,
'Welcome to ...'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
3
,
'email.signup.text'
,
'Welcome to ...'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
4
,
'email.signup.html'
,
'Welcome to ...'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
5
,
'email.password.subject'
,
'Password subject'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
6
,
'email.password.text'
,
'Password text {{token}}'
);
insert
into
SIMPLE_
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
7
,
'email.password.html'
,
'Password HTML'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
1
,
'email.layout'
,
'{{template_content}}'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
2
,
'email.signup.subject'
,
'Welcome to ...'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
3
,
'email.signup.text'
,
'Welcome to ...'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
4
,
'email.signup.html'
,
'Welcome to ...'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
5
,
'email.password.subject'
,
'Password subject'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
6
,
'email.password.text'
,
'Password text {{token}}'
);
insert
into
TEMPLATE
(
ID
,
CODE
,
TEMPLATE
)
values
(
7
,
'email.password.html'
,
'Password HTML'
);
-- legal documents
insert
into
LEGAL_DOCUMENT
(
ID
,
CODE
,
LOCALE
,
CONTENT
)
values
(
1
,
'AUTH.TERMS'
,
'en'
,
'<p>By using the Inodio service you are
...
...
src/main/java/com/jh/boot/security/utils/TemplateEmailAuthServiceListener.java
View file @
e4d42a34
...
...
@@ -7,7 +7,6 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.StringUtils
;
import
com.jh.boot.email.Email
;
import
com.jh.boot.email.EmailRecipient
;
...
...
@@ -27,9 +26,6 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
@Autowired
private
TemplateService
templateService
;
@Value
(
"${template.email.layout:email.layout}"
)
private
String
layoutTemplateCode
;
@Value
(
"${template.email.signup.subject:email.signup.subject}"
)
private
String
signupSubjectCode
;
...
...
@@ -77,14 +73,11 @@ public class TemplateEmailAuthServiceListener implements AuthServiceListener {
content
=
templateService
.
evaluate
(
content
,
data
,
locale
);
html
=
templateService
.
evaluate
(
html
,
data
,
locale
);
//is layout defined?
String
layout
=
templateService
.
evaluate
(
layoutTemplateCode
,
Collections
.
singletonMap
(
"content"
,
html
),
locale
);
Email
email
=
new
Email
();
email
.
setRecipients
(
Collections
.
singleton
(
new
EmailRecipient
(
user
.
getEmail
(),
RecipientType
.
TO
)));
email
.
setSubject
(
subject
);
email
.
setText
(
content
);
email
.
setHtml
(
StringUtils
.
hasText
(
layout
)
?
layout
:
html
);
email
.
setHtml
(
html
);
emailService
.
sendEmail
(
email
);
}
...
...
src/main/java/com/jh/boot/template/HibernateLoaderTemplateService.java
View file @
e4d42a34
...
...
@@ -30,16 +30,27 @@ public class HibernateLoaderTemplateService implements TemplateService {
}
Map
<
String
,
Object
>
values
=
new
HashMap
<
String
,
Object
>();
values
.
putAll
(
data
);
if
(
valuesConfig
!=
null
)
{
values
.
putAll
(
valuesConfig
.
getValues
());
}
values
.
putAll
(
data
);
String
content
=
t
.
getTemplate
();
StringWriter
sw
=
new
StringWriter
();
engine
.
evaluate
(
sw
,
content
,
values
);
content
=
sw
.
toString
();
if
(
t
.
getLayout
()
!=
null
)
{
t
=
loader
.
loadTemplate
(
t
.
getLayout
(),
locale
);
if
(
t
!=
null
)
{
values
.
put
(
"__layout_content__"
,
content
);
}
sw
=
new
StringWriter
();
engine
.
evaluate
(
sw
,
t
.
getTemplate
(),
values
);
content
=
sw
.
toString
();
}
return
sw
.
toString
()
;
return
content
;
}
@Autowired
...
...
src/main/java/com/jh/boot/template/HibernateTemplateLoader.java
View file @
e4d42a34
...
...
@@ -14,8 +14,16 @@ public class HibernateTemplateLoader implements TemplateLoader {
@Override
@Transactional
public
Template
loadTemplate
(
String
code
,
Locale
locale
)
{
// TODO Auto-generated method stub
return
null
;
String
l
=
locale
==
null
?
null
:
(
locale
.
getLanguage
()
+
"-"
+
locale
.
getCountry
());
Template
t
=
repository
.
loadTemplate
(
code
,
l
);
//TODO refactor
if
(
t
==
null
)
{
t
=
repository
.
loadTemplate
(
code
,
locale
.
getLanguage
());
}
if
(
t
==
null
)
{
t
=
repository
.
loadTemplate
(
code
,
null
);
}
return
t
;
}
}
src/main/java/com/jh/boot/template/HibernateTemplateRepository.java
View file @
e4d42a34
package
com
.
jh
.
boot
.
template
;
import
java.util.List
;
import
javax.persistence.TypedQuery
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.util.StringUtils
;
import
com.jh.boot.jpa.AbstractHibernateRepository
;
@Repository
public
class
HibernateTemplateRepository
extends
AbstractHibernateRepository
{
public
Template
loadTemplate
(
String
code
,
String
locale
)
{
if
(
code
==
null
)
{
return
null
;
}
String
hql
=
"select t from Template t where lower(code) = :code"
;
if
(
StringUtils
.
hasText
(
locale
))
{
hql
+=
" and lower(locale) = :locale"
;
}
else
{
hql
+=
" and locale is null"
;
}
TypedQuery
<
Template
>
q
=
entityManager
.
createQuery
(
hql
,
Template
.
class
);
q
.
setParameter
(
"code"
,
code
.
toLowerCase
());
if
(
StringUtils
.
hasText
(
locale
))
{
q
.
setParameter
(
"locale"
,
locale
.
toLowerCase
());
}
List
<
Template
>
list
=
q
.
getResultList
();
return
list
==
null
||
list
.
isEmpty
()
?
null
:
list
.
get
(
0
);
}
}
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