Skip to content

Commit d0b58f3

Browse files
add handle_users_is_blocked and logic in base controller
1 parent 40f3210 commit d0b58f3

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

app/controllers/api_authentication/facebook/sessions_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
class ApiAuthentication::Facebook::SessionsController < ApiAuthentication::BaseController
22
skip_before_action :authenticate!, only: :create
33

4+
attr_reader :resource
5+
46
private
5-
def build_resource
6-
@session = ::ApiAuthentication::Session.social_login.facebook.new resource_params
7-
end
87

9-
def resource
10-
@session
8+
def build_resource
9+
@resource = ::ApiAuthentication::Session.social_login.facebook.new resource_params
1110
end
1211

1312
def resource_params

app/controllers/concerns/api_authentication/acts_as_base_controller_with_authentication.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def decode_jwt_hash_by token
7272

7373
@current_user_id = current_jwt_hash[:user][:id]
7474

75+
#
76+
# is_blocked
77+
#
78+
if \
79+
ApiAuthentication.configuration.handle_users_is_blocked &&
80+
current_user_with_only_is_blocked.respond_to?(:is_blocked) &&
81+
current_user_with_only_is_blocked.is_blocked?
82+
return false
83+
end
84+
7585
return true
7686
rescue JWT::DecodeError
7787
return false
@@ -83,6 +93,11 @@ def current_user
8393
"::#{ ApiAuthentication.configuration.app_user_model_class_name.constantize }".constantize.find current_user_id
8494
end
8595

96+
def current_user_with_only_is_blocked
97+
@current_user ||=
98+
"::#{ ApiAuthentication.configuration.app_user_model_class_name.constantize }".constantize.select(:is_blocked).find current_user_id
99+
end
100+
86101
def current_session
87102
@current_session ||= ::ApiAuthentication::Session.find_by_token! current_token
88103
end

lib/api_authentication/configuration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ class Configuration
4242

4343
config_accessor(:app_user_model_class_name) { 'User' }
4444

45+
config_accessor(:handle_users_is_blocked) { false }
46+
4547
end
4648
end

lib/api_authentication/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ApiAuthentication
2-
VERSION = '0.2.0'
2+
VERSION = '0.2.1'
33
end

lib/generators/templates/api_authentication.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@
3434
# => allow to set up in-app class name of user model
3535
#
3636
# config.app_user_model_class_name = 'User'
37+
38+
# config.handle_users_is_blocked = false
3739
end

0 commit comments

Comments
 (0)