Skip to content

Instantly share code, notes, and snippets.

@dapi
Created December 19, 2010 18:20
Show Gist options
  • Save dapi/747552 to your computer and use it in GitHub Desktop.
Save dapi/747552 to your computer and use it in GitHub Desktop.
Use Devise authentication for Typus 3.0
class AddTypusAttributesToUsers < ActiveRecord::Migration
def self.up
add_column :users, :role, :string
add_column :users, :status, :boolean, :null=>false, :default=>true
User.find(1).update_attribute(:role,'admin')
end
def self.down
remove_column :users, :role
remove_column :users, :status
end
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :nick, :email, :password, :password_confirmation, :remember_me
validates_uniqueness_of :nick
#
# Typus adaptation
#
enable_as_typus_user
ROLE = Typus::Configuration.roles.keys.sort
LANGUAGE = Typus.locales
def self.authenticate(email, password)
resource = find_for_database_authentication({ :email=>email })
resource && resource.valid_password?( password ) ? resource : nil
end
# Typus redefines it
def password_required?
true
end
def first_name
email
end
def last_name
end
def preferences
''
end
end
@bradphelan
Copy link

Works well. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment