Created
May 5, 2014 22:00
-
-
Save tubbo/29ccd52673c04771174c to your computer and use it in GitHub Desktop.
This file contains 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
class ApplicationController < ActionController::Base | |
# Prevent CSRF attacks by raising an exception. | |
# For APIs, you may want to use :null_session instead. | |
protect_from_forgery with: :exception | |
before_filter :require_login | |
helper_method :current_user | |
private | |
def current_user | |
@current_user ||= User.find(session[:user_id]) if session[:user_id] | |
end | |
def require_login | |
redirect_to 'welcome/index' unless :current_user? | |
end | |
#end | |
end |
This file contains 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
class WelcomeController < ApplicationController | |
skip_before_filter :require_login | |
... | |
def auth | |
user = User.find_by_email(params[:email]) | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to root_url | |
else | |
redirect_to login_path | |
end | |
end | |
def logout | |
session[:user_id] = nil | |
redirect_to root_url | |
end | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment