exvo-auth 0.2.2 → 0.3.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/exvo-auth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exvo-auth}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jacek Becela"]
12
- s.date = %q{2010-06-29}
12
+ s.date = %q{2010-07-01}
13
13
  s.description = %q{Sign in with Exvo account}
14
14
  s.email = %q{jacek.becela@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,9 +25,10 @@ Gem::Specification.new do |s|
25
25
  "exvo-auth.gemspec",
26
26
  "lib/exvo-auth.rb",
27
27
  "lib/exvo_auth/config.rb",
28
+ "lib/exvo_auth/controllers/base.rb",
29
+ "lib/exvo_auth/controllers/merb.rb",
30
+ "lib/exvo_auth/controllers/rails.rb",
28
31
  "lib/exvo_auth/oauth2.rb",
29
- "lib/exvo_auth/path_helpers.rb",
30
- "lib/exvo_auth/rails/controller_helpers.rb",
31
32
  "lib/exvo_auth/strategies/base.rb",
32
33
  "lib/exvo_auth/strategies/interactive.rb",
33
34
  "lib/exvo_auth/strategies/non_interactive.rb",
data/lib/exvo-auth.rb CHANGED
@@ -2,9 +2,8 @@ require 'omniauth/oauth'
2
2
  require 'multi_json'
3
3
 
4
4
  module ExvoAuth
5
- autoload :PathHelpers, 'exvo_auth/path_helpers'
6
- autoload :Config, 'exvo_auth/config'
7
-
5
+ autoload :Config, 'exvo_auth/config'
6
+
8
7
  module OAuth2
9
8
  module Strategy
10
9
  autoload :NonInteractive, 'exvo_auth/oauth2'
@@ -17,8 +16,10 @@ module ExvoAuth
17
16
  autoload :NonInteractive, 'exvo_auth/strategies/non_interactive'
18
17
  end
19
18
 
20
- module Rails
21
- autoload :ControllerHelpers, 'exvo_auth/rails/controller_helpers'
19
+ module Controllers
20
+ autoload :Base, 'exvo_auth/controllers/base'
21
+ autoload :Rails, 'exvo_auth/controllers/rails'
22
+ autoload :Merb, 'exvo_auth/controllers/merb'
22
23
  end
23
24
  end
24
25
 
@@ -1,9 +1,4 @@
1
- module ExvoAuth::Rails::ControllerHelpers
2
- def self.included(base)
3
- base.send :include, ExvoAuth::PathHelpers
4
- base.helper_method :current_user, :signed_in?
5
- end
6
-
1
+ module ExvoAuth::Controllers::Base
7
2
  def authenticate_user!
8
3
  if !signed_in?
9
4
  store_location!
@@ -11,19 +6,23 @@ module ExvoAuth::Rails::ControllerHelpers
11
6
  callback_key = ExvoAuth::Config.callback_key
12
7
  callback_value = params[callback_key]
13
8
 
14
- if request.xhr?
15
- redirect_to non_interactive_sign_in_path
16
- elsif callback_value.present?
9
+ if callback_value
17
10
  redirect_to non_interactive_sign_in_path(callback_key => callback_value)
18
11
  else
19
- redirect_to interactive_sign_in_path
12
+ redirect_to sign_in_path
20
13
  end
21
14
  end
22
15
  end
23
16
 
17
+ def sign_out_and_redirect!(url = sign_out_url)
18
+ session.delete(:user_id)
19
+ @current_user = nil
20
+ redirect_to url
21
+ end
22
+
24
23
  def current_user
25
24
  return @current_user if defined?(@current_user)
26
- @current_user = session[:user_id] && User.find_by_id(session[:user_id])
25
+ @current_user = session[:user_id] && find_user_by_id(session[:user_id])
27
26
  end
28
27
 
29
28
  def signed_in?
@@ -31,24 +30,27 @@ module ExvoAuth::Rails::ControllerHelpers
31
30
  end
32
31
 
33
32
  def store_location!
34
- session[:return_to] = request.url if request.get?
33
+ session[:return_to] = current_url
35
34
  end
36
35
 
37
36
  def stored_location
38
37
  session.delete(:return_to)
39
38
  end
39
+
40
+ def sign_in_path
41
+ "/auth/interactive"
42
+ end
40
43
 
41
- private
42
-
43
- def interactive_sign_in_path(params = {})
44
- path_with_query("/auth/interactive", params)
44
+ def sign_up_path
45
+ "/auth/interactive"
45
46
  end
46
47
 
47
- def non_interactive_sign_in_path(params = {})
48
- path_with_query("/auth/non_interactive", params)
48
+ def sign_out_url
49
+ ExvoAuth::Config.host + "/users/sign_out"
49
50
  end
50
-
51
- def path_with_query(path, params = {})
51
+
52
+ def non_interactive_sign_in_path(params = {})
53
+ path = "/auth/non_interactive"
52
54
  query = Rack::Utils.build_query(params)
53
55
  query.empty? ? path : "#{path}?#{query}"
54
56
  end
@@ -0,0 +1,17 @@
1
+ module ExvoAuth::Controllers::Merb
2
+ def self.included(base)
3
+ base.send :include, ExvoAuth::Controllers::Base
4
+ end
5
+
6
+ def redirect_to(*args)
7
+ redirect(*args)
8
+ end
9
+
10
+ def find_user_by_id(id)
11
+ User[id]
12
+ end
13
+
14
+ def current_url
15
+ request.full_uri if request.method == :get
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module ExvoAuth::Controllers::Rails
2
+ def self.included(base)
3
+ base.send :include, ExvoAuth::Controllers::Base
4
+ helper_method :current_user, :signed_in?, :sign_in_path, :sign_up_path
5
+ end
6
+
7
+ def find_user_by_id(id)
8
+ User.find(id)
9
+ end
10
+
11
+ def current_url
12
+ request.url if request.get?
13
+ end
14
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jacek Becela
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-29 00:00:00 +02:00
17
+ date: 2010-07-01 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -49,9 +49,10 @@ files:
49
49
  - exvo-auth.gemspec
50
50
  - lib/exvo-auth.rb
51
51
  - lib/exvo_auth/config.rb
52
+ - lib/exvo_auth/controllers/base.rb
53
+ - lib/exvo_auth/controllers/merb.rb
54
+ - lib/exvo_auth/controllers/rails.rb
52
55
  - lib/exvo_auth/oauth2.rb
53
- - lib/exvo_auth/path_helpers.rb
54
- - lib/exvo_auth/rails/controller_helpers.rb
55
56
  - lib/exvo_auth/strategies/base.rb
56
57
  - lib/exvo_auth/strategies/interactive.rb
57
58
  - lib/exvo_auth/strategies/non_interactive.rb
@@ -1,17 +0,0 @@
1
- module ExvoAuth::PathHelpers
2
- def self.included(base)
3
- if base.respond_to?(:helper_method)
4
- base.helper_method :auth_sign_out_url, :auth_sign_in_path
5
- end
6
- end
7
-
8
- # Redirect users after logout there
9
- def auth_sign_out_url
10
- ExvoAuth::Config.host + "/users/sign_out"
11
- end
12
-
13
- # Redirect users to sign in / sign up
14
- def auth_sign_in_path
15
- "/auth/interactive"
16
- end
17
- end