softwear-lib 1.5.0 → 1.5.1
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.
- checksums.yaml +4 -4
- data/lib/softwear/auth/controller.rb +4 -0
- data/lib/softwear/auth/model.rb +4 -0
- data/lib/softwear/auth/spec.rb +58 -0
- data/lib/softwear/lib.rb +1 -0
- data/lib/softwear/lib/controller_authentication.rb +22 -7
- data/lib/softwear/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee29f7263adae53ab78fc85bbf5be053ab9e595
|
4
|
+
data.tar.gz: fb4122fcdf16d493d6458ccd6244b0389abed414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d9e0af480f85c41f40b64c63e26d1c6de7bc8a061117673373fe3889e7c606be2e49ab664a3f53296141be71c0a3a2a2bbdb470113a9008546d8f7ce6d4d975
|
7
|
+
data.tar.gz: 1eaf5225a3240a1e6d0b7953ce33ebab100cb836bf9388dcafc899ba84581a4feaf505cc87ca26696052f54fc443d668320fc12870e5a8e1a22c95a4c4149b0e
|
@@ -3,6 +3,10 @@ module Softwear
|
|
3
3
|
class Controller < ApplicationController
|
4
4
|
skip_before_filter :authenticate_user!, only: [:set_session_token, :clear_query_cache]
|
5
5
|
|
6
|
+
def self.abstract_class?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
6
10
|
# ====================
|
7
11
|
# Comes from an img tag on softwear-hub to let an authorized app know that
|
8
12
|
# a user has signed in.
|
data/lib/softwear/auth/model.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Softwear
|
2
|
+
module Auth
|
3
|
+
module Spec
|
4
|
+
def spec_users
|
5
|
+
User.instance_variable_get(:@_spec_users)
|
6
|
+
end
|
7
|
+
|
8
|
+
def stub_authentication!(config, *a)
|
9
|
+
config.before(:each, *a) do
|
10
|
+
User.instance_variable_set(:@_spec_users, [])
|
11
|
+
|
12
|
+
allow(User).to receive(:all) { spec_users }
|
13
|
+
allow(User).to receive(:find) { |n| spec_users.find { |u| u.id == n } }
|
14
|
+
allow(User).to receive(:auth) { @_signed_in_user or false }
|
15
|
+
allow(User).to receive(:raw_query) { |q| raise "Unstubbed authentication query \"#{q}\"" }
|
16
|
+
|
17
|
+
allow_any_instance_of(Softwear::Lib::ControllerAuthentication)
|
18
|
+
.to receive(:user_token)
|
19
|
+
.and_return('')
|
20
|
+
|
21
|
+
if (controller rescue false)
|
22
|
+
allow(controller).to receive(:current_user) { @_signed_in_user }
|
23
|
+
controller.class_eval { helper_method :current_user }
|
24
|
+
|
25
|
+
allow(controller).to receive(:user_signed_in?) { !!@_signed_in_user }
|
26
|
+
controller.class_eval { helper_method :user_signed_in? }
|
27
|
+
|
28
|
+
allow(controller).to receive(:destroy_user_session_path) { '#' }
|
29
|
+
controller.class_eval { helper_method :destroy_user_session_path }
|
30
|
+
|
31
|
+
allow(controller).to receive(:users_path) { '#' }
|
32
|
+
controller.class_eval { helper_method :users_path }
|
33
|
+
|
34
|
+
allow(controller).to receive(:edit_user_path) { '#' }
|
35
|
+
controller.class_eval { protected; helper_method :edit_user_path }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
config.after(:each, *a) do
|
40
|
+
User.instance_variable_set(:@_spec_users, nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def sign_in_as(user)
|
45
|
+
@_signed_in_user = user
|
46
|
+
|
47
|
+
allow_any_instance_of(Softwear::Lib::ControllerAuthentication)
|
48
|
+
.to receive(:user_token).and_return 'abc123'
|
49
|
+
|
50
|
+
if respond_to?(:session) && session.respond_to?(:[]=)
|
51
|
+
session[:user_token] = 'abc123'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
alias_method :sign_in, :sign_in_as
|
55
|
+
alias_method :login_as, :sign_in_as
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/softwear/lib.rb
CHANGED
@@ -42,8 +42,15 @@ module Softwear
|
|
42
42
|
respond_to do |format|
|
43
43
|
format.html do
|
44
44
|
render inline: \
|
45
|
-
"<
|
46
|
-
|
45
|
+
"<div class='panel panel-danger'>"\
|
46
|
+
"<div class='panel-heading'>"\
|
47
|
+
"<h3 class='panel-title'>#{error.message}</h3>"\
|
48
|
+
"</div>"\
|
49
|
+
"<div class='panel-body'>"\
|
50
|
+
"Not all site functions will work until the problem is resolved. "\
|
51
|
+
"<a href='javascripr' onclick='history.go(-1);return false;' class='btn btn-default'>Go back.</a>"\
|
52
|
+
"</div>"\
|
53
|
+
"</div>"
|
47
54
|
end
|
48
55
|
|
49
56
|
format.js do
|
@@ -57,16 +64,14 @@ module Softwear
|
|
57
64
|
# just like in Devise.
|
58
65
|
# ====================
|
59
66
|
def authenticate_user!
|
60
|
-
|
61
|
-
|
62
|
-
if token.blank?
|
67
|
+
if user_token.blank?
|
63
68
|
raise NotSignedInError, "No token"
|
64
69
|
end
|
65
70
|
|
66
|
-
if user = user_class.auth(
|
71
|
+
if user = user_class.auth(user_token)
|
67
72
|
@current_user = user
|
68
73
|
else
|
69
|
-
|
74
|
+
self.user_token = nil
|
70
75
|
raise NotSignedInError, "Invalid token"
|
71
76
|
end
|
72
77
|
end
|
@@ -98,6 +103,16 @@ module Softwear
|
|
98
103
|
def users_path
|
99
104
|
Figaro.env.softwear_hub_url + "/users"
|
100
105
|
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def user_token
|
110
|
+
session[:user_token]
|
111
|
+
end
|
112
|
+
|
113
|
+
def user_token=(new_token)
|
114
|
+
session[:user_token] = new_token
|
115
|
+
end
|
101
116
|
end
|
102
117
|
end
|
103
118
|
end
|
data/lib/softwear/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Baillie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/softwear/auth/controller.rb
|
88
88
|
- lib/softwear/auth/helper.rb
|
89
89
|
- lib/softwear/auth/model.rb
|
90
|
+
- lib/softwear/auth/spec.rb
|
90
91
|
- lib/softwear/lib.rb
|
91
92
|
- lib/softwear/lib/api_controller.rb
|
92
93
|
- lib/softwear/lib/authentication.rb
|