username 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -2
- data/app/models/concerns/username/model.rb +5 -26
- data/app/models/concerns/username/model/devise.rb +24 -0
- data/lib/username.rb +0 -1
- data/lib/username/version.rb +1 -1
- metadata +3 -3
- data/lib/username/railtie.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8de930561c5caa99fd5429ef17fb6699a6090e07d27fdd190572d22bc2d4608
|
4
|
+
data.tar.gz: 4fab1cb6940a149fca8226ab472cd0a56ac4686d05a42d88bbdecf8d5141a7ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 793a84c0d5d2d0ecd794700940576bbfd5de43fcba5f01d01c66985df217218c14328503d3cd94422056eb696a6064998c6598e8fe34d3cea05b3d5620ceca43
|
7
|
+
data.tar.gz: cf50fc8fca114cc98651806e8d9b2b28596c500a914a3bc8a78569b0d736a5f9ba43344c4cd017b1c5d40d970818df000537f1194b0d464f838a5303f87b4871
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -55,7 +55,7 @@ You can add usernames to an ActiveRecord model:
|
|
55
55
|
|
56
56
|
```ruby
|
57
57
|
class User < ApplicationRecord
|
58
|
-
|
58
|
+
include Username::Model
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
@@ -81,7 +81,8 @@ If you are using Devise and you want to allow your users to sign in using either
|
|
81
81
|
|
82
82
|
```ruby
|
83
83
|
class User < ApplicationRecord
|
84
|
-
|
84
|
+
include Username::Model
|
85
|
+
include Username::Model::Devise
|
85
86
|
end
|
86
87
|
```
|
87
88
|
|
@@ -3,22 +3,12 @@ module Username
|
|
3
3
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
options = defaults.merge options
|
12
|
-
|
13
|
-
Username.configuration&.models << self.name
|
14
|
-
validate :username_validation
|
15
|
-
|
16
|
-
if options[:devise]
|
17
|
-
attr_accessor :login
|
18
|
-
extend Username::Model::DeviseMethods
|
19
|
-
end
|
20
|
-
end
|
6
|
+
included do
|
7
|
+
Username.configuration&.models << self.name
|
8
|
+
validate :username_validation
|
9
|
+
end
|
21
10
|
|
11
|
+
module ClassMethods
|
22
12
|
def username_valid? username
|
23
13
|
unless username.nil?
|
24
14
|
valid = true
|
@@ -37,17 +27,6 @@ module Username
|
|
37
27
|
end
|
38
28
|
end
|
39
29
|
|
40
|
-
module DeviseMethods
|
41
|
-
def find_for_database_authentication warden_conditions
|
42
|
-
conditions = warden_conditions.dup
|
43
|
-
if login = conditions.delete(:login)
|
44
|
-
where(conditions.to_h).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
|
45
|
-
elsif conditions.has_key?(:username) || conditions.has_key?(:email)
|
46
|
-
where(conditions.to_h).first
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
30
|
def username_available? username
|
52
31
|
unless username.nil?
|
53
32
|
valid = true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Username
|
2
|
+
module Model
|
3
|
+
module Devise
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
attr_accessor :login
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def find_for_database_authentication warden_conditions
|
13
|
+
conditions = warden_conditions.dup
|
14
|
+
if login = conditions.delete(:login)
|
15
|
+
where(conditions.to_h).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
|
16
|
+
elsif conditions.has_key?(:username) || conditions.has_key?(:email)
|
17
|
+
where(conditions.to_h).first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/username.rb
CHANGED
data/lib/username/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: username
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -76,12 +76,12 @@ files:
|
|
76
76
|
- LICENSE
|
77
77
|
- README.md
|
78
78
|
- app/models/concerns/username/model.rb
|
79
|
+
- app/models/concerns/username/model/devise.rb
|
79
80
|
- lib/generators/templates/initializer.rb
|
80
81
|
- lib/generators/username_generator.rb
|
81
82
|
- lib/username.rb
|
82
83
|
- lib/username/configuration.rb
|
83
84
|
- lib/username/engine.rb
|
84
|
-
- lib/username/railtie.rb
|
85
85
|
- lib/username/version.rb
|
86
86
|
homepage: https://github.com/jonhue/username
|
87
87
|
licenses:
|