sso_clyent 0.0.7.31 → 0.0.7.32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +1,63 @@
1
- module CurrentUserHelpers
2
- def login_required
3
- if !current_user
4
- return respond_to do |format|
5
- format.html { redirect_to login_path }
6
- format.json { render :json => { 'error' => 'Access Denied' }.to_json }
1
+ module SsoClyent
2
+ module CurrentUserHelpers
3
+
4
+ def self.included base
5
+ base.send :before_filter, :sso_clyent_check_if_from_sign_up
6
+ base.send :before_filter, :sso_clyent_store_return_to_url
7
+ end
8
+
9
+ def login_required
10
+ if !current_user
11
+ return respond_to do |format|
12
+ format.html { redirect_to sso_login_path }
13
+ format.json { render :json => { 'error' => 'Access Denied' }.to_json }
14
+ end
7
15
  end
8
16
  end
9
- end
10
-
11
- def login_path
12
- "#{SsoClyent.path}/auth/sso"
13
- end
14
-
15
- def logout_path
16
- "#{SsoClyent.path}/logout"
17
- end
18
17
 
19
- def signup_path
20
- SsoClyent.signup_url
21
- end
22
-
23
- def edit_account_path
24
- SsoClyent.edit_account_url
25
- end
26
-
27
- def current_user
28
- return nil unless session[:user_id]
29
- users = user_klass
30
- uid = userid
31
- if users.respond_to?(:"find_by_#{uid}")
32
- @current_user ||= users.send(:"find_by_#{uid}", session[:user_id]['uid'])
18
+ def current_user
19
+ return nil unless session[:user_id]
20
+ users = sso_clyent_user_klass
21
+ uid = sso_clyent_userid
22
+ if users.respond_to?(:"find_by_#{uid}")
23
+ @current_user ||= users.send(:"find_by_#{uid}", session[:user_id]['uid'])
24
+ end
33
25
  end
34
- end
35
26
 
36
- def user_signed_in?
37
- !!current_user
38
- end
27
+ def user_signed_in?
28
+ !!current_user
29
+ end
39
30
 
40
- def check_for_login_error api_response
41
- current_user_logout if !api_response.is_a? Array and api_response.try(:[],:error).try(:==,'401 Unauthorized')
42
- end
31
+ def check_for_login_error api_response
32
+ current_user_logout if !api_response.is_a?(Array) and api_response.try(:[],:error).try(:==,'401 Unauthorized')
33
+ end
43
34
 
44
- def current_user_logout
45
- session[:user_id] = nil
46
- end
35
+ def current_user_logout
36
+ session[:user_id] = nil
37
+ end
47
38
 
48
- def user_klass
49
- SsoClyent.user_class
50
- end
39
+ def sso_clyent_user_klass
40
+ SsoClyent.user_class
41
+ end
51
42
 
52
- def userid
53
- SsoClyent.unique_id
54
- end
43
+ def sso_clyent_userid
44
+ SsoClyent.unique_id
45
+ end
55
46
 
56
- def check_if_from_sign_up
57
- if from_sign_up = params.delete(:from_sign_up)
58
- login_required
59
- begin process_params_from_sign_up(from_sign_up)
60
- rescue
61
- end
62
- unless performed?
63
- return redirect_to(url_for(params))
47
+ def sso_clyent_check_if_from_sign_up
48
+ if from_sign_up = params.delete(:from_sign_up)
49
+ login_required
50
+ begin process_params_from_sign_up(from_sign_up)
51
+ rescue
52
+ end
53
+ unless performed?
54
+ return redirect_to(url_for(params))
55
+ end
64
56
  end
65
57
  end
58
+
59
+ def sso_clyent_store_return_to_url
60
+ (session['for_sign_up'] ||= {})['send_back_to'] = session['return-to-url'] = request.url
61
+ end
66
62
  end
67
- end
68
- ActionController::Base.send :include, CurrentUserHelpers
69
- ActionController::Base.send :before_filter, :check_if_from_sign_up
63
+ end
@@ -0,0 +1,21 @@
1
+ module SsoClyent
2
+ module PathHelpers
3
+
4
+ def login_path
5
+ "#{SsoClyent.path}/auth/sso"
6
+ end
7
+
8
+ def logout_path
9
+ "#{SsoClyent.path}/logout"
10
+ end
11
+
12
+ def signup_path
13
+ SsoClyent.signup_url
14
+ end
15
+
16
+ def edit_account_path
17
+ SsoClyent.edit_account_url
18
+ end
19
+
20
+ end
21
+ end
@@ -1,4 +1,5 @@
1
1
  require_relative './helpers/current_user_helpers'
2
+ require_relative './controllers/path_helpers'
2
3
 
3
4
  module SsoClyent
4
5
  class Engine < ::Rails::Engine
@@ -26,8 +27,10 @@ module SsoClyent
26
27
  end
27
28
  end
28
29
 
29
- initializer 'sso_clyent.extend_view_helpers' do |app|
30
+ initializer 'sso_clyent.extend_controllers_and_view_helpers' do |app|
30
31
  ActiveSupport.on_load :action_controller do
32
+ include SsoClyent::CurrentUserHelpers
33
+ include SsoClyent::PathHelpers
31
34
  helper SsoClyent::Helpers::CurrentUserHelpers
32
35
  end
33
36
  end
@@ -3,7 +3,7 @@ require_relative '../controllers/current_user_helpers'
3
3
  module SsoClyent
4
4
  module Helpers
5
5
  module CurrentUserHelpers
6
- include ::CurrentUserHelpers
6
+ include ::SsoClyent::CurrentUserHelpers
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module SsoClyent
2
- VERSION = "0.0.7.31"
2
+ VERSION = "0.0.7.32"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sso_clyent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.31
4
+ version: 0.0.7.32
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-03 00:00:00.000000000 Z
12
+ date: 2014-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70175890649680 !ruby/object:Gem::Requirement
16
+ requirement: &70359513219100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70175890649680
24
+ version_requirements: *70359513219100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: omniauth-oauth2
27
- requirement: &70175890648420 !ruby/object:Gem::Requirement
27
+ requirement: &70359513218060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70175890648420
35
+ version_requirements: *70359513218060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mysql2
38
- requirement: &70175890647040 !ruby/object:Gem::Requirement
38
+ requirement: &70359513216320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70175890647040
46
+ version_requirements: *70359513216320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &70175890646240 !ruby/object:Gem::Requirement
49
+ requirement: &70359513215480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70175890646240
57
+ version_requirements: *70359513215480
58
58
  description: See sso_provyder for the provider part. Based on Devise, Authentifyd
59
59
  and joshsoftware/sso-devise-omniauth-client. Parts directly taken from https://github.com/joshsoftware/sso-devise-omniauth-client
60
60
  email:
@@ -72,6 +72,7 @@ files:
72
72
  - config/routes.rb
73
73
  - lib/sso_clyent/base.rb
74
74
  - lib/sso_clyent/controllers/current_user_helpers.rb
75
+ - lib/sso_clyent/controllers/path_helpers.rb
75
76
  - lib/sso_clyent/engine.rb
76
77
  - lib/sso_clyent/helpers/current_user_helpers.rb
77
78
  - lib/sso_clyent/omniauth/strategies/sso.rb