lato 0.1.63 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/app/assets/javascripts/lato/application.js +10 -0
- data/app/models/lato/invitation.rb +14 -7
- data/app/models/lato/user.rb +42 -18
- data/lib/lato/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0022ea0879d81f9d92624508b04419c1949b4528264c0af286852bb1fd2a683e
|
4
|
+
data.tar.gz: 18676f46ef4c681dac7568843db624d4723a5303c3fa97e82838a6ea9b16b3cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97683db01c97cdd4b8b043488ba26b73aa667720b22184acedcdd837a90735cae3832d75adb94b72df0aee17569a61b353e5e3091739bfacefecf1c710f00c2
|
7
|
+
data.tar.gz: fbdf84e72347070544d30ce16083f778b3dc27cc2d89eeb2db8bebe061ef78e02c0a42602fdf9769a6b225865d5d657d4bb7eccd1977e07bcf9052e9a6c97cc4
|
data/README.md
CHANGED
@@ -9,15 +9,11 @@ Add required dependencies to your application's Gemfile:
|
|
9
9
|
gem "importmap-rails" # NOTE: Probably already installed in default rails 7 project
|
10
10
|
|
11
11
|
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
12
|
-
gem "turbo-rails"
|
12
|
+
gem "turbo-rails"
|
13
13
|
|
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
|
|
@@ -97,9 +93,3 @@ $ ruby ./bin/publish.rb
|
|
97
93
|
## License
|
98
94
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
99
95
|
|
100
|
-
## Problems with turbo-rails 1.4.0
|
101
|
-
|
102
|
-
There is an issue with turbo-rails >= 1.4.0 related to the usage of redirects from a request with a turbo_frame not present on the redirect page.
|
103
|
-
|
104
|
-
Problem: https://github.com/hotwired/turbo-rails/issues/440
|
105
|
-
Possible solution: https://github.com/hotwired/turbo-rails/pull/367
|
@@ -5,6 +5,16 @@ import "bootstrap"
|
|
5
5
|
// Import controllers (stimulus rails)
|
6
6
|
import "controllers"
|
7
7
|
|
8
|
+
/**
|
9
|
+
* Fix form inside turbo-frame tag with redirect
|
10
|
+
* https://github.com/hotwired/turbo-rails/issues/440
|
11
|
+
*/
|
12
|
+
|
13
|
+
document.addEventListener("turbo:frame-missing", event => {
|
14
|
+
event.preventDefault()
|
15
|
+
event.detail.visit(event.detail.response)
|
16
|
+
})
|
17
|
+
|
8
18
|
/**
|
9
19
|
* Manage page transitions
|
10
20
|
*/
|
@@ -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
|
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
|
-
|
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
|
data/app/models/lato/user.rb
CHANGED
@@ -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
|
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
|
-
|
129
|
-
|
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
|
-
|
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
|
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
|
-
|
146
|
-
|
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
|
-
|
164
|
+
c_password_update_code(code)
|
170
165
|
|
171
166
|
true
|
172
167
|
end
|
173
168
|
|
174
169
|
def update_password(params)
|
175
|
-
|
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
|
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
|
-
|
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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregorio Galante
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|