standard-file 0.1.9 → 0.1.21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ab8f64216e606826f8cf9724b89725e0e36fa77
4
- data.tar.gz: e5fcc42d7de62ebbdc7baf0e30a0773cda1eb2d2
3
+ metadata.gz: fd3197cfdf910c453147dcb98c0d901accb03ea7
4
+ data.tar.gz: 0354d14c7afdf121ae2c74e8c4b04967afeb8e46
5
5
  SHA512:
6
- metadata.gz: eb025676ebfbe79137614e2c799a8b80a09542450dc11327fd2ca31a757998e6a6a7fcacb143e1f083ac7a502c3193552bb9968eb56be88e48303a7111b228e2
7
- data.tar.gz: f20eced00dd47a3a496e8f0ce932d996a85c8f1864de2aab3e9c12631a2eb572fcb84861f2b05d09d58d825213ad4ea0088d7ca867093e47a423c9ef6d6fb778
6
+ metadata.gz: 7d79bdc8a0c1453d7b4a99ac634ff6d42d71c77c767dc64a497e243bf06f1a561d5e3ac9c05515e1ccfb4e4b055901816ee3fd5437986d0c6f2573ef5a4ced43
7
+ data.tar.gz: 8dceaaa77be3404f5f66e38ab9356d828d7d2091ea903702dbe2a2ca57a77f3c2ba4683cc78ca0c14965c6d43bf634c8be76c7af7ed06900a6d2617a7bf3d6e8
@@ -1,7 +1,7 @@
1
1
  module StandardFile
2
2
  module JwtHelper
3
- require "jwt"
4
-
3
+ require "JWT"
4
+
5
5
  def self.encode(payload)
6
6
  JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
7
7
  end
@@ -29,33 +29,24 @@ module StandardFile
29
29
  end
30
30
 
31
31
  # manage conflicts
32
- min_conflict_interval = 20
33
-
34
32
  saved_ids = saved_items.map{|x| x.uuid }
35
33
  retrieved_ids = retrieved_items.map{|x| x.uuid }
36
34
  conflicts = saved_ids & retrieved_ids # & is the intersection
37
35
  # saved items take precedence, retrieved items are duplicated with a new uuid
38
36
  conflicts.each do |conflicted_uuid|
39
- # if changes are greater than min_conflict_interval seconds apart, create conflicted copy, otherwise discard conflicted
37
+ # if changes are greater than 60 seconds apart, create conflicted copy, otherwise discard conflicted
40
38
  saved = saved_items.find{|i| i.uuid == conflicted_uuid}
41
39
  conflicted = retrieved_items.find{|i| i.uuid == conflicted_uuid}
42
- if (saved.updated_at - conflicted.updated_at).abs > min_conflict_interval
40
+ if (saved.updated_at - conflicted.updated_at).abs > 60
43
41
  puts "\n\n\n Creating conflicted copy of #{saved.uuid}\n\n\n"
44
42
  dup = conflicted.dup
45
43
  dup.user = conflicted.user
46
44
  dup.save
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
45
+ retrieved_items.push(dup)
52
46
  end
53
47
  retrieved_items.delete(conflicted)
54
48
  end
55
49
 
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
-
59
50
  sync_token = sync_token_from_datetime(last_updated)
60
51
  return {
61
52
  :retrieved_items => retrieved_items,
@@ -66,30 +57,19 @@ module StandardFile
66
57
  }
67
58
  end
68
59
 
69
- def destroy_items(uuids)
70
- items = @user.items.where(uuid: uuids)
71
- items.destroy_all
72
- end
73
-
74
60
 
75
61
  private
76
62
 
77
63
  def sync_token_from_datetime(datetime)
78
- version = 2
79
- Base64.encode64("#{version}:" + "#{datetime.to_f}")
64
+ version = 1
65
+ Base64.encode64("#{version}:" + "#{datetime.to_i}")
80
66
  end
81
67
 
82
68
  def datetime_from_sync_token(sync_token)
83
69
  decoded = Base64.decode64(sync_token)
84
70
  parts = decoded.rpartition(":")
85
71
  timestamp_string = parts.last
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
-
72
+ date = DateTime.strptime(timestamp_string,'%s')
93
73
  return date
94
74
  end
95
75
 
@@ -9,7 +9,7 @@ module StandardFile
9
9
  def sign_in(email, password)
10
10
  user = @user_class.find_by_email(email)
11
11
  if user and test_password(password, user.encrypted_password)
12
- return { user: user, token: jwt(user) }
12
+ return { user: user, token: jwt(user), items: user.items }
13
13
  else
14
14
  return {:error => {:message => "Invalid email or password.", :status => 401}}
15
15
  end
@@ -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 => "This email is already registered.", :status => 401}}
21
+ return {:error => {:message => "Unable to register.", :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,12 +26,6 @@ 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
-
35
29
  def auth_params(email)
36
30
  user = @user_class.find_by_email(email)
37
31
  pw_salt = user ? Digest::SHA1.hexdigest(email + "SN" + user.pw_nonce) : Digest::SHA1.hexdigest(email + "SN" + @salt_psuedo_nonce)
@@ -59,7 +53,7 @@ module StandardFile
59
53
  end
60
54
 
61
55
  def jwt(user)
62
- JwtHelper.encode({:user_uuid => user.uuid, :pw_hash => Digest::SHA256.hexdigest(user.encrypted_password)})
56
+ JwtHelper.encode({:user_uuid => user.uuid})
63
57
  end
64
58
 
65
59
  def registration_params(params)
@@ -1,3 +1,3 @@
1
1
  module StandardFile
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.21'
3
3
  end
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.1.9
4
+ version: 0.1.21
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-04-21 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bcrypt
43
43
  requirement: !ruby/object:Gem::Requirement