devise_latcheable 0.1.0 → 0.1.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/README.md +18 -14
- data/lib/devise_latcheable.rb +7 -3
- data/lib/devise_latcheable/model.rb +6 -2
- data/lib/devise_latcheable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87241b423b253073441eb3c2856b6b2051a31e3d
|
4
|
+
data.tar.gz: 7bb4b6a26c5b52ffc2bf214368f31c5002fb06e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f56511bb07e35bc80939f13a64d183c5e49d48c4285c4d4b74a274cdbaf5d7bd0d79dd1a5843a4806b2bf829dfcac88c6aaaf81c71fc0d81e2d5cb4330fb5252
|
7
|
+
data.tar.gz: 5b9632722d28176bf52e33f7e6e8f32201970a7cd91a11f01380f9ceddf34a4f675c3b76c9feab23df08643d72691e6efb48f3cf9d0147241bbc4ce96d036660
|
data/README.md
CHANGED
@@ -110,25 +110,29 @@ user.latch_account_id
|
|
110
110
|
### Methods on the users model
|
111
111
|
|
112
112
|
#### latch_pair!
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
On success, it sets latch_account_id to the value that
|
117
|
-
|
118
|
-
@returns true on success, false otherwise
|
113
|
+
This method pairs an user with the server. If an error occurs, it copies the
|
114
|
+
error at errors base so you can access it with model_instance.errors
|
115
|
+
|
116
|
+
On success, it sets latch_account_id to the value that the latch server sent
|
117
|
+
on its response
|
119
118
|
|
120
119
|
### latch_unpair!
|
121
|
-
Removes the pairing from latch
|
122
|
-
|
123
|
-
so you can access it with model_instance.errors
|
124
|
-
@returns true on success, false otherwise
|
120
|
+
Removes the pairing from latch. If an error occurs, it copies the error at
|
121
|
+
errors base so you can access it with model_instance.errors.
|
125
122
|
|
126
123
|
### latch_unlocked?
|
127
|
-
Checks if the app lock is open
|
128
|
-
|
129
|
-
@returns false if the latch is locked or if there was an error
|
124
|
+
Checks if the app lock is open. Returns true if the latch is unlocked and
|
125
|
+
false if the latch is locked or if there was an error
|
130
126
|
|
131
127
|
## Demo
|
132
128
|
There is a app already configured with devise and devise\_latcheable at
|
133
|
-
[this repo](https://github.com/
|
129
|
+
[this repo](https://github.com/carlosrdrz/latch_app) for demo and
|
134
130
|
development purposes.
|
131
|
+
|
132
|
+
You can see that app running at http://latcheable.carlosrdrz.es
|
133
|
+
|
134
|
+
## How it works
|
135
|
+
|
136
|
+
Devise builds a chain of strategies that he must check when logging an user in.
|
137
|
+
You can define your chain of strategies in your model. We use database_authenticaton
|
138
|
+
with latcheable, so both strategies are checked when logging an user in.
|
data/lib/devise_latcheable.rb
CHANGED
@@ -7,12 +7,16 @@ require 'devise_latcheable/engine'
|
|
7
7
|
module DeviseLatcheable
|
8
8
|
# The config file
|
9
9
|
mattr_accessor :config
|
10
|
-
self.config = YAML.load(File.read('config/latch.yml'))
|
11
10
|
|
12
11
|
# We instantiate only one api client per app
|
13
12
|
mattr_accessor :api
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
def self.initialize
|
15
|
+
self.config = YAML.load(File.read('config/latch.yml'))
|
16
|
+
|
17
|
+
self.api = ::Latch.new ::DeviseLatcheable.config['app_id'],
|
18
|
+
::DeviseLatcheable.config['app_secret']
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
Devise.add_module :latcheable,
|
@@ -25,6 +25,7 @@ module Devise
|
|
25
25
|
def latch_unlocked?
|
26
26
|
return true unless latch_enabled?
|
27
27
|
return false if latch_account_id.nil?
|
28
|
+
::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil?
|
28
29
|
api_response = ::DeviseLatcheable.api.status latch_account_id
|
29
30
|
|
30
31
|
if api_response.error.nil?
|
@@ -43,6 +44,7 @@ module Devise
|
|
43
44
|
def latch_unpair!
|
44
45
|
return true unless latch_enabled?
|
45
46
|
return true if latch_account_id.nil?
|
47
|
+
::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil?
|
46
48
|
api_response = ::DeviseLatcheable.api.unpair latch_account_id
|
47
49
|
|
48
50
|
if api_response.error.nil?
|
@@ -61,8 +63,9 @@ module Devise
|
|
61
63
|
# @returns true on success, false otherwise
|
62
64
|
def latch_pair!
|
63
65
|
return true unless latch_enabled?
|
66
|
+
::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil?
|
64
67
|
api_response = ::DeviseLatcheable.api.pair latch_pair_code
|
65
|
-
|
68
|
+
|
66
69
|
if api_response.error.nil?
|
67
70
|
self.latch_account_id = api_response.data['accountId']
|
68
71
|
return true
|
@@ -72,7 +75,8 @@ module Devise
|
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
75
|
-
def latch_enable
|
78
|
+
def latch_enable
|
79
|
+
::DeviseLatcheable.initialize if ::DeviseLatcheable.config.nil?
|
76
80
|
if ::DeviseLatcheable.config['always_enabled'] == true
|
77
81
|
self.latch_enabled = true
|
78
82
|
end
|