First, I need help about login_generator, I am a programmer of rails applications. I have some examples for this ruby gem.
I share this with us.
1.- First It's necessary to install login_generator gem
sudo gem install login_generator
2.- you need to create a model
./script/generate model user
this command create a file called user.rb that contains this:
#-----------------------user.rb in a models folder ----------------------
require 'digest/sha1'
# this model expects a certain database layout and its based on the name/login pattern.
class User < ActiveRecord::Base
def self.authenticate(login, pass)
find_first(["login = ? AND password = ?", login, sha1(pass)])
end
def change_password(pass)
update_attribute "password", self.class.sha1(pass)
end
protected
def self.sha1(pass)
Digest::SHA1.hexdigest("change-me--#{pass}--")
end
before_create :crypt_password
def crypt_password
write_attribute("password", self.class.sha1(password))
end
validates_length_of :login, :within => 3..40
validates_length_of :password, :within => 5..40
validates_presence_of :login, :password, :password_confirmation
validates_uniqueness_of :login, :on => :create
validates_confirmation_of :password, :on => :create
end
3.- then, rails by default create a migration file that should have the follow:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :login, :string, :default => nil
t.column :password, :string, :default => nil
end
User.create(:login => 'administrador',
:password => 'password',
:password_confirmation => 'password')
end
def self.down
drop_table :users
end
end
4.- It's necesarry have a file login_system.rb in a lib folder of your rails project, the most easy way to apply login_generator system it's to eject the command
./script/generate login_generator
5.- comments with Carlos Augusto Monterrosa Lopez
http://cmonterrosatechnotes.blogspot.com