Compare commits

...

1 Commits
1.3.0 ... main

Author SHA1 Message Date
Johan Carlberg c74474241a Show expiration time of password link in invites and forgotten password emails. 2026-02-22 21:40:10 +01:00
4 changed files with 16 additions and 6 deletions

View File

@ -1,3 +1,5 @@
Välkommen till #(host). Welcome to #(host).
För att aktivera ditt konto, gå till #baseURL/auth/password/#(token) och skriv in ett lösenord. To activate your account, go to #baseURL/auth/password/#(token) and enter a password.
The link is valid until #date(expiration, "yyyy-MM-dd HH:mm (z)").

View File

@ -1,3 +1,5 @@
Du har begärt ett nytt lösenord på #(host). You have requested a new password on #(host).
För att ändra ditt lösenord, gå till #baseURL/auth/password/#(token) och skriv in ett lösenord. To change your password, go to #baseURL/auth/password/#(token) and enter a password.
The link is valid until #date(expiration, "yyyy-MM-dd HH:mm (z)").

View File

@ -88,7 +88,7 @@ public struct AdminController<User: ManagedUser>: Sendable where User.SessionID
let token = try await UserToken.create (connection: connection).token let token = try await UserToken.create (connection: connection).token
try await User.create (email: invitation.email, fullname: invitation.fullname, roles: invitation.roles, token: token, on: connection) try await User.create (email: invitation.email, fullname: invitation.fullname, roles: invitation.roles, token: token, on: connection)
let host = try Environment.baseURL.host() ?? "" let host = try Environment.baseURL.host() ?? ""
let body = try await request.view.render ("email/invite", ["token": token, "host": host]) let body = try await request.view.render ("email/invite", AuthenticationController<User>.TokenEmailContext (token: token, host: host, expiration: Calendar.current.date (byAdding: .day, value: 1, to: Date()) ?? Date()))
.data .data
let message = Email (sender: Email.Contact (emailAddress: try Environment.emailSender), let message = Email (sender: Email.Contact (emailAddress: try Environment.emailSender),
recipients: [Email.Contact(emailAddress: invitation.email)], recipients: [Email.Contact(emailAddress: invitation.email)],

View File

@ -91,6 +91,12 @@ public struct AuthenticationController<User: ManagedUser>: Sendable where User.S
let email: String let email: String
} }
struct TokenEmailContext: Encodable {
let token: String
let host: String
let expiration: Date
}
func forgotPassword (request: Request) async throws -> Response { func forgotPassword (request: Request) async throws -> Response {
let input = try request.content.decode (Input.self) let input = try request.content.decode (Input.self)
@ -101,7 +107,7 @@ public struct AuthenticationController<User: ManagedUser>: Sendable where User.S
let token = try await UserToken.create (connection: connection).token let token = try await UserToken.create (connection: connection).token
try await User.store (token: token, userId: user.id, on: connection) try await User.store (token: token, userId: user.id, on: connection)
let host = try Environment.baseURL.host() ?? "" let host = try Environment.baseURL.host() ?? ""
let body = try await request.view.render ("email/reset", ["token": token, "host": host, "section": "login"]) let body = try await request.view.render ("email/reset", TokenEmailContext (token: token, host: host, expiration: Calendar.current.date (byAdding: .hour, value: 1, to: Date()) ?? Date()))
.data .data
let message = Email (sender: Email.Contact (emailAddress: try Environment.emailSender), let message = Email (sender: Email.Contact (emailAddress: try Environment.emailSender),
recipients: [Email.Contact(emailAddress: input.email)], recipients: [Email.Contact(emailAddress: input.email)],