w4d4 - rails auth Flashcards

1
Q

How do you set up a transaction? Where would you set up one up?

A

transaction do … end

Set one up anywhere where you are making multiple database queries that must all succeed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a member route?

A

A route that applies to a single model

ex: /cats/5/pet_the_cat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the definition of being logged in?

A

We’re able to find a user in the database that has a .session_token equal to the session[:session_token] cookie value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you set encrypted cookies?

A

session[:some_key]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does session[:some_key] do?

A

Set an encrypted cookie.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why do you need an attr_reader for password in the user model?

A

we overwrite the password= method and so we need to be access @password to validate its length/complexity/etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Diff between BCrypt::Password.new/create ?

A
#new takes in a password digest
#create takes in a cleartext string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Difference between :: and . ?

A

:: accesses namespace’s objects

. accesses an instance’s objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why do we allow_nil on our password validator?

A

Once a password has been set, @password will generally be nil, as there is no password column for the User model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the pattern for logging in?

A

user = User.find_by_credentials(params[:username], params[:password])

user.reset_session_token!
session[:session_token] = user.session_token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you make controller methods available within a view?

A

in the controller

use helper_method :method_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why would you need a button for a logout link?

A

so you can access session#destroy via:

input type=”hidden” name=”_method”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly