The Auth Controller

flitter-auth/deploy/controllers/Auth.controller.js

deployed to: app/controllers/auth/Auth.controller.js         exports:  class Auth

class Auth

create_auth_session(express.request req, flitter-auth/deploy/models/User user)

returns:  undefined

Creates a new Object in req.session.auth that indicates that the user is logged in and provides information about them, but sanitizes the password field. This Object contains the following:

Key Value
authenticated true
uuid user.uuid
user user (password field is blanked)
destroy_auth_session(express.request req)

returns:  undefined

Removes any information in req.session.auth by reassigning it to an empty Object. This is effectually "logging out" the user, but it will succeed even if no user existed in the first place.

register_get(express.request req, express.response res)

returns:  mixed

Serve the register view. Looks for session data from any submitted auth forms. If session data exists, retrieve it and delete it. Pass that data to the auth/register view and serve said view. Returns the value of view().

register_post(express.request req, express.response res)

returns:  mixed

Handles an attempt at registration. Validates the required input from req.body and formatting for the username, password, and password_verify fields. If any of these fail validation, redirect back to /auth/register after writing the errors and username to the session. If validation succeeds, it creates a new instance of flitter-auth/deploy/models/User with the provided input as data. After saving the user, it returns the auth/register_success view.

logout(express.request req, express.response res)

returns:  mixed

Calls this.destroy_auth_session on the provided req then returns the auth/logged_out view.

login_get(express.request req, express.response res)

returns:  mixed

Serve the login view. Looks for session data from any submitted auth forms. If session data exists, retrieve it and delete it. Pass that data to the auth/login view and serve said view. Returns the value of view().

login_post(express.request req, express.response res)

returns:  mixed

Handles an attempted login. Validates the required input from req.body and formatting for the username and password fields. Then, it attempts to retrieve the flitter-auth/deploy/models/User instance with the corresponding username and check the password against the stored hash. If any of this fails, it writes the errors and username to session data and redirects back to the /auth/login route.

If the authentication succeeds, it checks to see if req.session.destination is set. If it is, it redirects the user there. If not, it redirects the user to the /auth/dash route.

dash_get(express.request req, express.response res)

returns:  mixed

Returns the auth/dash view. Passes req.session.auth.user to the view as user.

No Comments
Back to top