Skip to content

Instantly share code, notes, and snippets.

@brettbuddin
Created February 24, 2011 19:50
Show Gist options
  • Save brettbuddin/842751 to your computer and use it in GitHub Desktop.
Save brettbuddin/842751 to your computer and use it in GitHub Desktop.
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :login, :null => false
t.string :email, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false
t.string :persistence_token, :null => false
t.string :single_access_token, :null => false
t.string :perishable_token, :null => false
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
t.timestamps
end
end
def self.down
drop_table :users
end
end
protect_from_forgery
helper :all
helper_method :current_user_session, :current_user, :navigation_data
private
def navigation_data
@work_categories = WorkSeries.find :all
@personal_categories = PersonalSeries.find :all
end
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
def require_user
unless current_user
store_location
flash[:notice] = "You must be logged in to access this page"
redirect_to new_manage_session_url
return false
end
end
def require_no_user
if current_user
store_location
flash[:notice] = "You must be logged out to access this page"
redirect_to manage_photos_url
return false
end
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment