Skip to content

Commit 2bae5b7

Browse files
committed
display error message in forgot password
1 parent 8d4508f commit 2bae5b7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Sources/App/Controllers/Manage/ForgotPasswordController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SotoCognitoIdentity
88
enum ForgotPasswordController {
99
@Sendable
1010
static func show(req: Request) async throws -> HTML {
11-
return ForgotPassword.View(path: req.url.path).document()
11+
return ForgotPassword.View(path: req.url.path, model: ForgotPassword.Model()).document()
1212
}
1313

1414
@Sendable
@@ -21,8 +21,7 @@ enum ForgotPasswordController {
2121
try await req.application.cognito.authenticatable.forgotPassword(username: user.email)
2222
return Reset.View(path: SiteURL.resetPassword.relativeURL(), model: Reset.Model(email: user.email)).document()
2323
} catch {
24-
// TODO: handle this
25-
return Reset.View(path: SiteURL.resetPassword.relativeURL(), model: Reset.Model(email: user.email)).document()
24+
return ForgotPassword.View(path: req.url.path, model: ForgotPassword.Model(errorMessage: "There was an error. Please try again.")).document()
2625
}
2726
}
2827
}

Sources/App/Views/Manage/ForgotPassword+View.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ import Foundation
33

44
enum ForgotPassword {
55

6+
struct Model {
7+
var errorMessage: String = ""
8+
}
9+
610
class View: PublicPage {
711

12+
let model: Model
13+
14+
init(path: String, model: Model) {
15+
self.model = model
16+
super.init(path: path)
17+
}
18+
819
override func pageTitle() -> String? {
920
"Forgot Password"
1021
}
@@ -13,7 +24,8 @@ enum ForgotPassword {
1324
.div(
1425
.class("manage-page"),
1526
.h2("An email will be sent with a reset code"),
16-
.forgotPasswordForm()
27+
.forgotPasswordForm(),
28+
.text(model.errorMessage)
1729
)
1830
}
1931
}

0 commit comments

Comments
 (0)