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

    path

    A PathComponent describing the path to the endpoint.

  • Logs in a user passed in a Request by creating a bearer token for it and saving it in the database.

    Throws

    An Abort error if something goes wrong.

    Declaration

    Swift

    public func handler(_ req: Request) throws -> EventLoopFuture<T>

    Parameters

    req

    An incoming HTTP Request.

    Return Value

    An EventLoopFuture containing the created token.

  • A method that registers the handler() to the supplied RoutesBuilder. It also registers basic authentication middleware using the user belonging to the token T.

    Declaration

    Swift

    public func register(to routes: RoutesBuilder)

    Parameters

    routes

    A RoutesBuilder containing all the information about the HTTP route leading to the current component.