* Add User model * Add SessionsController * Add password authentication on User * Request authentication for all actions except sign in * Add some helpers for ApplicationController * Update features to work with mandatory authentication
20 lines
369 B
Ruby
20 lines
369 B
Ruby
class ApplicationController < ActionController::Base
|
|
protect_from_forgery
|
|
|
|
before_filter :authenticate!
|
|
|
|
def current_user=(user)
|
|
session[:user_id] = user.id
|
|
end
|
|
|
|
def current_user
|
|
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
|
end
|
|
|
|
protected
|
|
|
|
def authenticate!
|
|
redirect_to new_session_path if current_user.nil?
|
|
end
|
|
end
|