w4d4 - rails auth Flashcards
How do you set up a transaction? Where would you set up one up?
transaction do … end
Set one up anywhere where you are making multiple database queries that must all succeed.
What is a member route?
A route that applies to a single model
ex: /cats/5/pet_the_cat
What’s the definition of being logged in?
We’re able to find a user in the database that has a .session_token equal to the session[:session_token] cookie value
How do you set encrypted cookies?
session[:some_key]
What does session[:some_key] do?
Set an encrypted cookie.
Why do you need an attr_reader for password in the user model?
we overwrite the password= method and so we need to be access @password to validate its length/complexity/etc
Diff between BCrypt::Password.new/create ?
#new takes in a password digest #create takes in a cleartext string
Difference between :: and . ?
:: accesses namespace’s objects
. accesses an instance’s objects
Why do we allow_nil on our password validator?
Once a password has been set, @password will generally be nil, as there is no password column for the User model
What’s the pattern for logging in?
user = User.find_by_credentials(params[:username], params[:password])
user.reset_session_token!
session[:session_token] = user.session_token
How do you make controller methods available within a view?
in the controller
use helper_method :method_name
Why would you need a button for a logout link?
so you can access session#destroy via:
input type=”hidden” name=”_method”