Skip to content

Commit

Permalink
Send rich email
Browse files Browse the repository at this point in the history
  • Loading branch information
BoogieMonster1O1 committed Apr 25, 2024
1 parent c1da7d2 commit 5368343
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Resources/Views/signup.leaf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verification Code</title>
<style>
body {
font-family: San Francisco, Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}

.container {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.header {
text-align: center;
margin-bottom: 20px;
}

.footer {
margin-top: 20px;
text-align: center;
font-size: 12px;
color: #999999;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Welcome to Thoda Core</h2>
<p>Please use the following verification code:</p>
<h1 style="letter-spacing: 8px; font-size: 36px; margin-top: 10px;">#(code)</h1>
</div>

<div class="footer">
<p>This email was sent by Thoda Core. If you did not request this verification code, please ignore this email.</p>
<p>&copy; 2024 Project Kula</p>
</div>
</div>
</body>
</html>
6 changes: 5 additions & 1 deletion Sources/App/Controllers/Auth/SignupController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ struct SignupController: RouteCollection {
}

let code = try await getOrGenerateConfirmationCode(jwt: payload.state, req: req)

let emailBody: View = try await req.view.render("signup", ["code": code])
let body = emailBody.data.getString(at: 0, length: emailBody.data.readableBytes)

let email = try Email(
from: EmailAddress(address: appConfig.smtp.email, name: "Thoda Core"),
to: [EmailAddress(address: user.email, name: user.name)],
subject: "Your verification code",
body: "Your verification code is: \(code)"
body: body ?? "Your verification code is \(code)",
isBodyHtml: true
)

let sent = try await req.smtp.send(email) { message in
Expand Down
3 changes: 3 additions & 0 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Vapor
import Smtp
import Redis
import JWT
import Leaf

var appConfig: AppConfig = .init()

Expand Down Expand Up @@ -59,6 +60,8 @@ public func configure(_ app: Application) async throws {

app.routes.defaultMaxBodySize = "512kb"

app.views.use(.leaf)

// register routes
try routes(app)
}

0 comments on commit 5368343

Please sign in to comment.