Created
February 1, 2011 01:40
-
-
Save harfangk/805250 to your computer and use it in GitHub Desktop.
authlogic deal
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
usersessionscontroller.rb | |
class UserSessionsController < ApplicationController | |
before_filter :require_no_user, :only => [:new, :create] | |
before_filter :require_user, :only => :destroy | |
def new | |
@user_session = UserSession.new | |
end | |
def create | |
@user_session = UserSession.new(params[:user_session]) | |
if @user_session.save | |
flash[:notice] = "Login successful!" | |
redirect_back_or_default users_url | |
else | |
render :action => :new | |
end | |
end | |
def destroy | |
current_user_session.destroy | |
flash[:notice] = "Logout successful!" | |
redirect_back_or_default root_path | |
end | |
end | |
User.rb | |
acts_as_authentic do |c| | |
c.validates_length_of_password_field_options({:within => 6..40}) | |
c.crypto_provider = Authlogic::CryptoProviders::Sha512 | |
end | |
User Table Migration | |
class CreateUsers < ActiveRecord::Migration | |
def self.up | |
create_table :users do |t| | |
t.string :name | |
t.string :email | |
t.datetime :birthday | |
t.string :cellphone | |
t.integer :avatar_file_size | |
t.string :avatar_file_name | |
t.string :avatar_content_type | |
t.boolean :admin, :default => false | |
t.string :profile | |
t.string :persistence_token | |
t.string :single_access_token | |
t.string :perishable_token | |
t.integer :failed_login_count, :default => 0 | |
t.string :crypted_password | |
t.string :password_salt | |
t.timestamps | |
end | |
add_index :users, :email, :unique => true | |
end | |
def self.down | |
drop_table :users | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment