Bootcamp
Search…
5.POCE.2: Bug Reports AJAX Users

Base

Requirements

  1. 1.
    Add users to the Bug Reports app. In the migration, remember to add the foreign key to enable Bug to belong to User. In the model, remember to add the associations between Bug and User.
  2. 2.
    Create a User in the seed file and associate her with the Bugs in the seed file. Note that we can import the hashing library in the seed file to generate the seed user's hashed password.
  3. 3.
    User registration and login happen within the home route where the page does not refresh.

Schema

User Table (Users)

column name
data type
description
example
id
SERIAL PRIMARY KEY
ID
1
email
TEXT
User's email
password
TEXT
jdh3732gd
Hashed password

Bug Table (Bugs)

column name
data type
description
example
id
SERIAL PRIMARY KEY
ID
1
problem
TEXT
Description of the problem.
Crashes on POST request.
error_text
TEXT
Error output text, if any.
Cannot set property "fill" of null.
commit
TEXT
Git commit hash of solution.
961f1c
feature_id
Foreign Key
Foreign Feature Key
1
user_id
Foreign Key
Foreign User ID
1
Feature Table (Features)
column name
data type
description
example
id
SERIAL PRIMARY KEY
ID
1
name
TEXT
Name of the feature
Navbar

Comfortable

Auth-Protected Pages

When the site loads, use JavaScript to check if the user is currently logged in by reading and verifying their cookie values. If they are logged in, show the user their dashboard. If not, show them the login/registration form. To do this, we can use client-side JavaScript to read cookies, and send an AJAX request with those cookie values to verify cookie authenticity. Based on the server's response, we can decide what UI to render.

Email Validation

When the user clicks Submit to register, verify if their email is unique in the DB. If the email is not unique, continue to display the registration form and let the user know that their email is already used.

Reference solution

Click here for a reference solution for this POCE.