-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
214 additions
and
143 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/vauthenticator/server/VAuthenticatorApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...cation/email/NoReplyEMailConfiguration.kt → ...munication/CustomerCommunicationConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/vauthenticator/server/communication/adapter/JinJavaTemplateResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vauthenticator.server.communication.adapter | ||
|
||
import com.hubspot.jinjava.Jinjava | ||
import com.vauthenticator.server.communication.domain.MessageTemplateResolver | ||
|
||
class JinJavaTemplateResolver(private val engine: Jinjava) : MessageTemplateResolver { | ||
override fun compile(template: String, context: Map<String, Any>): String { | ||
return engine.render(template, context) | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...in/kotlin/com/vauthenticator/server/communication/adapter/email/JavaEMailSenderService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.vauthenticator.server.communication.adapter.email | ||
|
||
import com.vauthenticator.document.repository.DocumentRepository | ||
import com.vauthenticator.document.repository.DocumentType | ||
import com.vauthenticator.server.account.Account | ||
import com.vauthenticator.server.communication.domain.* | ||
import jakarta.mail.internet.MimeMessage | ||
import org.springframework.mail.javamail.JavaMailSender | ||
import org.springframework.mail.javamail.MimeMessageHelper | ||
|
||
|
||
class JavaEMailSenderService( | ||
private val documentRepository: DocumentRepository, | ||
private val mailSender: JavaMailSender, | ||
private val templateResolver: MessageTemplateResolver, | ||
private val emailMessageFactory: EMailMessageFactory | ||
) : EMailSenderService { | ||
|
||
override fun sendFor(account: Account, emailContext: MessageContext) { | ||
val mailMessage = emailMessageFactory.makeMailMessageFor(account, emailContext) | ||
val mailContent = mailTemplateFor(mailMessage) | ||
val email = composeMailFor(mailContent, mailMessage) | ||
mailSender.send(email) | ||
} | ||
|
||
private fun mailTemplateFor(email: EMailMessage): String { | ||
val documentContent = | ||
documentRepository.loadDocument(DocumentType.MAIL.content, mailTemplatePathFor(email.type)) | ||
return String(documentContent.content) | ||
} | ||
|
||
private fun mailTemplatePathFor(emailType: EMailType): String = emailType.path | ||
|
||
private fun composeMailFor(mailContent: String, emailMessage: EMailMessage): MimeMessage { | ||
val mimeMessage: MimeMessage = mailSender.createMimeMessage() | ||
|
||
val helper = MimeMessageHelper(mimeMessage, "utf-8") | ||
helper.setText(templateResolver.compile(mailContent, emailMessage.context), true) // Use this or above line. | ||
helper.setTo(emailMessage.to) | ||
helper.setSubject(emailMessage.subject) | ||
helper.setFrom(emailMessage.from) | ||
|
||
return mimeMessage | ||
} | ||
|
||
} |
17 changes: 5 additions & 12 deletions
17
...ver/communication/sms/SmsSenderService.kt → ...cation/adapter/sms/SnsSmsSenderService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...rver/communication/email/EMailEndPoint.kt → ...server/communication/api/EMailEndPoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/vauthenticator/server/communication/domain/Email.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.vauthenticator.server.communication.domain | ||
|
||
import com.vauthenticator.server.account.Account | ||
|
||
fun interface EMailSenderService { | ||
fun sendFor(account: Account, emailContext: MessageContext) | ||
} | ||
|
||
fun interface EMailMessageFactory { | ||
fun makeMailMessageFor(account: Account, requestContext: MessageContext): EMailMessage | ||
} | ||
|
||
class SimpleEMailMessageFactory(val from: String, val subject: String, private val emailType: EMailType) : | ||
EMailMessageFactory { | ||
|
||
override fun makeMailMessageFor(account: Account, requestContext: MessageContext): EMailMessage { | ||
val context = messageContextFrom(account) + requestContext | ||
return EMailMessage(context["email"] as String, from, subject, emailType, context) | ||
} | ||
|
||
} | ||
|
||
enum class EMailType(val path: String) { | ||
WELCOME("templates/welcome.html"), | ||
EMAIL_VERIFICATION("templates/email-verify-challenge.html"), | ||
RESET_PASSWORD("templates/reset-password.html"), | ||
MFA("templates/mfa-challenge.html"); | ||
} | ||
|
||
data class EMailMessage( | ||
val to: String, | ||
val from: String, | ||
val subject: String, | ||
val type: EMailType = EMailType.WELCOME, | ||
val context: MessageContext | ||
) | ||
|
||
data class EMailTemplate(val emailType: EMailType, val body: String) |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/vauthenticator/server/communication/domain/MessageContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.vauthenticator.server.communication.domain | ||
|
||
import com.vauthenticator.server.account.Account | ||
|
||
typealias MessageContext = Map<String, Any> | ||
|
||
fun messageContextFrom(account: Account) = | ||
mapOf( | ||
"enabled" to account.enabled, | ||
"username" to account.username, | ||
"authorities" to account.authorities, | ||
"email" to account.email, | ||
"firstName" to account.firstName, | ||
"lastName" to account.lastName, | ||
"birthDate" to account.birthDate.map { it.iso8601FormattedDate() }.orElse(""), | ||
"phone" to account.phone.map { it.formattedPhone() }.orElse("") | ||
) | ||
|
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/vauthenticator/server/communication/domain/MessageTemplateResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.vauthenticator.server.communication.domain | ||
|
||
interface MessageTemplateResolver { | ||
|
||
fun compile(template: String, context: Map<String, Any>): String | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/vauthenticator/server/communication/domain/Sms.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.vauthenticator.server.communication.domain | ||
|
||
import com.vauthenticator.server.account.Account | ||
|
||
data class SmsMessage(val phoneNumber: String, val message: String) | ||
|
||
|
||
fun interface SmsSenderService { | ||
fun sendFor(account: Account, smsContext: MessageContext) | ||
} | ||
|
||
fun interface SmsMessageFactory { | ||
fun makeSmsMessageFor(account: Account, requestContext: MessageContext): SmsMessage | ||
} | ||
|
13 changes: 0 additions & 13 deletions
13
src/main/kotlin/com/vauthenticator/server/communication/email/EMailMessage.kt
This file was deleted.
Oops, something went wrong.
71 changes: 0 additions & 71 deletions
71
src/main/kotlin/com/vauthenticator/server/communication/email/EMailSender.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/kotlin/com/vauthenticator/server/communication/email/EMailTemplateResolver.kt
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
src/main/kotlin/com/vauthenticator/server/communication/sms/SmsMessage.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.