Update kitura smtp to fix compile error

This commit is contained in:
Christoph Hagen 2022-12-18 17:19:19 +01:00
parent 76f5e6eb39
commit 2d683e34c4
3 changed files with 10 additions and 10 deletions

View File

@ -14,7 +14,7 @@ let package = Package(
// https://github.com/onevcat/Hedwig
// https://github.com/Joannis/SMTPKitten
// https://github.com/Joannis/VaporSMTPKit <- Uses SMTPKitten
.package(url: "https://github.com/Kitura/Swift-SMTP", from: "5.1.0"),
.package(url: "https://github.com/Kitura/Swift-SMTP", from: "6.0.0"),
],
targets: [
.target(

View File

@ -71,21 +71,21 @@ final class SQLiteDatabase {
Possible errors:
- `417`: Player name or email not found.
*/
func sendPasswordResetEmailIfPossible(name: PlayerName, in database: Database) async throws {
guard let user = try await User.query(on: database).filter(\.$name == name).first() else {
func sendPasswordResetEmailIfPossible(name: PlayerName, request: Request) async throws {
guard let user = try await User.query(on: request.db).filter(\.$name == name).first() else {
throw Abort(.expectationFailed)
}
guard let email = user.recoveryEmail else {
throw Abort(.expectationFailed)
}
try await user.$resetRequest.load(on: database)
if let request = user.resetRequest {
request.renew()
try await request.save(on: database)
self.sendEmail(name: name, email: email, token: request.resetToken)
try await user.$resetRequest.load(on: request.db)
if let reset = user.resetRequest {
reset.renew()
try await reset.save(on: request.db)
self.sendEmail(name: name, email: email, token: reset.resetToken)
} else {
let reset = PasswordReset()
try await user.$resetRequest.create(reset, on: database)
try await user.$resetRequest.create(reset, on: request.db)
self.sendEmail(name: name, email: email, token: reset.resetToken)
}
}

View File

@ -79,7 +79,7 @@ func registerPlayer(_ app: Application) {
func requestPlayerPasswordReset(_ app: Application) {
app.post("player", "password", "reset") { request async throws -> HTTPResponseStatus in
let name = try request.header(.name) // Error: 400
try await server.sendPasswordResetEmailIfPossible(name: name, in: request.db) // 417
try await server.sendPasswordResetEmailIfPossible(name: name, request: request) // 417
return .ok
}
}