lato 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97957e5c077e1eb2c5fc2f543ccd910e3c9e20c31a032f1caddf6d8f367f65d5
4
- data.tar.gz: ff14d933bc169b717bc6383b384f5b88454d5d74149b3c2c8d35843f0d9e2c3b
3
+ metadata.gz: 0022ea0879d81f9d92624508b04419c1949b4528264c0af286852bb1fd2a683e
4
+ data.tar.gz: 18676f46ef4c681dac7568843db624d4723a5303c3fa97e82838a6ea9b16b3cf
5
5
  SHA512:
6
- metadata.gz: 3f07d0df90a8c54f90eb3f8a12410a4d226710eaaaca16a63a0a9329dee6fb09e13e2abf8258555a4f45abeffc914328f5aec8c70aacb7778e70b34cd2f8e43d
7
- data.tar.gz: bcc45846cac8cf85cbe29cb2ffc5f7b90602148ab3a25f805d9d9f3414a2d6b6cce94167f57509d5e146d6df2887f7462e76bf3a0cbdcd75c71e837286e9814c
6
+ metadata.gz: d97683db01c97cdd4b8b043488ba26b73aa667720b22184acedcdd837a90735cae3832d75adb94b72df0aee17569a61b353e5e3091739bfacefecf1c710f00c2
7
+ data.tar.gz: fbdf84e72347070544d30ce16083f778b3dc27cc2d89eeb2db8bebe061ef78e02c0a42602fdf9769a6b225865d5d657d4bb7eccd1977e07bcf9052e9a6c97cc4
data/README.md CHANGED
@@ -14,10 +14,6 @@ gem "turbo-rails"
14
14
  # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
15
15
  gem "stimulus-rails" # NOTE: Probably already installed in default rails 7 project
16
16
 
17
- # Use Kredis as Redis interface [https://github.com/rails/kredis]
18
- # NOTE: Installation -> https://github.com/rails/kredis#installation
19
- gem "kredis"
20
-
21
17
  # Use Sass to process CSS
22
18
  gem "sassc-rails"
23
19
 
@@ -2,11 +2,6 @@ module Lato
2
2
  class Invitation < ApplicationRecord
3
3
  attr_accessor :actions
4
4
 
5
- # Kredis
6
- ##
7
-
8
- kredis_boolean :email_invite_semaphore, expires_in: 2.minutes
9
-
10
5
  # Validations
11
6
  ##
12
7
 
@@ -64,7 +59,7 @@ module Lato
64
59
  return false
65
60
  end
66
61
 
67
- if email_invite_semaphore.value
62
+ if c_email_invite_semaphore
68
63
  errors.add(:base, :email_sending_limit)
69
64
  return false
70
65
  end
@@ -75,9 +70,21 @@ module Lato
75
70
  return false
76
71
  end
77
72
 
78
- email_invite_semaphore.value = true
73
+ c_email_invite_semaphore(true)
79
74
 
80
75
  true
81
76
  end
77
+
78
+
79
+ # Cache
80
+ ##
81
+
82
+ def c_email_invite_semaphore(value = nil)
83
+ cache_key = "Lato::Invitation/c_email_invite_semaphore/#{id}"
84
+ return Rails.cache.read(cache_key) if value.nil?
85
+
86
+ Rails.cache.write(cache_key, value, expires_in: 2.minutes)
87
+ value
88
+ end
82
89
  end
83
90
  end
@@ -4,13 +4,6 @@ module Lato
4
4
 
5
5
  has_secure_password
6
6
 
7
- # Kredis
8
- ##
9
-
10
- kredis_boolean :email_verification_semaphore, expires_in: 2.minutes
11
- kredis_string :email_verification_code, expires_in: 30.minutes
12
- kredis_string :password_update_code, expires_in: 30.minutes
13
-
14
7
  # Validations
15
8
  ##
16
9
 
@@ -113,7 +106,7 @@ module Lato
113
106
  end
114
107
 
115
108
  def request_verify_email
116
- if email_verification_semaphore.value
109
+ if c_email_verification_semaphore
117
110
  errors.add(:base, :email_verification_limit)
118
111
  return
119
112
  end
@@ -125,25 +118,27 @@ module Lato
125
118
  return
126
119
  end
127
120
 
128
- email_verification_code.value = code
129
- email_verification_semaphore.value = true
121
+ c_email_verification_code(code)
122
+ c_email_verification_semaphore(true)
130
123
 
131
124
  true
132
125
  end
133
126
 
134
127
  def verify_email(params)
135
- unless email_verification_code.value
128
+ email_verification_code = c_email_verification_code
129
+
130
+ if email_verification_code.blank?
136
131
  errors.add(:base, :email_verification_code_expired)
137
132
  return
138
133
  end
139
134
 
140
- unless email_verification_code.value == params[:code]
135
+ unless email_verification_code == params[:code]
141
136
  errors.add(:base, :email_verification_code_invalid)
142
137
  return
143
138
  end
144
139
 
145
- email_verification_code.value = nil
146
- email_verification_semaphore.value = nil
140
+ c_email_verification_code('')
141
+ c_email_verification_semaphore(false)
147
142
 
148
143
  update_column(:email_verified_at, Time.now)
149
144
  true
@@ -166,23 +161,25 @@ module Lato
166
161
  self.id = user.id
167
162
  reload
168
163
 
169
- password_update_code.value = code
164
+ c_password_update_code(code)
170
165
 
171
166
  true
172
167
  end
173
168
 
174
169
  def update_password(params)
175
- unless password_update_code.value
170
+ password_update_code = c_password_update_code
171
+
172
+ if password_update_code.blank?
176
173
  errors.add(:base, :password_update_code_expired)
177
174
  return
178
175
  end
179
176
 
180
- unless password_update_code.value == params[:code]
177
+ unless password_update_code == params[:code]
181
178
  errors.add(:base, :password_update_code_invalid)
182
179
  return
183
180
  end
184
181
 
185
- password_update_code.value = nil
182
+ c_password_update_code('')
186
183
 
187
184
  update(params.permit(:password, :password_confirmation))
188
185
  end
@@ -230,5 +227,32 @@ module Lato
230
227
  true
231
228
  end
232
229
  end
230
+
231
+ # Cache
232
+ ##
233
+
234
+ def c_email_verification_semaphore(value = nil)
235
+ cache_key = "Lato::User/c_email_verification_semaphore/#{id}"
236
+ return Rails.cache.read(cache_key) if value.nil?
237
+
238
+ Rails.cache.write(cache_key, value, expires_in: 2.minutes)
239
+ value
240
+ end
241
+
242
+ def c_email_verification_code(value = nil)
243
+ cache_key = "Lato::User/c_email_verification_code/#{id}"
244
+ return Rails.cache.read(cache_key) if value.nil?
245
+
246
+ Rails.cache.write(cache_key, value, expires_in: 30.minutes)
247
+ value
248
+ end
249
+
250
+ def c_password_update_code(value = nil)
251
+ cache_key = "Lato::User/c_password_update_code/#{id}"
252
+ return Rails.cache.read(cache_key) if value.nil?
253
+
254
+ Rails.cache.write(cache_key, value, expires_in: 30.minutes)
255
+ value
256
+ end
233
257
  end
234
258
  end
data/lib/lato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lato
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante