views:

357

answers:

1

hello!

i have a user and an admin role in my project. i created my authentification with devise, really nice and goot tool for handling the authentification. in my admin role i don´t have any confirmation or something like that. it is really simple and doesn´t make problems. but in my user model i have following things:

model:

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

and few validations, but they aren´t relevant this time.

my migration looks like following one:

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

into my route.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"

and now my problem.. if I register a new user, I fill in all my data in the register form and submit it. After that I get 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 don´t have confirmed my new user account yet. If I open the console I see the last things in the logs and there I see the confirmation-mail and the text and all stuff, but I am already logged in... I can´t explain why, ... does somebody of you 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..

+1  A: 

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.

guitsaru
yep that was it! thanks.guitsaru i have annother question, maybe you can help me.i want to test few things in functional test and because of this, i have to log in an user. the login helper is good and works very fine, but i have problems with the confirmation. if i make sign_in User.make (i develope with machinist), the User will be make, but not confirmed. If I do it so: sign_in User.make(:confirmed_at => Time.now, :confirmation_sent_at => Time.now, ....) It doesn´t work. Do you have an idea what I could do?
Try using confirm! user = User.make user.confirm!
guitsaru
thanks man! that was it! saved me from googeling another half day :)