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 +4 -4
- data/lib/softwear/auth/spec.rb +2 -0
- data/lib/softwear/lib/version.rb +1 -1
- metadata +1 -2
- data/lib/softwear/lib/authentication.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20165a6e28e50bf2343b3616f440fe581c249b4d
|
4
|
+
data.tar.gz: 6f50638cdade6f465fc5d92372c4181f877d3718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67cfdbec3d95464d2c551420582fc65d7bad6083dd03b2602b04db2c12a9f0335b802c0a686b3a06fd88513184423bbafd07cf9339d918d6151afd29db1d699
|
7
|
+
data.tar.gz: 34f0a721a49c5e7cad13e9673b9767251f516b3a050b186b79c002e72fe4cc00f89b6b335f7454b073f0090cfbee06721033ad47043bef380e0539000a494a8b
|
data/lib/softwear/auth/spec.rb
CHANGED
@@ -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('')
|
data/lib/softwear/lib/version.rb
CHANGED
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.
|
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
|