softwear-lib 1.5.8 → 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f0b0ffdf353b1125791532b04b4c69178f3848d
4
- data.tar.gz: b5ffb662dafdbd0ced2e2b3fda77c68314ed4a9e
3
+ metadata.gz: 20165a6e28e50bf2343b3616f440fe581c249b4d
4
+ data.tar.gz: 6f50638cdade6f465fc5d92372c4181f877d3718
5
5
  SHA512:
6
- metadata.gz: 51397655427dfd487c7690028a486f73e2b35bd4a5fa4bfd7a92b02a3b5f1cfe651d63d26238c4f5d0e5f3620e263264d8535abc8eb6f2bf9678921354fda310
7
- data.tar.gz: 536a85856023e46c1897ba453764710d257cc940beb5923b6510c1f3ff9ffaf40ab7c605443a469f927c9b3f4d0c6c25720f6ca64a43f537e16a3d36d2447a65
6
+ metadata.gz: a67cfdbec3d95464d2c551420582fc65d7bad6083dd03b2602b04db2c12a9f0335b802c0a686b3a06fd88513184423bbafd07cf9339d918d6151afd29db1d699
7
+ data.tar.gz: 34f0a721a49c5e7cad13e9673b9767251f516b3a050b186b79c002e72fe4cc00f89b6b335f7454b073f0090cfbee06721033ad47043bef380e0539000a494a8b
@@ -14,6 +14,8 @@ module Softwear
14
14
  allow(User).to receive(:auth) { @_signed_in_user or false }
15
15
  allow(User).to receive(:raw_query) { |q| raise "Unstubbed authentication query \"#{q}\"" }
16
16
 
17
+ allow(Figaro.env).to receive(:softwear_hub_url).and_return 'http://hub.example.com'
18
+
17
19
  allow_any_instance_of(Softwear::Lib::ControllerAuthentication)
18
20
  .to receive(:user_token)
19
21
  .and_return('')
@@ -1,5 +1,5 @@
1
1
  module Softwear
2
2
  module Lib
3
- VERSION = "1.5.8"
3
+ VERSION = "1.5.9"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softwear-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.8
4
+ version: 1.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie
@@ -91,7 +91,6 @@ files:
91
91
  - lib/softwear/auth/token_authentication.rb
92
92
  - lib/softwear/lib.rb
93
93
  - lib/softwear/lib/api_controller.rb
94
- - lib/softwear/lib/authentication.rb
95
94
  - lib/softwear/lib/capistrano.rb
96
95
  - lib/softwear/lib/controller_authentication.rb
97
96
  - lib/softwear/lib/spec.rb
@@ -1,103 +0,0 @@
1
- module Softwear
2
- module Lib
3
- module ControllerAuthentication
4
- extend ActiveSupport::Concern
5
-
6
- class NotSignedInError < StandardError
7
- end
8
-
9
- included do
10
- rescue_from NotSignedInError, with: :user_not_signed_in
11
- rescue_from Softwear::Auth::Model::AuthServerDown, with: :auth_server_down
12
-
13
- helper_method :current_user
14
- helper_method :user_signed_in?
15
-
16
- helper_method :destroy_user_session_path
17
- helper_method :users_path
18
- helper_method :user_path
19
- helper_method :edit_user_path
20
- end
21
-
22
- def user_class
23
- if Softwear::Auth::Model.descendants.size > 1
24
- raise "More than one descendent of Softwear::Auth::Model is not supported."
25
- elsif Softwear::Auth::Model.descendants.size == 0
26
- raise "Please define a user model that extends Softwear::Auth::Model."
27
- end
28
- Softwear::Auth::Model.descendants.first
29
- end
30
-
31
- # ====================
32
- # Action called when a NotSignedInError is raised.
33
- # ====================
34
- def user_not_signed_in
35
- redirect_to Figaro.env.softwear_hub_url + "/users/sign_in?#{{return_to: request.original_url}.to_param}"
36
- end
37
-
38
- # ====================
39
- # Action called when a NotSignedInError is raised.
40
- # ====================
41
- def auth_server_down(error)
42
- respond_to do |format|
43
- format.html do
44
- render inline: \
45
- "<h1>#{error.message}</h1><div>Not all site functions will work until the problem is resolved. "\
46
- "<a href='javascripr' onclick='history.go(-1);return false;' class='btn btn-default'>Go back.</a></div>"
47
- end
48
-
49
- format.js do
50
- render inline: "alert(\"#{error.message.gsub('"', '\"')}\");"
51
- end
52
- end
53
- end
54
-
55
- # ====================
56
- # Drop this into a before_filter to require a user be signed in on every request -
57
- # just like in Devise.
58
- # ====================
59
- def authenticate_user!
60
- token = session[:user_token]
61
-
62
- if token.blank?
63
- raise NotSignedInError, "No token"
64
- end
65
-
66
- if user = user_class.auth(token)
67
- @current_user = user
68
- else
69
- session[:user_token] = nil
70
- raise NotSignedInError, "Invalid token"
71
- end
72
- end
73
-
74
- def current_user
75
- @current_user
76
- end
77
-
78
- def user_signed_in?
79
- !@current_user.nil?
80
- end
81
-
82
- # -- url uelpers --
83
-
84
- def destroy_user_session_path
85
- Figaro.env.softwear_hub_url + "/users/sign_out"
86
- end
87
-
88
- def user_path(user)
89
- user_id = user.is_a?(user_class) ? user.id : user
90
- Figaro.env.softwear_hub_url + "/users/#{user_id}"
91
- end
92
-
93
- def edit_user_path(user)
94
- user_id = user.is_a?(user_class) ? user.id : user
95
- Figaro.env.softwear_hub_url + "/users/#{user_id}/edit"
96
- end
97
-
98
- def users_path
99
- Figaro.env.softwear_hub_url + "/users"
100
- end
101
- end
102
- end
103
- end