Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

support mongoid aswell #77

Open
wants to merge 1 commit into from

1 participant

@sbounmy

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2014
  1. @sbounmy

    support mongoid aswell

    sbounmy authored
This page is out of date. Refresh to see the latest.
View
10 lib/devise_security_extension.rb
@@ -1,5 +1,5 @@
#require 'rails/all'
-require 'active_record/connection_adapters/abstract/schema_definitions'
+require 'active_record/connection_adapters/abstract/schema_definitions' if defined?(ActiveRecord)
require 'active_support/core_ext/integer'
require 'active_support/ordered_hash'
require 'active_support/concern'
@@ -80,6 +80,8 @@ module Controllers
end
end
+orm = defined?(Mongoid) ? 'mongoid' : 'active_record'
+
# modules
Devise.add_module :password_expirable, :controller => :password_expirable, :model => 'devise_security_extension/models/password_expirable', :route => :password_expired
Devise.add_module :secure_validatable, :model => 'devise_security_extension/models/secure_validatable'
@@ -91,6 +93,6 @@ module Controllers
# requires
require 'devise_security_extension/routes'
require 'devise_security_extension/rails'
-require 'devise_security_extension/orm/active_record'
-require 'devise_security_extension/models/old_password'
-require 'devise_security_extension/models/security_question'
+require 'devise_security_extension/orm/active_record' if defined?(ActiveRecord)
+require "devise_security_extension/models/#{orm}/old_password"
+require "devise_security_extension/models/#{orm}/security_question"
View
3  lib/devise_security_extension/models/active_record/old_password.rb
@@ -0,0 +1,3 @@
+class OldPassword < ActiveRecord::Base
+ belongs_to :password_archivable, :polymorphic => true
+end
View
3  ...ity_extension/models/security_question.rb → ...models/active_record/security_question.rb
@@ -1,3 +1,2 @@
class SecurityQuestion < ActiveRecord::Base
-
-end
+end
View
12 lib/devise_security_extension/models/mongoid/old_password.rb
@@ -0,0 +1,12 @@
+class OldPassword
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :encrypted_password, :type => String
+ field :password_salt, :type => String
+ field :password_archivable_id, :type => Integer
+ field :password_archivable_type, :type => String
+
+ belongs_to :password_archivable, :polymorphic => true
+ attr_accessible :encrypted_password
+end
View
7 lib/devise_security_extension/models/mongoid/security_question.rb
@@ -0,0 +1,7 @@
+class SecurityQuestion
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :locale, type: String
+ field :name, type: String
+end
View
3  lib/devise_security_extension/models/old_password.rb
@@ -1,3 +0,0 @@
-class OldPassword < ActiveRecord::Base
- belongs_to :password_archivable, :polymorphic => true
-end
View
6 lib/devise_security_extension/models/secure_validatable.rb
@@ -36,7 +36,9 @@ def self.included(base)
end
# extra validations
- validates :email, :email => email_validation if email_validation # use rails_email_validator or similar
+ if email_validation # use rails_email_validator or similar
+ validates :email, :email => email_validation
+ end
validates :password, :format => { :with => password_regex, :message => :password_format }, :if => :password_required?
# don't allow use same password
@@ -76,7 +78,7 @@ module ClassMethods
private
def has_uniqueness_validation_of_login?
validators.any? do |validator|
- validator.kind_of?(ActiveRecord::Validations::UniquenessValidator) &&
+ validator.class.name =~ /::Validations::UniquenessValidator$/) &&
validator.attributes.include?(login_attribute)
end
end
Something went wrong with that request. Please try again.