acts_as_authenticated plugin in ROR

URL : http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated

script/plugin source http://svn.techno-weenie.net/projects/plugins

script/plugin install acts_as_authenticated

script/generate authenticated user account

rake db:migrate

script/generate authenticated_mailer user

script/generate migration add_column_activation

Inside Migration File:

add_column :users, :activation_code, :string, :limit => 40

add_column :users, :activated_at, :datetime

remove_column :users,:activation_code

remove_column :users, :activated_at

rake db:migrate

Account Controller:

def activate

@user = User.find_by_activation_code(params[:id])

if @user and @user.activate

self.current_user = @user

redirect_back_or_default(:controller => ‘/account’, :action => ‘index’)

flash[:notice] = “Your account has been activated.”

end

end

User_notifier.rb

def signup_notification(user)

setup_email(user)

@subject += ‘Please activate your new account’

@body[:url] = “http://localhost:3000/account/activate/#{user.activation_code}”

end

def activation(user)

setup_email(user)

@subject += ‘Your account has been activated!’

@body[:url] = “http://localhost:3000/account/index”

end

protected

def setup_email(user)

@recipients = “#{user.email}”

@from = “mailer@raveendran.org”

@subject = “Signup from Raveendran”

@sent_on = Time.now

@body[:user] = user

end

User.rb

before_create :make_activation_code

Before Protected:

def activate

@activated = true

update_attributes(:activated_at => Time.now.utc, :activation_code => nil)

end

def recently_activated?

@activated

end

After Protected:

def make_activation_code

self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )

end

Environment.rb

config.active_record.observers = :user_observer

After End (it means after do|config| loop):

ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.smtp_settings = {

:address => “mail.raveendran.com”,

:domain => “raveendran.com”,

:port => 25,

:authentication => :login,

:user_name => “mailer@raveendran.com”,

:password => “mailer”

}

ActionMailer::Base.perform_deliveries = true

ActionMailer::Base.raise_delivery_errors = true

ActionMailer::Base.default_charset = “utf-8”

Advertisements

6 thoughts on “acts_as_authenticated plugin in ROR

  1. Philip Rhoades says:

    I am unclear – I presume:

    config.active_record.observers = :user_observer

    goes at the top of:

    Environment.rb

    but where is:

    “After Method:”

    ?

    Thanks,

    Phil.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s