Login
public final class Login<
T: CorvusModelTokenAuthenticatable & ResponseEncodable>:
Endpoint where T.User: CorvusModelAuthenticatable
A class that provides functionality to log in a user with username and
password credentials sent in a HTTP POST Request and save a token for
that user. Needs an object of type T which represents the token to be
created upon login.
-
Initializes the component with a path to its functionality.
Declaration
Swift
public init(_ path: PathComponent)Parameters
pathA
PathComponentdescribing the path to the endpoint. -
Logs in a user passed in a
Requestby creating a bearer token for it and saving it in the database.Throws
AnAborterror if something goes wrong.Declaration
Swift
public func handler(_ req: Request) throws -> EventLoopFuture<T>Parameters
reqAn incoming HTTP
Request.Return Value
An
EventLoopFuturecontaining the created token. -
A method that registers the
handler()to the suppliedRoutesBuilder. It also registers basic authentication middleware using the user belonging to the tokenT.Declaration
Swift
public func register(to routes: RoutesBuilder)Parameters
routesA
RoutesBuildercontaining all the information about the HTTP route leading to the current component.
Login Class Reference