cop-detective 0.1.1 → 0.1.2
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/assigner.rb +8 -1
- data/lib/cop_detective.rb +12 -5
- data/lib/errors.rb +0 -4
- data/lib/validator.rb +0 -8
- 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: 8db75e49616c8035bab21a2a759d883b50441cd3
|
4
|
+
data.tar.gz: 384693b3ee2797511907c6fd53d7ff01f558ab47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d480423ad277c139cf96a86879add7338d8d2adfe3394616e37d513f69fcc34ee441a7ac2ac5cc1a8fdc0c259dd7a627cde75a75a74a77973d5cf223858f87
|
7
|
+
data.tar.gz: d74319f7a227192274117707be3313c28954a1edf8bcadab8598a0ca0e6a44104ad16cd9adf28feeaf0fee3608cd9325a65c26fbbe0ffea4fecbe4cdae42b164
|
data/lib/assigner.rb
CHANGED
@@ -8,8 +8,14 @@ class CopDetectiveAssigner
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
+
def reset_variables
|
12
|
+
@@params = Hash.new(nil)
|
13
|
+
@@keys = nil
|
14
|
+
@@keychain = []
|
15
|
+
@@internal_keys = nil
|
16
|
+
end
|
17
|
+
|
11
18
|
def build_params(params)
|
12
|
-
@@keychain
|
13
19
|
params.each do |k, v|
|
14
20
|
if v.is_a?(Hash)
|
15
21
|
build_params(v)
|
@@ -20,6 +26,7 @@ class CopDetectiveAssigner
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def assign(params, keys)
|
29
|
+
reset_variables
|
23
30
|
set_keychain(keys)
|
24
31
|
build_params(params)
|
25
32
|
translate_keys
|
data/lib/cop_detective.rb
CHANGED
@@ -7,10 +7,10 @@ require_relative 'assigner'
|
|
7
7
|
|
8
8
|
class CopDetective
|
9
9
|
cattr_reader :messages
|
10
|
-
|
11
|
-
|
10
|
+
include ActiveModel::SecurePassword
|
11
|
+
@@messages = CopDetectiveValidator.messages
|
12
12
|
|
13
|
-
|
13
|
+
class << self
|
14
14
|
|
15
15
|
def configure(options)
|
16
16
|
@@old_password = options[:old_password]
|
@@ -26,6 +26,7 @@ class CopDetective
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def investigate(user, params)
|
29
|
+
reset_variables
|
29
30
|
assign(params, @@keys)
|
30
31
|
return create_user(user) if @@old_password == nil
|
31
32
|
update_user(user)
|
@@ -33,6 +34,12 @@ class CopDetective
|
|
33
34
|
|
34
35
|
private
|
35
36
|
|
37
|
+
def reset_variables
|
38
|
+
@@old_password = nil
|
39
|
+
@@password = nil
|
40
|
+
@@confirmation = nil
|
41
|
+
end
|
42
|
+
|
36
43
|
def inspect_keys(keys)
|
37
44
|
keys.each do |k, v|
|
38
45
|
raise CopDetective::ErrorMessages.formatting if k != :confirmation && k != :password && k != :old_password
|
@@ -47,7 +54,7 @@ class CopDetective
|
|
47
54
|
|
48
55
|
def update_user(user)
|
49
56
|
return validate_new_passwords(user) if valid_credentials?(user, @@old_password)
|
50
|
-
|
57
|
+
user.errors.set(:password, [ErrorMessages.unsaved_password(ErrorMessages.invalid_password)])
|
51
58
|
end
|
52
59
|
|
53
60
|
def create_user(user)
|
@@ -55,7 +62,7 @@ class CopDetective
|
|
55
62
|
user.save
|
56
63
|
@@messages[:notice] = "Account created. You may now log in."
|
57
64
|
else
|
58
|
-
user.errors.
|
65
|
+
user.errors.set(:password, ["Passwords don't match or other params are not valid."])
|
59
66
|
end
|
60
67
|
end
|
61
68
|
|
data/lib/errors.rb
CHANGED
data/lib/validator.rb
CHANGED
@@ -20,14 +20,6 @@ class CopDetectiveValidator
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def options_valid?(options)
|
24
|
-
options.each do |k, v|
|
25
|
-
return CopDetective::ErrorMessages.options_error(k, @@options_errors[:option_nil]) if v.nil?
|
26
|
-
return CopDetective::ErrorMessages.options_error(k, @@options_errors[:empty]) if v.empty?
|
27
|
-
end
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
23
|
def valid_credentials?(user, old_password)
|
32
24
|
user.authenticate(old_password) == user
|
33
25
|
end
|