-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: contact form (get in touch) sending mail + discord webhook
- Loading branch information
1 parent
03afade
commit 63fa3b8
Showing
20 changed files
with
262 additions
and
8 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
...nd/src/commonMain/kotlin/me/nathanfallet/groupeminaste/services/discord/DiscordService.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,31 @@ | ||
package me.nathanfallet.groupeminaste.services.discord | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.plugins.contentnegotiation.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import io.ktor.serialization.kotlinx.json.* | ||
import me.nathanfallet.groupeminaste.models.application.DiscordWebhook | ||
import me.nathanfallet.groupeminaste.models.application.GroupeMinasteJson | ||
|
||
class DiscordService( | ||
private val getInTouchWebhook: String, | ||
) : IDiscordService { | ||
|
||
private val client = HttpClient { | ||
install(ContentNegotiation) { | ||
json(GroupeMinasteJson.json) | ||
} | ||
} | ||
|
||
override suspend fun sendWebhookMessage(webhook: DiscordWebhook, message: String) { | ||
val url = when (webhook) { | ||
DiscordWebhook.GET_IN_TOUCH -> getInTouchWebhook | ||
} | ||
client.post(url) { | ||
contentType(ContentType.Application.Json) | ||
setBody(mapOf("content" to message)) | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...d/src/commonMain/kotlin/me/nathanfallet/groupeminaste/services/discord/IDiscordService.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,9 @@ | ||
package me.nathanfallet.groupeminaste.services.discord | ||
|
||
import me.nathanfallet.groupeminaste.models.application.DiscordWebhook | ||
|
||
interface IDiscordService { | ||
|
||
suspend fun sendWebhookMessage(webhook: DiscordWebhook, message: String) | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...ckend/src/commonMain/kotlin/me/nathanfallet/groupeminaste/services/email/EmailsService.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,34 @@ | ||
package me.nathanfallet.groupeminaste.services.email | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import me.nathanfallet.groupeminaste.models.application.Email | ||
import me.nathanfallet.usecases.emails.IEmail | ||
import org.apache.commons.mail.HtmlEmail | ||
|
||
class EmailsService( | ||
private val host: String, | ||
private val username: String, | ||
private val password: String, | ||
) : IEmailsService { | ||
|
||
override fun sendEmail(email: IEmail, destination: List<String>) { | ||
if (email !is Email) return | ||
CoroutineScope(Job()).launch { | ||
destination.forEach { target -> | ||
val htmlEmail = HtmlEmail() | ||
htmlEmail.hostName = host | ||
htmlEmail.isStartTLSEnabled = true | ||
htmlEmail.setSmtpPort(587) | ||
htmlEmail.setAuthentication(username, password) | ||
htmlEmail.setFrom(username) | ||
htmlEmail.addTo(target) | ||
htmlEmail.subject = email.title | ||
htmlEmail.setHtmlMsg(email.body) | ||
htmlEmail.send() | ||
} | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...kend/src/commonMain/kotlin/me/nathanfallet/groupeminaste/services/email/IEmailsService.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,9 @@ | ||
package me.nathanfallet.groupeminaste.services.email | ||
|
||
import me.nathanfallet.usecases.emails.IEmail | ||
|
||
interface IEmailsService { | ||
|
||
fun sendEmail(email: IEmail, destination: List<String>) | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/application/GetInTouchUseCase.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,32 @@ | ||
package me.nathanfallet.groupeminaste.usecases.application | ||
|
||
import me.nathanfallet.groupeminaste.models.application.DiscordWebhook | ||
import me.nathanfallet.groupeminaste.models.application.Email | ||
import me.nathanfallet.groupeminaste.models.application.GetInTouchPayload | ||
import me.nathanfallet.usecases.emails.ISendEmailUseCase | ||
|
||
class GetInTouchUseCase( | ||
private val sendEmailUseCase: ISendEmailUseCase, | ||
private val sendDiscordWebhookUseCase: ISendDiscordWebhookUseCase, | ||
) : IGetInTouchUseCase { | ||
|
||
override suspend fun invoke(input: GetInTouchPayload) { | ||
val message = """ | ||
|Nom: ${input.name} | ||
|Email: ${input.email} | ||
| | ||
|Message: | ||
|${input.message} | ||
""".trimMargin() | ||
|
||
sendEmailUseCase( | ||
Email("Have an Project in Mind?", message), | ||
listOf("contact@groupe-minaste.org") | ||
) | ||
sendDiscordWebhookUseCase( | ||
DiscordWebhook.GET_IN_TOUCH, | ||
message | ||
) | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...ommonMain/kotlin/me/nathanfallet/groupeminaste/usecases/application/IGetInTouchUseCase.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,6 @@ | ||
package me.nathanfallet.groupeminaste.usecases.application | ||
|
||
import me.nathanfallet.groupeminaste.models.application.GetInTouchPayload | ||
import me.nathanfallet.usecases.base.ISuspendUseCase | ||
|
||
interface IGetInTouchUseCase : ISuspendUseCase<GetInTouchPayload, Unit> |
6 changes: 6 additions & 0 deletions
6
...n/kotlin/me/nathanfallet/groupeminaste/usecases/application/ISendDiscordWebhookUseCase.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,6 @@ | ||
package me.nathanfallet.groupeminaste.usecases.application | ||
|
||
import me.nathanfallet.groupeminaste.models.application.DiscordWebhook | ||
import me.nathanfallet.usecases.base.IPairSuspendUseCase | ||
|
||
interface ISendDiscordWebhookUseCase : IPairSuspendUseCase<DiscordWebhook, String, Unit> |
13 changes: 13 additions & 0 deletions
13
...in/kotlin/me/nathanfallet/groupeminaste/usecases/application/SendDiscordWebhookUseCase.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,13 @@ | ||
package me.nathanfallet.groupeminaste.usecases.application | ||
|
||
import me.nathanfallet.groupeminaste.models.application.DiscordWebhook | ||
import me.nathanfallet.groupeminaste.services.discord.IDiscordService | ||
|
||
class SendDiscordWebhookUseCase( | ||
private val discordService: IDiscordService, | ||
) : ISendDiscordWebhookUseCase { | ||
|
||
override suspend fun invoke(input1: DiscordWebhook, input2: String) = | ||
discordService.sendWebhookMessage(input1, input2) | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
.../commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/application/SendEmailUseCase.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 me.nathanfallet.groupeminaste.usecases.application | ||
|
||
import me.nathanfallet.groupeminaste.services.email.IEmailsService | ||
import me.nathanfallet.usecases.emails.IEmail | ||
import me.nathanfallet.usecases.emails.ISendEmailUseCase | ||
|
||
class SendEmailUseCase( | ||
private val emailsService: IEmailsService, | ||
) : ISendEmailUseCase { | ||
|
||
override fun invoke(input1: IEmail, input2: List<String>) { | ||
emailsService.sendEmail(input1, input2) | ||
} | ||
|
||
} |
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
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
21 changes: 21 additions & 0 deletions
21
groupeminaste-backend/src/commonMain/resources/templates/public/getintouch.ftl
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,21 @@ | ||
<#import "../template.ftl" as template> | ||
<@template.page> | ||
<section id="contact" class="py-[120px]"> | ||
<div class="container"> | ||
<div class="flex flex-wrap mx-[-16px]"> | ||
<div class="w-full px-4"> | ||
<div class="max-w-[600px] mx-auto text-center mb-[50px]"> | ||
<span class="font-semibold text-lg text-primary block mb-2"><@t key="home_contact_headline" /></span> | ||
<h2 class="font-bold text-black text-3xl sm:text-4xl md:text-[45px] mb-5"><@t key="home_contact_title" /></h2> | ||
<p class="font-medium text-lg text-body-color"><@t key="home_contact_confirmation" /></p> | ||
|
||
<a href="/${locale}" | ||
class="pt-4 inline-flex justify-center items-center py-4 px-9 rounded-full font-semibold text-white bg-primary mx-auto transition duration-300 ease-in-out hover:shadow-signUp hover:bg-opacity-90"> | ||
<@t key="home_contact_back" /> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</@template.page> |
7 changes: 7 additions & 0 deletions
7
.../src/commonMain/kotlin/me/nathanfallet/groupeminaste/models/application/DiscordWebhook.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 me.nathanfallet.groupeminaste.models.application | ||
|
||
enum class DiscordWebhook { | ||
|
||
GET_IN_TOUCH | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...e-commons/src/commonMain/kotlin/me/nathanfallet/groupeminaste/models/application/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,8 @@ | ||
package me.nathanfallet.groupeminaste.models.application | ||
|
||
import me.nathanfallet.usecases.emails.IEmail | ||
|
||
data class Email( | ||
val title: String, | ||
val body: String, | ||
) : IEmail |
10 changes: 10 additions & 0 deletions
10
...c/commonMain/kotlin/me/nathanfallet/groupeminaste/models/application/GetInTouchPayload.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,10 @@ | ||
package me.nathanfallet.groupeminaste.models.application | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GetInTouchPayload( | ||
val name: String, | ||
val email: String, | ||
val message: String, | ||
) |