standard-file 0.1.28 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/standard_file/sync_manager.rb +21 -6
- data/lib/standard_file/user_manager.rb +8 -2
- data/lib/standard_file/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a69077337f48d6974151f5aa9fbdb6d03a55c29
|
4
|
+
data.tar.gz: db6a54182bb62b35ec2bed3a3e7e4aefbf67acd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab4b67da5c58816fb5e7f070ca21b5c47d8999f797b81c0d86d58686ec0229cd86e38a84b19158aa5f713d3df4b2b677af31481e75388774a0580049b0a8ed1
|
7
|
+
data.tar.gz: fe42b466e4fe00fdbbd19cbc3f5e267e1447f40db844b9048790ab02e985c9ea15af5ff1094415916a08ebfd682523b1243246a1fbc37702a4423b5d45fd9357
|
@@ -29,24 +29,33 @@ module StandardFile
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# manage conflicts
|
32
|
+
min_conflict_interval = 20
|
33
|
+
|
32
34
|
saved_ids = saved_items.map{|x| x.uuid }
|
33
35
|
retrieved_ids = retrieved_items.map{|x| x.uuid }
|
34
36
|
conflicts = saved_ids & retrieved_ids # & is the intersection
|
35
37
|
# saved items take precedence, retrieved items are duplicated with a new uuid
|
36
38
|
conflicts.each do |conflicted_uuid|
|
37
|
-
# if changes are greater than
|
39
|
+
# if changes are greater than min_conflict_interval seconds apart, create conflicted copy, otherwise discard conflicted
|
38
40
|
saved = saved_items.find{|i| i.uuid == conflicted_uuid}
|
39
41
|
conflicted = retrieved_items.find{|i| i.uuid == conflicted_uuid}
|
40
|
-
if (saved.updated_at - conflicted.updated_at).abs >
|
42
|
+
if (saved.updated_at - conflicted.updated_at).abs > min_conflict_interval
|
41
43
|
puts "\n\n\n Creating conflicted copy of #{saved.uuid}\n\n\n"
|
42
44
|
dup = conflicted.dup
|
43
45
|
dup.user = conflicted.user
|
44
46
|
dup.save
|
45
|
-
|
47
|
+
dup_json = dup.as_json({})
|
48
|
+
dup_json[:conflict_of] = conflicted.uuid
|
49
|
+
retrieved_items.push(dup_json)
|
50
|
+
|
51
|
+
last_updated = dup.updated_at
|
46
52
|
end
|
47
53
|
retrieved_items.delete(conflicted)
|
48
54
|
end
|
49
55
|
|
56
|
+
# add 1 microsecond to avoid returning same object in subsequent sync
|
57
|
+
last_updated = (last_updated.to_time + 1/100000.0).to_datetime.utc
|
58
|
+
|
50
59
|
sync_token = sync_token_from_datetime(last_updated)
|
51
60
|
return {
|
52
61
|
:retrieved_items => retrieved_items,
|
@@ -66,15 +75,21 @@ module StandardFile
|
|
66
75
|
private
|
67
76
|
|
68
77
|
def sync_token_from_datetime(datetime)
|
69
|
-
version =
|
70
|
-
Base64.encode64("#{version}:" + "#{datetime.
|
78
|
+
version = 2
|
79
|
+
Base64.encode64("#{version}:" + "#{datetime.to_f}")
|
71
80
|
end
|
72
81
|
|
73
82
|
def datetime_from_sync_token(sync_token)
|
74
83
|
decoded = Base64.decode64(sync_token)
|
75
84
|
parts = decoded.rpartition(":")
|
76
85
|
timestamp_string = parts.last
|
77
|
-
|
86
|
+
version = parts.first
|
87
|
+
if version == "1"
|
88
|
+
date = DateTime.strptime(timestamp_string,'%s')
|
89
|
+
elsif version == "2"
|
90
|
+
date = Time.at(timestamp_string.to_f).to_datetime.utc
|
91
|
+
end
|
92
|
+
|
78
93
|
return date
|
79
94
|
end
|
80
95
|
|
@@ -18,7 +18,7 @@ module StandardFile
|
|
18
18
|
def register(email, password, params)
|
19
19
|
user = @user_class.find_by_email(email)
|
20
20
|
if user
|
21
|
-
return {:error => {:message => "
|
21
|
+
return {:error => {:message => "This email is already registered.", :status => 401}}
|
22
22
|
else
|
23
23
|
user = @user_class.new(:email => email, :encrypted_password => hash_password(password))
|
24
24
|
user.update!(registration_params(params))
|
@@ -26,6 +26,12 @@ module StandardFile
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def change_pw(user, password, params)
|
30
|
+
user.encrypted_password = hash_password(password)
|
31
|
+
user.update!(registration_params(params))
|
32
|
+
return { user: user, token: jwt(user) }
|
33
|
+
end
|
34
|
+
|
29
35
|
def auth_params(email)
|
30
36
|
user = @user_class.find_by_email(email)
|
31
37
|
pw_salt = user ? Digest::SHA1.hexdigest(email + "SN" + user.pw_nonce) : Digest::SHA1.hexdigest(email + "SN" + @salt_psuedo_nonce)
|
@@ -53,7 +59,7 @@ module StandardFile
|
|
53
59
|
end
|
54
60
|
|
55
61
|
def jwt(user)
|
56
|
-
JwtHelper.encode({:user_uuid => user.uuid})
|
62
|
+
JwtHelper.encode({:user_uuid => user.uuid, :pw_hash => Digest::SHA256.hexdigest(user.encrypted_password)})
|
57
63
|
end
|
58
64
|
|
59
65
|
def registration_params(params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Standard File
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|