Class: CASino::DeviseActiveRecordAuthenticator
- Inherits:
-
Object
- Object
- CASino::DeviseActiveRecordAuthenticator
- Defined in:
- lib/casino/devise_activerecord_authenticator/version.rb,
lib/casino/devise_activerecord_authenticator.rb
Defined Under Namespace
Classes: AuthDatabase
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Method Summary collapse
-
#initialize(options) ⇒ DeviseActiveRecordAuthenticator
constructor
A new instance of DeviseActiveRecordAuthenticator.
- #load_user_data(username) ⇒ Object
- #validate(username, password) ⇒ Object
Constructor Details
#initialize(options) ⇒ DeviseActiveRecordAuthenticator
Returns a new instance of DeviseActiveRecordAuthenticator.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/casino/devise_activerecord_authenticator.rb', line 13 def initialize() if !.respond_to?(:deep_symbolize_keys) raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." end @options = .deep_symbolize_keys raise ArgumentError, "Table name is missing" unless @options[:table] if @options[:model_name] model_name = @options[:model_name] else model_name = @options[:table] if @options[:connection][:database] model_name = "#{@options[:connection][:database].gsub(/[^a-zA-Z]+/, '')}_#{model_name}" end model_name = model_name.classify end model_class_name = "#{self.class.to_s}::#{model_name}" eval <<-END class #{model_class_name} < AuthDatabase self.table_name = "#{@options[:table]}" self.inheritance_column = :_type_disabled end END @model = model_class_name.constantize @model.establish_connection @options[:connection] end |
Instance Method Details
#load_user_data(username) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/casino/devise_activerecord_authenticator.rb', line 58 def load_user_data(username) user = @model.send("find_by_#{@options[:username_column]}!", username) user_data(user) rescue ActiveRecord::RecordNotFound nil end |
#validate(username, password) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/casino/devise_activerecord_authenticator.rb', line 40 def validate(username, password) #user = find_by_email!(username) user = @model.send("find_by_#{@options[:username_column]}!", username) password_from_database = user.send(@options[:password_column]) if valid_password?(password, password_from_database) && active_for_authentication?(user) user_data(user) else false end rescue ActiveRecord::RecordNotFound false end |