Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
uphrh-smf-user
Commits
5eb573f4
Commit
5eb573f4
authored
3 years ago
by
nivetha
Browse files
Options
Download
Patches
Plain Diff
Notification template
parent
b0f3ade4
master
bulkupload
delete-user
delete-user-fix
increase_timeout
institute-district
maney-test
sessionTimeout
updateEmailContentforOTP
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java
+5
-10
...java/com/tarento/retail/service/impl/UserServiceImpl.java
src/main/java/com/tarento/retail/util/Constants.java
+4
-0
src/main/java/com/tarento/retail/util/Constants.java
src/main/java/com/tarento/retail/util/NotificationService.java
+57
-4
...ain/java/com/tarento/retail/util/NotificationService.java
with
66 additions
and
14 deletions
+66
-14
src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java
+
5
−
10
View file @
5eb573f4
...
...
@@ -15,6 +15,7 @@ import java.util.Map.Entry;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.apache.velocity.VelocityContext
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -506,8 +507,10 @@ public class UserServiceImpl implements UserDetailsService, UserService {
String
otp
=
Util
.
generateOTP
();
// send Email
String
[]
receipent
=
{
email
};
Boolean
sendEmail
=
NotificationService
.
sendMail
(
receipent
,
Constants
.
OTP_EMAIL_SUBJECT
,
String
.
format
(
Constants
.
OTP_EMAIL_BODY
,
otp
));
VelocityContext
context
=
new
VelocityContext
();
context
.
put
(
"otp"
,
otp
);
Boolean
sendEmail
=
NotificationService
.
sendMail
(
receipent
,
Constants
.
OTP_EMAIL_SUBJECT
,
context
,
Constants
.
EmailTemplate
.
OTP
);
if
(
sendEmail
)
{
Cache
.
setUserOTPData
(
email
,
otp
);
return
Boolean
.
TRUE
;
...
...
@@ -522,17 +525,9 @@ public class UserServiceImpl implements UserDetailsService, UserService {
@Override
public
Boolean
validateUserOTP
(
String
username
,
String
otp
)
{
try
{
// LoginDto loginDto = new LoginDto();
LoginAuthentication
loginAuth
=
Cache
.
getUserAuthData
(
username
);
if
(
loginAuth
!=
null
&&
loginAuth
.
getOtpExpiryDate
()
>
DateUtil
.
getCurrentTimestamp
()
&&
loginAuth
.
getOtp
().
equals
(
otp
))
{
// // generate user session id and cache it
// String sessionId = Util.getUniqueSessionId(username);
// Cache.setTokenDetails(username, sessionId);
//
// loginDto.setAuthToken(sessionId);
// loginDto.setUsername(username);
// return loginDto;
return
Boolean
.
TRUE
;
}
}
catch
(
Exception
e
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/retail/util/Constants.java
+
4
−
0
View file @
5eb573f4
...
...
@@ -85,6 +85,10 @@ public class Constants {
public
static
final
String
OTP_EMAIL_SUBJECT
=
"UP SMF - OTP request"
;
public
static
final
String
OTP_EMAIL_BODY
=
"UP SMF login OTP: %s. Valid for 5 minutes"
;
public
interface
EmailTemplate
{
public
static
final
String
OTP
=
"/otp_template.vm"
;
}
public
static
enum
CountryList
{
SWE
(
1
,
"Sweden"
,
"SWEDEN"
),
NOR
(
2
,
"Norway"
,
"NORWAY"
),
FIN
(
3
,
"Finland"
,
"FINLAND"
),
IND
(
4
,
"India"
,
"INDIA"
);
private
int
countryCode
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/retail/util/NotificationService.java
+
57
−
4
View file @
5eb573f4
package
com.tarento.retail.util
;
import
java.io.StringWriter
;
import
java.util.Properties
;
import
javax.mail.Message
;
...
...
@@ -8,6 +9,11 @@ import javax.mail.Transport;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeMessage
;
import
org.apache.velocity.Template
;
import
org.apache.velocity.VelocityContext
;
import
org.apache.velocity.app.VelocityEngine
;
import
org.apache.velocity.runtime.RuntimeConstants
;
import
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -36,18 +42,17 @@ public class NotificationService {
}
private
static
final
String
SMTP
=
"smtp"
;
private
static
final
String
TEXT_HTML
=
"text/html"
;
/**
* this method is used to send email.
*
* @param receipent
* email to whom we send mail
* @param context
* VelocityContext
* @param templateName
* String
* @param subject
* subject
* @param body
* body
*/
@Async
public
static
Boolean
sendMail
(
String
[]
recipient
,
String
subject
,
String
body
)
{
...
...
@@ -78,4 +83,52 @@ public class NotificationService {
return
Boolean
.
FALSE
;
}
/**
* this method is used to send email.
*
* @param receipent
* email to whom we send mail
* @param context
* VelocityContext
* @param templateName
* String
* @param subject
* subject
* @return
*/
@Async
public
static
Boolean
sendMail
(
String
[]
receipent
,
String
subject
,
VelocityContext
context
,
String
templateName
)
{
try
{
Session
session
=
Session
.
getInstance
(
props
,
new
GMailAuthenticator
(
appConfiguration
.
getSmtpUser
(),
appConfiguration
.
getSmtpPassword
()));
MimeMessage
message
=
new
MimeMessage
(
session
);
message
.
setFrom
(
new
InternetAddress
(
appConfiguration
.
getSmtpEmail
()));
int
size
=
receipent
.
length
;
int
i
=
0
;
while
(
size
>
0
)
{
message
.
addRecipient
(
Message
.
RecipientType
.
BCC
,
new
InternetAddress
(
receipent
[
i
]));
i
++;
size
--;
}
message
.
setSubject
(
subject
);
VelocityEngine
engine
=
new
VelocityEngine
();
engine
.
setProperty
(
RuntimeConstants
.
RESOURCE_LOADER
,
"classpath"
);
engine
.
setProperty
(
"classpath.resource.loader.class"
,
ClasspathResourceLoader
.
class
.
getName
());
engine
.
init
();
Template
template
=
engine
.
getTemplate
(
templateName
);
StringWriter
writer
=
new
StringWriter
();
template
.
merge
(
context
,
writer
);
message
.
setContent
(
writer
.
toString
(),
TEXT_HTML
);
Transport
transport
=
session
.
getTransport
(
SMTP
);
transport
.
connect
(
appConfiguration
.
getSmtpHost
(),
appConfiguration
.
getSmtpUser
(),
appConfiguration
.
getSmtpPassword
());
transport
.
sendMessage
(
message
,
message
.
getAllRecipients
());
transport
.
close
();
return
Boolean
.
TRUE
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
String
.
format
(
"Exception in %s : %s"
,
"sendMail"
,
e
.
getMessage
()));
return
Boolean
.
FALSE
;
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets