bpluser 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 372ac72e258bf4c58b6a5ebeeb9c69e692c907e5
4
- data.tar.gz: 61e4ceeb7e81b08b8d48ef40f97c29e220d8a30e
3
+ metadata.gz: f4ab974f23262f36d86356fc2d1d05e2ee46abba
4
+ data.tar.gz: fda00536fcbafb091456ea510679609db31b3f27
5
5
  SHA512:
6
- metadata.gz: 1daf8ccd6aee71dd38fe0b77793a850ea76d8a4cce52cf0a9040ec616aad201e134c319c5605a77b6db965e6dd45aa57e74415afc79df7f37a5bf291e59e3010
7
- data.tar.gz: 9b6d13cd3b7c4f77ed324b318a88cefe1d6fd61e11c874110add33e9a7dc652437b37178d8e1421240b4e186ff149722c34babce7db8c53eaf35da3f04ff297e
6
+ metadata.gz: c0666213d531153a61e6bdde7d79921aec1cdf6001a0f669f1fc3e2c8ab00d90fa7e7d2925a0801a21ac538549b6e9b585f0833ebc4a152eca1901d2fb904d5c
7
+ data.tar.gz: b25788d108f7718c6aa0fdb79480452fe97b4f0a8f86ec5ba3ebbe195914f60c388ee131322c471e9423f7adb5d40e5600c82f0463f4cf8c2f42caa854e4b551
@@ -2,14 +2,17 @@ module Bpluser::User
2
2
 
3
3
 
4
4
  def self.included(base)
5
+ #, :validatable
5
6
  base.send :devise, :database_authenticatable, :registerable,
6
- :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:ldap, :polaris, :facebook]
7
+ :recoverable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [:ldap, :polaris, :facebook]
7
8
  #base.send :attr_accessible, :provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid
8
9
  base.send :has_many, :user_institutions, :class_name => "Bpluser::UserInstitution"
9
10
  base.send :has_many, :folders, :dependent => :destroy, :class_name => "Bpluser::Folder"
10
11
  base.extend(ClassMethods)
11
12
  base.send :include, InstanceMethods
12
13
 
14
+ base.send :include, Bpluser::Validatable
15
+
13
16
  end
14
17
 
15
18
  module ClassMethods
@@ -0,0 +1,65 @@
1
+ #By default, devise requires an email to be unique. I want the email checks but need to remove the uniqueness...
2
+ module BplUser
3
+ # Validatable creates all needed validations for a user email and password.
4
+ # It's optional, given you may want to create the validations by yourself.
5
+ # Automatically validate if the email is present, unique and its format is
6
+ # valid. Also tests presence of password, confirmation and length.
7
+ #
8
+ # == Options
9
+ #
10
+ # Validatable adds the following options to devise_for:
11
+ #
12
+ # * +email_regexp+: the regular expression used to validate e-mails;
13
+ # * +password_length+: a range expressing password length. Defaults to 8..72.
14
+ #
15
+ module Validatable
16
+ # All validations used by this module.
17
+ VALIDATIONS = [:validates_presence_of, :validates_format_of,
18
+ :validates_confirmation_of, :validates_length_of].freeze
19
+
20
+ def self.required_fields(klass)
21
+ []
22
+ end
23
+
24
+ def self.included(base)
25
+ base.extend ClassMethods
26
+ assert_validations_api!(base)
27
+
28
+ base.class_eval do
29
+ validates_presence_of :email, if: :email_required?
30
+ #validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
31
+ validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
32
+
33
+ validates_presence_of :password, if: :password_required?
34
+ validates_confirmation_of :password, if: :password_required?
35
+ validates_length_of :password, within: password_length, allow_blank: true
36
+ end
37
+ end
38
+
39
+ def self.assert_validations_api!(base) #:nodoc:
40
+ unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
41
+
42
+ unless unavailable_validations.empty?
43
+ raise "Could not use :validatable module since #{base} does not respond " <<
44
+ "to the following methods: #{unavailable_validations.to_sentence}."
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ # Checks whether a password is needed or not. For validations only.
51
+ # Passwords are always required if it's a new record, or if the password
52
+ # or confirmation are being set somewhere.
53
+ def password_required?
54
+ !persisted? || !password.nil? || !password_confirmation.nil?
55
+ end
56
+
57
+ def email_required?
58
+ true
59
+ end
60
+
61
+ module ClassMethods
62
+ Devise::Models.config(self, :email_regexp, :password_length)
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module Bpluser
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bpluser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boston Public Library Web Services
@@ -137,6 +137,7 @@ files:
137
137
  - lib/bpluser.rb
138
138
  - lib/bpluser/engine.rb
139
139
  - lib/bpluser/routes.rb
140
+ - lib/bpluser/validatable.rb
140
141
  - lib/bpluser/version.rb
141
142
  - lib/generators/bpluser/bpluser_generator.rb
142
143
  - lib/generators/bpluser/templates/config/hydra-ldap.yml