Skip to content

Instantly share code, notes, and snippets.

@tubbo
Created May 5, 2014 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/29ccd52673c04771174c to your computer and use it in GitHub Desktop.
Save tubbo/29ccd52673c04771174c to your computer and use it in GitHub Desktop.
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
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