You just had the time of your life adding hand rolled auth to a Rails app.
But you know by now that this stuff doesn't stick without practice. So let's practice!
Here is your mission:
rails new <insert an app name here> -d postgresql -T
- Generate a
User
model compatible withhas_secure_password
authentication. Hint: Don't forget a certain critical attribute... - Your choice on whether to use an
email
orusername
attribute to uniquely identify your user, however, as a user and a dev, I preferemail
. - Include in your model any additional fields you want (
first_name
,age
, etc.). - Do not generate any other models in this lab! You will only need the
User
model. - Code out your
User
model so that you can create new users in the Rails console and that:
- Saving fails unless a unique
email
orusername
is provided. Test this by attempting to create the same user twice. - Saving fails if the
password
andpassword_confirmation
don't match. - The saved user has a
password_digest
.
- Provide a
users#index
action that displays all users in the database. Display each user'semail
orusername
. - On the
index
view, include aSign Up
link that displays a sign up form, creates the user in the database when submitted and returns to theindex
view. - On the
index
view, include aLog In
link that displays a login form that logs in the user when submitted with valid credentials and returns to theindex
view. - On the
index
view, if a user IS logged in, don't show theSign Up
orLog In
links. Show aLog Out
link instead that when clicked, logs out the user shows theindex
view. This functionality should hold up if the page is refreshed (requires that the login be persisted in the session).
- Require that passwords be at least 4 characters in length.
- If, and only if, a user is logged in, display a
delete
link next to eachemail
orusername
on theindex
view, except for the user that is currently logged in. Clicking thedelete
link should remove that user from the database and return to theindex
view.
- If you complete this lab, you will in essence have an excellent starting point for your Project 2!