-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add name and avatar to user, refactoring (#11)
- Loading branch information
1 parent
7013899
commit d0acfd1
Showing
9 changed files
with
166 additions
and
114 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Petr Pavlik on 29.01.2024. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
import MixpanelVapor | ||
|
||
extension Request { | ||
func trackAnalyticsEvent(name: String, params: [String: any Content] = [:]) async { | ||
|
||
guard application.environment.isRelease else { | ||
return | ||
} | ||
|
||
var params = params | ||
if let profile = try? await profile { | ||
|
||
if let profileId = profile.id { | ||
params["$user_id"] = profileId.uuidString | ||
} | ||
|
||
params["$email"] = profile.email | ||
|
||
if let name = profile.name { | ||
params["$name"] = name | ||
} | ||
if let avatarUrl = profile.avatarUrl { | ||
params["$avatar"] = avatarUrl | ||
} | ||
} | ||
|
||
// Log to a destination of your choice | ||
await mixpanel.track(name: name, request: self, params: params) | ||
} | ||
} |
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,59 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Petr Pavlik on 29.01.2024. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
import VaporSMTPKit | ||
import SMTPKitten | ||
|
||
extension Application { | ||
func sendEmail(subject: String, message: String, to email: String) async throws { | ||
guard try Environment.detect() != .testing else { | ||
return | ||
} | ||
|
||
// Following logic uses an email integrated through STMP to send your transactional emails | ||
// You can replace this with email provider of your choice, like Amazon SES or resend.com | ||
|
||
guard let smtpHostName = Environment.process.SMTP_HOSTNAME else { | ||
throw Abort(.internalServerError, reason: "SMTP_HOSTNAME env variable not defined") | ||
} | ||
|
||
guard let smtpEmail = Environment.process.SMTP_EMAIL else { | ||
throw Abort(.internalServerError, reason: "SMTP_EMAIL env variable not defined") | ||
} | ||
|
||
guard let smtpPassword = Environment.process.SMTP_PASSWORD else { | ||
throw Abort(.internalServerError, reason: "SMTP_PASSWORD env variable not defined") | ||
} | ||
|
||
let credentials = SMTPCredentials( | ||
hostname: smtpHostName, | ||
ssl: .startTLS(configuration: .default), | ||
email: smtpEmail, | ||
password: smtpPassword | ||
) | ||
|
||
let email = Mail( | ||
from: .init(name: "[name] from [company]", email: smtpEmail), | ||
to: [ | ||
MailUser(name: nil, email: email) | ||
], | ||
subject: subject, | ||
contentType: .plain, // supports html | ||
text: message | ||
) | ||
|
||
try await sendMail(email, withCredentials: credentials).get() | ||
} | ||
} | ||
|
||
extension Request { | ||
func sendEmail(subject: String, message: String, to: String) async throws { | ||
try await self.application.sendEmail(subject: subject, message: message, to: to) | ||
} | ||
} |
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