Hey all,

I'm using devise plugin for rails. When the user creates a new session,
in addition to devise authenticating the user, I want to check if the
user is enabled by checking the value of the enabled (a boolean) field
in the database. If the value is 0, I want to alert user that they
haven't been enabled, otherwise devise can do it's thing.

I have this:

    class SessionsController < Devise::RegistrationsController

  def new
    super
  end

  def create
  @user = User.authenticate(params[:user][:email])
  if !@user.enabled
    raise "You are not enabled"
  else
    super
  end
  end

  def update
    super
  end
end

I have this in User model:

class User < ActiveRecord::Base
  devise :invitable, :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

def self.authenticate(email)
u = find(:first, :conditions=>["email = ?", email])
return nil if u.nil?
return u
  end

 scope :enabled, :conditions => {:enabled => true}

And the routes:

 devise_for :users, :controllers => {
:registrations => "registrations",
 :sessions => "sessions" }

Unfortunately right now I get a nil object error for instance variable
@user, presumably because the params hash is not structured correctly. I
look at html form and notice the name attribute for email says
users[email] which is an array. So that's why I try to do it:
[:user][:email] but it doesn't work. Or if you know a better way of
doing all this, I'd greatly appreciate the knowledge.

Thanks for response.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to