diff --git a/Package.swift b/Package.swift index 77c2016..73089a6 100644 --- a/Package.swift +++ b/Package.swift @@ -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( diff --git a/Sources/App/Management/SQLiteDatabase.swift b/Sources/App/Management/SQLiteDatabase.swift index 0e72527..926e1a2 100644 --- a/Sources/App/Management/SQLiteDatabase.swift +++ b/Sources/App/Management/SQLiteDatabase.swift @@ -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) } } diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index f8bbbcb..eb08790 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -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 } }