I want to learn how to create my own authentication system, please provide some guidance if am doing this wrong.
- I will create a Module in my /lib folder /lib/auth.rb
- I will require this module in my ApplicationController.
- when a user enters their email + password, I will call a method that will do a lookup in the user's table for a user with the same email, I will then compare the passwords. (i'll add encryption with salt later).
- If the user entered the correct credentials, I will create a row in the Sessions table, and then write the session GUID to a cookie.
- Now whenever I need to check if the user is logged in, or I need the user object, I will check if the cookie exists, if it does, I will lookup the session table for a row with the same guid, if it exists, I will return the session row and then load the User object.
I realize there are many suggestions one can give, but in a nutshell does this sound like a workable solution?
Now to make this usable, I will have to make some helper methods in my ApplicationController right?
How will I access the current_user from within my views?
P.S I know of other authentication systems, I just want to learn how to create my own.