Wiele aplikacji Rails 2.3 używa Restful Authentication, ale ta wtyczka wydaje się mieć pewne problemy z Rails 3. Podczas aktualizacji do Rails 3 używałem Devise. Czy istnieje sposób na płynne przejście z Restful Authentication do Devise? Czy ktoś przeprowadził migrację, która pokazuje, jak zaktualizować model użytkownika?Migracja z Restful Authentication do Devise
Odpowiedz
Zaktualizowałem moją aplikację z Restful Authentication do Devise. Oto moja migracja:
class AlterUsersForDevise < ActiveRecord::Migration
def self.up
remove_column :users, :name
change_column :users, :email, :string, :default => "", :null => false, :limit => 128
rename_column :users, :crypted_password, :encrypted_password
change_column :users, :encrypted_password, :string, :limit => 128, :default => "", :null => false
rename_column :users, :salt, :password_salt
change_column :users, :password_salt, :string, :default => "", :null => false, :limit => 255
add_column :users, :reset_password_token, :string
change_column :users, :remember_token, :string, :limit => 255
rename_column :users, :remember_token_expires_at, :remember_created_at
add_column :users, :sign_in_count, :integer, :default => 0
add_column :users, :current_sign_in_at, :datetime
add_column :users, :last_sign_in_at, :datetime
add_column :users, :current_sign_in_ip, :string
add_column :users, :last_sign_in_ip, :string
rename_column :users, :activation_code, :confirmation_token
change_column :users, :confirmation_token, :string, :limit => 255
rename_column :users, :activated_at, :confirmed_at
add_column :users, :confirmation_sent_at, :datetime
end
def self.down
add_column :users, :name, :string, :limit => 100, :default => ""
rename_column :users, :encrypted_password, :crypted_password
change_column :users, :crypted_password, :string, :limit => 40
rename_column :users, :password_salt, :salt
change_column :users, :salt, :string, :limit => 40
remove_column :users, :reset_password_token
change_column :users, :remember_token, :string, :limit => 40
rename_column :users, :remember_created_at, :remember_token_expires_at
remove_column :users, :sign_in_count
remove_column :users, :current_sign_in_at
remove_column :users, :last_sign_in_at
remove_column :users, :current_sign_in_ip
remove_column :users, :last_sign_in_ip
rename_column :users, :confirmation_token, :activation_code
change_column :users, :confirmation_token, :string, :limit => 40
rename_column :users, :confirmed_at, :activated_at
remove_column :users, :confirmation_sent_at
end
end
Moja aplikacja nie jest na razie z nami. Używam szyfrowania hasła od Devise zamiast tego z Restful Authorization. Jeśli aplikacja jest już aktywna i masz aktywnych użytkowników, powinieneś skonfigurować program Devise tak, aby używał SHA1 z Restful Authentication do de- i odszyfrowywania haseł. W przeciwnym razie wszyscy użytkownicy muszą poprosić o nowe hasło.
Możesz to skonfigurować w inicjalizatorze devise.
nadzieję, że pomoże ...
miałem problemy z szyfrowaniem haseł (ale znalazłem odpowiedź, zobacz moje inne odpowiedzi). Stara aplikacja korzystała ze starej wersji Restful Authentication. Został obsługi szyfrowania haseł tak:
# before filter
def encrypt_password
return if password.blank?
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
self.crypted_password = encrypt(password)
end
# Encrypts some data with the salt.
def self.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
# Encrypts the password with the user salt
def encrypt(password)
self.class.encrypt(password, salt)
end
Jeżeli ustawić config.encryptor
do :restful_authentication_sha1
nie działa Devise jest.
Zobacz moje rozwiązanie w innej odpowiedzi. –
Oto jak przezwyciężyć problem hasło:
Musisz zrobić zwyczaj szyfrującego tak:
# /config/initializers/devise_encryptor.rb
require "digest/sha1"
module Devise
module Encryptors
class OldRestfulAuthentication < Base
def self.digest(password, stretches, salt, pepper)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
end
end
end
a następnie wybierz go devise.rb
tak:
config.encryptor = :old_restful_authentication
Że powinienem to zrobić!
Tutaj jest dobrym przewodnikiem w sprawie migracji z restful_authentication opracowanie
https://github.com/plataformatec/devise/wiki/How-To:-Migrate-from-restful_authentication-to-Devise
Powód edycji: przed powiązanie wziął ludzi do pustej strony.
poprawiono link, który poprzednio prowadził do pustej strony z napisem "Utwórz nową stronę". – Jay
W moim przypadku to działa (analized authentication.rb i by_password.rb w stary klejnot restful_authentication):
config/inicjalizatory/devise.rb dodać to:
config.encryptor = :restful_authentication
config.stretches = 10 #REST_AUTH_DIGEST_STRETCHES frome Restful Authentication file config/initializers/site_key.rb
config.pepper = 'mashauronilavrechkumyachik' #REST_AUTH_SITE_KEY frome Restful Authentication file config/initializers/site_key.rb
aplikacja/models/user.rb dodaj: zaszyfrowane
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:encryptable, :omniauthable, :authentication_keys => [:login]
config/inicjalizatory/devise_encryptor.rb stworzyć z tym w ten sposób:
# -*- encoding : utf-8 -*-
require "digest/sha1"
module Devise
module Encryptable
module Encryptors
class RestfulAuthentication < Base
def self.digest(password, stretches, salt, pepper)
digest = pepper
stretches.times do
digest = secure_digest(digest, salt, password, pepper)
end
digest
end
def self.secure_digest(*args)
Digest::SHA1.hexdigest(args.flatten.join('--'))
end
def self.encrypt_password
return if password.blank?
self.password_salt = make_token if new_record?
self.encrypted_password = encrypt(password)
end
def self.make_token
secure_digest(Time.now, (1..10).map{ rand.to_s })
end
def self.encrypt(password)
self.password_digest(password, stretches, salt, pepper)
end
end
end
end
end
- 1. RESTful-Authentication lub Authlogic?
- 2. cancan skip_authorization_check for Devise authentication
- 3. Rails 3 z Devise for Authentication - Jak ręcznie utworzyć użytkownika?
- 4. Błąd kodowania podczas korzystania z Devise ldap authentication
- 5. Migracja z Jam do CMake
- 6. Migracja z NetBeans do Eclipse
- 7. Migracja z MySQL do Crate
- 8. Migracja z JSP do Freemarker
- 9. Migracja z WinForm do WPF
- 10. Migracja z DataSets do EntityFramework
- 11. migracja do C# z Java
- 12. Migracja z MySQL do PostgreSQL
- 13. migracja ze starego hasła do ruterów wymyślić
- 14. Migracja do WKWebView
- 15. Migracja do Django 1.4
- 16. Migracja PHP4 do PHP5
- 17. Migracja do jquery 1.4
- 18. Migracja Microsoft.Build.BuildEngine.Engine do Microsoft.Build.Evaluation.ProjectCollection
- 19. IIS Binding z Windows Authentication
- 20. Windows Authentication z ASP.NET MVC
- 21. Migracja z Jetty 6 do Jetty 8
- 22. Migracja z SVN do Perforce - porady? Doświadczenie?
- 23. Migracja biletów sourceforge do problemów z GitHub
- 24. Migracja z ExtJS 3.0 do 4.0
- 25. Migracja z Subversion 1.4 do 1.6
- 26. Migracja z mongodb do bazy Firebase
- 27. Migracja z Oracle do Sql Server
- 28. Migracja z MySQL do MariaDB i viceversa
- 29. Migracja z Hit/Odsłon do TopDocs/TopDocCollector
- 30. Migracja z ngRoute do routera ui
Dzięki, to działa.Miałem jeden dodatkowy problem, który omówiłem w 2 odpowiedziach poniżej. –