2012-02-16 21 views
9

Kullanıcı modeli ve sıfırdan oluşturulmuş bir kimlik doğrulama sistemi ile basit bir uygulamanız var. Şimdi bunun yerine Devise'yi kullanmaya çalışıyorum ve işe yaramıyor ve web geliştirmede yeni bir kişi olarak, kavramadığım bir şey var ve bunu nasıl ayıklayacağımı bilmiyorum.Devise: Oturum açma başarısız, nasıl hata ayıklanır?

Sorunum: Devise yüklenir ve çalışır, ancak her iki alan da doğru olsa bile oturum açma her zaman "geçersiz e-postayı veya şifreyi" döndürür.

Boş bir uygulama geliştirdim, Devise ekledim ve bu sorunla karşılaşmadım. Bu nedenle problem, muhtemelen, varolan bir Kullanıcı modeline Devise eklemeye çalıştığımdan kaynaklanmaktadır.

Bu konuyla ilgili bir konusu olan doc ve Devise wiki'sini okudum: here. kullanıcı modeli zaten bir e-posta alanı olduğundan ve geçişte yaptığım t.encrypted_password ile değiştirdiğinden, taşıma alanlarından veritabanı_authenticatable'ın kaldırılmasını söylüyor.

Şimdi, kullanıcı modelimde, ayrıldım: attr_accessible içinde database_authenticatable. Bunu kaldırırsam, session_path tanınmayan bir çok hata mesajım var, vb ... ama taşınmamış değil mi? Ayrıca:: encrypted_password benim modelimin herhangi bir yerinde görünmüyor, bu normal mi? ...

Gerçekten bir yeni kullanıcı sorusu olduğunu biliyorum, biraz kayboldum ve uygulamamı yeniden yazmam gerekip gerekmediğini bilmiyorum başlangıç ​​ya da kolay bir düzeltme varsa ... Ben de nasıl hata ayıklamak bilmiyorum, tüm günlüğünde gördüğüm kullanıcı başarıyla imzalanması gerektiğinde "yetkisiz" görünür ve aynı zamanda "authentication_token" değil bu size apaçık görünüyor eğer bir kez

yüzden

kaydoldum oluşturulan bu sign_in çalışırken aynı, ben aşağıda eklemek

... herhangi bir tavsiye duymak memnuniyet duyarım, kayboldum routes.rb, User.rb, schema.rb ve taşıma dosyası

routes.rb:

TapaG::Application.routes.draw do 

    devise_for :users 

    get "pages/home" 

    resources :users 
    resources :belongings 

    devise_scope :user do 
    get "sign_in", :to => "devise/sessions#new" 
    get "sign_out", :to => "devise/sessions#destroy" 
    get "sign_up", :to => "devise/registrations#new" 
    end 

    get "pages/more_details" 
    get "pages/infos_pratiques" 
    get "pages/contact_us" 

    #match 'Profil', :to => 'users#Profil' 
    match "more_details", :to => "pages#more_details" 
    match 'contact_us', :to => 'pages#contact_us' 
    match "infos_pratiques", :to => "pages#infos_pratiques" 
    match '/belongings/new', :to => 'belongings#new' 
    root :to => 'pages#home' 

göç:

class AddDeviseToUsers < ActiveRecord::Migration 
    def self.up 
    change_table(:users) do |t| 
     t.recoverable 
     t.rememberable 
     t.trackable 
     t.encrypted_password :null => false, :default => '', :limit => 128 

     # t.encryptable 
     # t.confirmable 
     # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both 
     # t.token_authenticatable 


     # Uncomment below if timestamps were not included in your original model. 
     # t.timestamps 
    end 

    add_index :users, :email,    :unique => true 
    add_index :users, :reset_password_token, :unique => true 
    # add_index :users, :confirmation_token, :unique => true 
    # add_index :users, :unlock_token,   :unique => true 
    # add_index :users, :authentication_token, :unique => true 
    end 

    def self.down 
    # By default, we don't want to make any assumption about how to roll back a migration when your 
    # model already existed. Please edit below which fields you would like to remove in this migration. 
    raise ActiveRecord::IrreversibleMigration 
    end 
end 

User.rb:

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :registerable, #:database_authenticatable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me 
    attr_accessor :password 
    attr_accessible :name, :number_of_positive_reco, :confidence_percent, :avatar 

schema.rb:

create_table "users", :force => true do |t| 
    t.string "name" 
    t.string "email" 
    t.integer "number_of_positive_reco" 
    t.float "confidence_percent" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "encrypted_password" 
    t.string "salt" 
    t.string "avatar_file_name" 
    t.string "avatar_content_type" 
    t.integer "avatar_file_size" 
    t.datetime "avatar_updated_at" 
    t.boolean "admin",     :default => false 
    t.string "reset_password_token" 
    t.datetime "reset_password_sent_at" 
    t.datetime "remember_created_at" 
    t.integer "sign_in_count",   :default => 0 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.string "current_sign_in_ip" 
    t.string "last_sign_in_ip" 
    end 

    add_index "users", ["email"], :name => "index_users_on_email", :unique => true 
    add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true 

+0

Aslında, Devise herhangi bir şifre şifrelemesi yapmaz (şifreli_password ve tuz her ikisi de NIL'de oturum açtıktan sonra ayarlanır) ... – citraL

+0

Ahhh, şimdi anladım, bir açıklama için teşekkürler :) – socjopata

cevap

9

Cevap: attr_accessor: password ... 'ı kaldırın. Aksi takdirde, Devise şifreleyemez!

+2

Tam olarak aynı problemi yaşadım, sadece “attr_accessor: password” satırına sahip değildim. Benim durumumda, bir 'before_save: encrypt_password' vardı çünkü bu yüzden soruna neden oldu, bu yüzden şifreyi iki kez şifreliyordum. Herkesin aynı sorunla karşılaşması durumunda buradan ayrılıyorum – Ramses

1

konsolunda size bu şifre-encryptable bir yöntemdir

u = User.last 
u.valid_password? 

kullanabilir ve şifre vermek kullanıcı için geçerli olup olmadığını söyleyecektir.

İlgili konular