Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise registration confirmation

I have a User and an Admin role in my project. I created my authentication with Devise.

In my admin role I don't have any confirmation. In my User model I have the following:

devise :database_authenticatable, :confirmable, :recoverable,
       :rememberable, :trackable, :validatable, :timeoutable, :registerable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :username, :prename, :surname, :phone, :street, :number, :location,
                :password, :password_confirmation

My migration looks like:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.confirmable
      t.recoverable
      t.rememberable
      t.trackable
      t.timeoutable
      t.validateable
      t.string  :username
      t.string  :prename
      t.string  :surname
      t.string  :phone
      t.string  :street
      t.integer :number
      t.string  :location

      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :confirmation_token,   :unique => true
    add_index :users, :reset_password_token, :unique => true
    add_index :users, :username,             :unique => true
    add_index :users, :prename,              :unique => false
    add_index :users, :surname,              :unique => false
    add_index :users, :phone,                :unique => false
    add_index :users, :street,               :unique => false
    add_index :users, :number,               :unique => false
    add_index :users, :location,             :unique => false
  end

  def self.down
    drop_table :users
  end
end

In my routes.rb I added following statements:

map.devise_for :admins
map.devise_for :users, :path_names => { :sign_up => "register", :sign_in => "login" }

map.root :controller => "main"

After user registration I am redirected to the controller main with the flash notice, "You have signed up successfully," and I am logged in. But I don´t want to be logged in, because I have not confirmed my new user account yet.

If I open the console I see in the logs the confirmation mail text, but I am already logged in. I can´t explain why. Does anyone have an idea?

If I copy out the confirmation-token from the logs and confirm my account, I can log in, but if I don´t confirm, I also can log in.

like image 376
Matthias Avatar asked May 02 '10 17:05

Matthias


1 Answers

In config/initializers/devise.rb there is a line to set the amount of time a user has to confirm before they're locked out.

config.confirm_within = 2.days

If you set that to 0, you should get the desired outcome.

like image 170
guitsaru Avatar answered Sep 30 '22 16:09

guitsaru