Created
September 14, 2013 12:13
-
-
Save igkuz/6561527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module AuthHelper | |
| def sign_in(user) | |
| session[:user_id] = user.id | |
| end | |
| def sign_out | |
| session[:user_id] = nil | |
| end | |
| def signed_in? | |
| session[:user_id] && User.find_by_id(session[:user_id]) | |
| end | |
| def authenticate_user! | |
| redirect_to new_session_path if !signed_in? || !current_user.admin? | |
| end | |
| def authenticate_client! | |
| redirect_to new_session_path if !signed_in? || current_user.admin? | |
| end | |
| def current_user | |
| @current_user ||= User.find(session[:user_id]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment