challah 1.1.1 → 1.2.0.rc
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 +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +3 -3
- data/app/models/authorization.rb +2 -2
- data/app/models/user.rb +2 -2
- data/lib/challah.rb +60 -53
- data/lib/challah/active_record_extensions.rb +23 -0
- data/lib/challah/{authorization.rb → concerns/authorizeable.rb} +14 -19
- data/lib/challah/concerns/user/attributeable.rb +73 -0
- data/lib/challah/{user/authentication.rb → concerns/user/authenticateable.rb} +2 -2
- data/lib/challah/concerns/user/authorizable.rb +32 -0
- data/lib/challah/concerns/user/findable.rb +45 -0
- data/lib/challah/{user/password.rb → concerns/user/passwordable.rb} +2 -2
- data/lib/challah/{user/providers.rb → concerns/user/provideable.rb} +46 -6
- data/lib/challah/concerns/user/validateable.rb +21 -0
- data/lib/challah/concerns/userable.rb +20 -0
- data/lib/challah/engine.rb +1 -2
- data/lib/challah/test.rb +52 -32
- data/lib/challah/version.rb +1 -1
- metadata +14 -76
- data/lib/challah/user.rb +0 -128
- data/lib/challah/user/attributes.rb +0 -28
- data/lib/challah/user/finders.rb +0 -31
- data/lib/challah/user/reflector.rb +0 -15
- data/test/controllers/controller_test.rb +0 -34
- data/test/controllers/restrictions_controller_test.rb +0 -95
- data/test/controllers/sessions_controller_test.rb +0 -42
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/controllers/restrictions_controller.rb +0 -25
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/user.rb +0 -15
- data/test/dummy/app/models/widget.rb +0 -3
- data/test/dummy/app/views/bakery/templates/layouts/sample.erb +0 -1
- data/test/dummy/app/views/bakery/templates/partials/sample.html.haml +0 -1
- data/test/dummy/app/views/bakery/templates/themes/sample.haml +0 -1
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -24
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -30
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -29
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/environments/test.rb +0 -36
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/i18n.rb +0 -1
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -12
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -5
- data/test/dummy/db/migrate/20140114212939_create_widgets.rb +0 -32
- data/test/dummy/db/migrate/20140307205735_create_users.challah_engine.rb +0 -34
- data/test/dummy/db/migrate/20140307205736_create_authorizations.challah_engine.rb +0 -21
- data/test/dummy/db/schema.rb +0 -81
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +0 -11547
- data/test/dummy/public/404.html +0 -58
- data/test/dummy/public/422.html +0 -58
- data/test/dummy/public/500.html +0 -57
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/factories.rb +0 -8
- data/test/models/authorization_test.rb +0 -20
- data/test/models/user_test.rb +0 -345
- data/test/services/audit_test.rb +0 -107
- data/test/services/cookie_store_test.rb +0 -97
- data/test/services/encrypter_test.rb +0 -73
- data/test/services/plugins_test.rb +0 -65
- data/test/services/random_test.rb +0 -22
- data/test/services/routes_test.rb +0 -11
- data/test/services/session_test.rb +0 -197
- data/test/services/signup_test.rb +0 -122
- data/test/services/simple_cookie_store_test.rb +0 -122
- data/test/support/stubs.rb +0 -88
- data/test/test_helper.rb +0 -47
@@ -0,0 +1,21 @@
|
|
1
|
+
module Challah
|
2
|
+
module UserValidateable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
email_validation_hash = {
|
7
|
+
presence: true,
|
8
|
+
uniqueness: true
|
9
|
+
}
|
10
|
+
|
11
|
+
email_validator_key = Challah.options[:email_validator].to_s.underscore
|
12
|
+
email_validation_hash[email_validator_key] = true
|
13
|
+
|
14
|
+
validates :email, email_validation_hash
|
15
|
+
validates :first_name, presence: true
|
16
|
+
validates :last_name, presence: true
|
17
|
+
|
18
|
+
validates_with Challah.options[:password_validator], force: false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Challah
|
2
|
+
module Userable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
include UserAttributeable
|
6
|
+
include UserAuthenticateable
|
7
|
+
include UserAuthorizable
|
8
|
+
include UserFindable
|
9
|
+
include UserPasswordable
|
10
|
+
include UserProvideable
|
11
|
+
|
12
|
+
unless Challah.options[:skip_user_validations]
|
13
|
+
include UserValidateable
|
14
|
+
end
|
15
|
+
|
16
|
+
included do
|
17
|
+
Challah.include_user_plugins!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/challah/engine.rb
CHANGED
@@ -45,8 +45,7 @@ module Challah
|
|
45
45
|
if defined?(ActiveRecord)
|
46
46
|
Challah.options[:logger] = ActiveRecord::Base.logger
|
47
47
|
|
48
|
-
ActiveRecord::Base.send(:
|
49
|
-
ActiveRecord::Base.send(:extend, Challah::Authorization)
|
48
|
+
ActiveRecord::Base.send(:include, Challah::ActiveRecordExtensions)
|
50
49
|
ActiveRecord::Base.send(:include, Challah::Audit)
|
51
50
|
|
52
51
|
# Load any ActiveRecord/Challah plugins
|
data/lib/challah/test.rb
CHANGED
@@ -1,45 +1,65 @@
|
|
1
|
-
|
2
|
-
# data
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Challah
|
2
|
+
# Used to persist session data in test mode instead of using cookies. Stores the session
|
3
|
+
# data lazily in a global var, accessible across the testing environment.
|
4
|
+
class TestSessionStore
|
5
|
+
def initialize(session = nil)
|
6
|
+
@session = session
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def destroy
|
10
|
+
$challah_test_session = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def read
|
14
|
+
if $challah_test_session
|
15
|
+
return $challah_test_session.to_s.split(":")
|
16
|
+
end
|
11
17
|
|
12
|
-
|
13
|
-
if $challah_test_session
|
14
|
-
return $challah_test_session.to_s.split(':')
|
18
|
+
nil
|
15
19
|
end
|
16
20
|
|
17
|
-
|
21
|
+
def save(token, user_id)
|
22
|
+
$challah_test_session = "#{ token }:#{ user_id }"
|
23
|
+
true
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
module Testing
|
28
|
+
|
29
|
+
# Sign the given user instance in
|
30
|
+
def signin_as(user)
|
31
|
+
Session.create!(user, nil, nil, user.class)
|
32
|
+
end
|
33
|
+
alias_method :login_as, :signin_as
|
34
|
+
|
35
|
+
# Sign the given user instance out
|
36
|
+
def signout
|
37
|
+
Session.destroy
|
38
|
+
end
|
39
|
+
alias_method :logout, :signout
|
40
|
+
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
26
|
-
Challah.options[:storage_class] = TestSessionStore
|
27
|
-
|
28
44
|
class ActiveSupport::TestCase
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
alias_method :login_as, :signin_as
|
45
|
+
include Challah::Testing
|
46
|
+
setup :signout
|
47
|
+
end
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
if defined?(RSpec)
|
50
|
+
RSpec.configure do |config|
|
51
|
+
|
52
|
+
config.before(:all) do
|
53
|
+
# make sure challah is using test session in test mode
|
54
|
+
Challah.options[:storage_class] = Challah::TestSessionStore
|
55
|
+
end
|
56
|
+
|
57
|
+
config.before(:each) do
|
58
|
+
# Reset any challah user sessions for each test.
|
59
|
+
$challah_test_session = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
config.include Challah::Testing, type: :controller
|
40
63
|
|
41
|
-
setup do
|
42
|
-
# Reset any challah user sessions for each test.
|
43
|
-
$challah_test_session = nil
|
44
64
|
end
|
45
|
-
end
|
65
|
+
end
|
data/lib/challah/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: challah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Tornow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -81,75 +81,20 @@ files:
|
|
81
81
|
- config/locales/en.yml
|
82
82
|
- db/migrate/20120127150433_create_users.rb
|
83
83
|
- db/migrate/20121116210759_create_authorizations.rb
|
84
|
-
-
|
85
|
-
- test/controllers/restrictions_controller_test.rb
|
86
|
-
- test/controllers/sessions_controller_test.rb
|
87
|
-
- test/dummy/app/assets/javascripts/application.js
|
88
|
-
- test/dummy/app/assets/stylesheets/application.css
|
89
|
-
- test/dummy/app/controllers/application_controller.rb
|
90
|
-
- test/dummy/app/controllers/restrictions_controller.rb
|
91
|
-
- test/dummy/app/helpers/application_helper.rb
|
92
|
-
- test/dummy/app/models/user.rb
|
93
|
-
- test/dummy/app/models/widget.rb
|
94
|
-
- test/dummy/app/views/bakery/templates/layouts/sample.erb
|
95
|
-
- test/dummy/app/views/bakery/templates/partials/sample.html.haml
|
96
|
-
- test/dummy/app/views/bakery/templates/themes/sample.haml
|
97
|
-
- test/dummy/app/views/layouts/application.html.erb
|
98
|
-
- test/dummy/config/application.rb
|
99
|
-
- test/dummy/config/boot.rb
|
100
|
-
- test/dummy/config/database.yml
|
101
|
-
- test/dummy/config/environment.rb
|
102
|
-
- test/dummy/config/environments/development.rb
|
103
|
-
- test/dummy/config/environments/production.rb
|
104
|
-
- test/dummy/config/environments/test.rb
|
105
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
106
|
-
- test/dummy/config/initializers/filter_parameter_logging.rb
|
107
|
-
- test/dummy/config/initializers/i18n.rb
|
108
|
-
- test/dummy/config/initializers/inflections.rb
|
109
|
-
- test/dummy/config/initializers/mime_types.rb
|
110
|
-
- test/dummy/config/initializers/secret_token.rb
|
111
|
-
- test/dummy/config/initializers/session_store.rb
|
112
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
113
|
-
- test/dummy/config/locales/en.yml
|
114
|
-
- test/dummy/config/routes.rb
|
115
|
-
- test/dummy/config.ru
|
116
|
-
- test/dummy/db/migrate/20140114212939_create_widgets.rb
|
117
|
-
- test/dummy/db/migrate/20140307205735_create_users.challah_engine.rb
|
118
|
-
- test/dummy/db/migrate/20140307205736_create_authorizations.challah_engine.rb
|
119
|
-
- test/dummy/db/schema.rb
|
120
|
-
- test/dummy/db/test.sqlite3
|
121
|
-
- test/dummy/log/test.log
|
122
|
-
- test/dummy/public/404.html
|
123
|
-
- test/dummy/public/422.html
|
124
|
-
- test/dummy/public/500.html
|
125
|
-
- test/dummy/public/favicon.ico
|
126
|
-
- test/dummy/Rakefile
|
127
|
-
- test/dummy/README.rdoc
|
128
|
-
- test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
|
129
|
-
- test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
|
130
|
-
- test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
|
131
|
-
- test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
|
132
|
-
- test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
|
133
|
-
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
134
|
-
- test/factories.rb
|
135
|
-
- test/models/authorization_test.rb
|
136
|
-
- test/models/user_test.rb
|
137
|
-
- test/services/audit_test.rb
|
138
|
-
- test/services/cookie_store_test.rb
|
139
|
-
- test/services/encrypter_test.rb
|
140
|
-
- test/services/plugins_test.rb
|
141
|
-
- test/services/random_test.rb
|
142
|
-
- test/services/routes_test.rb
|
143
|
-
- test/services/session_test.rb
|
144
|
-
- test/services/signup_test.rb
|
145
|
-
- test/services/simple_cookie_store_test.rb
|
146
|
-
- test/support/stubs.rb
|
147
|
-
- test/test_helper.rb
|
84
|
+
- lib/challah/active_record_extensions.rb
|
148
85
|
- lib/challah/audit.rb
|
149
86
|
- lib/challah/authenticators/api_key.rb
|
150
87
|
- lib/challah/authenticators/password.rb
|
151
88
|
- lib/challah/authenticators.rb
|
152
|
-
- lib/challah/
|
89
|
+
- lib/challah/concerns/authorizeable.rb
|
90
|
+
- lib/challah/concerns/user/attributeable.rb
|
91
|
+
- lib/challah/concerns/user/authenticateable.rb
|
92
|
+
- lib/challah/concerns/user/authorizable.rb
|
93
|
+
- lib/challah/concerns/user/findable.rb
|
94
|
+
- lib/challah/concerns/user/passwordable.rb
|
95
|
+
- lib/challah/concerns/user/provideable.rb
|
96
|
+
- lib/challah/concerns/user/validateable.rb
|
97
|
+
- lib/challah/concerns/userable.rb
|
153
98
|
- lib/challah/controller.rb
|
154
99
|
- lib/challah/cookie_store.rb
|
155
100
|
- lib/challah/encrypter.rb
|
@@ -166,13 +111,6 @@ files:
|
|
166
111
|
- lib/challah/techniques/password_technique.rb
|
167
112
|
- lib/challah/techniques.rb
|
168
113
|
- lib/challah/test.rb
|
169
|
-
- lib/challah/user/attributes.rb
|
170
|
-
- lib/challah/user/authentication.rb
|
171
|
-
- lib/challah/user/finders.rb
|
172
|
-
- lib/challah/user/password.rb
|
173
|
-
- lib/challah/user/providers.rb
|
174
|
-
- lib/challah/user/reflector.rb
|
175
|
-
- lib/challah/user.rb
|
176
114
|
- lib/challah/validators/email_validator.rb
|
177
115
|
- lib/challah/validators/password_validator.rb
|
178
116
|
- lib/challah/version.rb
|
@@ -197,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
135
|
version: 1.9.2
|
198
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
137
|
requirements:
|
200
|
-
- - '
|
138
|
+
- - '>'
|
201
139
|
- !ruby/object:Gem::Version
|
202
|
-
version:
|
140
|
+
version: 1.3.1
|
203
141
|
requirements: []
|
204
142
|
rubyforge_project:
|
205
143
|
rubygems_version: 2.0.3
|
data/lib/challah/user.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'challah/user/attributes'
|
2
|
-
require 'challah/user/authentication'
|
3
|
-
require 'challah/user/finders'
|
4
|
-
require 'challah/user/password'
|
5
|
-
require 'challah/user/providers'
|
6
|
-
require 'challah/user/reflector'
|
7
|
-
|
8
|
-
module Challah
|
9
|
-
module User
|
10
|
-
def challah_user
|
11
|
-
unless included_modules.include?(InstanceMethods)
|
12
|
-
include Attributes
|
13
|
-
include Authentication
|
14
|
-
include InstanceMethods
|
15
|
-
include Providers
|
16
|
-
include Password
|
17
|
-
extend Finders
|
18
|
-
extend Reflector
|
19
|
-
end
|
20
|
-
|
21
|
-
email_validation_hash = {
|
22
|
-
presence: true,
|
23
|
-
uniqueness: true
|
24
|
-
}
|
25
|
-
|
26
|
-
email_validator_key = Challah.options[:email_validator].to_s.underscore
|
27
|
-
email_validation_hash[email_validator_key] = true
|
28
|
-
|
29
|
-
class_eval do
|
30
|
-
# Attributes
|
31
|
-
################################################################
|
32
|
-
|
33
|
-
attr_reader :password, :password_confirmation, :password_updated
|
34
|
-
|
35
|
-
# Validation
|
36
|
-
################################################################
|
37
|
-
|
38
|
-
unless Challah.options[:skip_user_validations]
|
39
|
-
validates :email, email_validation_hash
|
40
|
-
validates :first_name, presence: true
|
41
|
-
validates :last_name, presence: true
|
42
|
-
|
43
|
-
validates_with Challah.options[:password_validator], force: false
|
44
|
-
end
|
45
|
-
|
46
|
-
# Scoped Finders
|
47
|
-
################################################################
|
48
|
-
|
49
|
-
scope :active, -> { where(active: true) }
|
50
|
-
scope :inactive, -> { where(active: false) }
|
51
|
-
|
52
|
-
# Callbacks
|
53
|
-
################################################################
|
54
|
-
|
55
|
-
before_save :check_tokens
|
56
|
-
after_save :save_updated_providers
|
57
|
-
after_save :clear_cache
|
58
|
-
before_destroy :clear_authorizations
|
59
|
-
end
|
60
|
-
|
61
|
-
Challah.include_user_plugins!
|
62
|
-
end
|
63
|
-
|
64
|
-
# Instance methods to be included once challah_user is set up.
|
65
|
-
module InstanceMethods
|
66
|
-
def method_missing(method, *args)
|
67
|
-
method_name = method.to_s
|
68
|
-
|
69
|
-
if method_name =~ /^([a-z]*)_provider\?$/
|
70
|
-
return provider?($1)
|
71
|
-
elsif method_name =~ /^([a-z]*)_provider$/
|
72
|
-
return provider($1)
|
73
|
-
end
|
74
|
-
|
75
|
-
super
|
76
|
-
end
|
77
|
-
|
78
|
-
protected
|
79
|
-
# If password or username was changed, update the authorization record
|
80
|
-
def save_updated_providers
|
81
|
-
# Save password provider
|
82
|
-
if @password_updated or @username_updated
|
83
|
-
Challah.providers[:password].save(self)
|
84
|
-
@password_updated = false
|
85
|
-
@username_updated = false
|
86
|
-
@password = nil
|
87
|
-
end
|
88
|
-
|
89
|
-
# Save any other providers
|
90
|
-
Challah.custom_providers.each do |name, klass|
|
91
|
-
custom_provider_attributes = provider_attributes[name]
|
92
|
-
|
93
|
-
if custom_provider_attributes.respond_to?(:fetch)
|
94
|
-
if klass.valid?(self)
|
95
|
-
klass.save(self)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# Before a record is saved, make sure all tokens are set properly
|
102
|
-
def check_tokens
|
103
|
-
if self.persistence_token.to_s.blank?
|
104
|
-
self.persistence_token = Random.token(125)
|
105
|
-
end
|
106
|
-
|
107
|
-
if self.api_key.to_s.blank?
|
108
|
-
self.api_key = Random.token(50)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Store a hashed email if the column exists
|
112
|
-
if respond_to?("email_hash=")
|
113
|
-
if email_changed?
|
114
|
-
self.email_hash = Encrypter.md5(email.to_s.downcase.strip)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def clear_authorizations
|
120
|
-
authorizations.destroy_all
|
121
|
-
end
|
122
|
-
|
123
|
-
def clear_cache
|
124
|
-
@providers = nil
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Challah::User
|
2
|
-
|
3
|
-
module Attributes
|
4
|
-
# Returns true if this user is active, and should be able to log in. If
|
5
|
-
# the active column is false, the user will not be able to authenticate
|
6
|
-
def active?
|
7
|
-
!!self.active
|
8
|
-
end
|
9
|
-
|
10
|
-
# First name and last name together
|
11
|
-
def name
|
12
|
-
"#{first_name} #{last_name}".strip
|
13
|
-
end
|
14
|
-
|
15
|
-
# shortened name, just includes the first name and last initial
|
16
|
-
def small_name
|
17
|
-
"#{first_name.to_s.titleize} #{last_name.to_s.first.upcase}."
|
18
|
-
end
|
19
|
-
|
20
|
-
# Is this user valid and ready for a user session?
|
21
|
-
#
|
22
|
-
# Override this method if you need to check for a particular configuration on each page request.
|
23
|
-
def valid_session?
|
24
|
-
self.active?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/lib/challah/user/finders.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Challah::User
|
2
|
-
|
3
|
-
module Finders
|
4
|
-
# Find a user instance by username first, or email address if needed.
|
5
|
-
# If no user is found matching, return nil
|
6
|
-
def find_for_session(username_or_email)
|
7
|
-
return nil if username_or_email.to_s.blank?
|
8
|
-
|
9
|
-
result = nil
|
10
|
-
|
11
|
-
if username_or_email.to_s.include?('@')
|
12
|
-
result = where(email: username_or_email).first
|
13
|
-
end
|
14
|
-
|
15
|
-
if !result
|
16
|
-
uid = username_or_email.to_s.downcase.strip
|
17
|
-
|
18
|
-
authorization = self.authorization_model
|
19
|
-
authorization = authorization.where(provider: :password, uid: uid)
|
20
|
-
authorization = authorization.first
|
21
|
-
|
22
|
-
if authorization
|
23
|
-
result = authorization.user
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
result
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|