lato 0.1.58 → 0.1.60
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c9eb96e4d8465b539ddee7df568a3b9c37bdfb55e9b8b24ad3c5969a53c0e32
|
|
4
|
+
data.tar.gz: b31a028a5f3dbdf18ba8f846bb0636ee77e967a1b96ebd858fef93cd882ec0d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d150983fdebfba187569b988f957ca111030bc5617a64338cb90f13a9a4c635ab6fd10b88ada8f396615adb7d13cbf1bcef38decd9453962eb39bb16524864fb
|
|
7
|
+
data.tar.gz: 8ddff51d4154bf41ee332bb6b8cd8eefcb7ad2c3d70040b2eebaeedd97fe4bdd602188750b36e6febaed02c8d225d385b455e62e21e8ffdd2ab5836d2f312950
|
|
@@ -30,6 +30,22 @@ module Lato
|
|
|
30
30
|
false
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def limit_requests(limit = 10, time_window = 10.minutes)
|
|
34
|
+
cache_key = "Lato::Sessionable/limit_requests/#{controller_name}/#{action_name}/#{request.remote_ip}"
|
|
35
|
+
attempts = Rails.cache.read(cache_key) || 0
|
|
36
|
+
|
|
37
|
+
attempts += 1
|
|
38
|
+
Rails.cache.write(cache_key, attempts, expires_in: time_window)
|
|
39
|
+
return true unless attempts >= limit
|
|
40
|
+
|
|
41
|
+
respond_to do |format|
|
|
42
|
+
format.html { render plain: "Too many requests, please wait #{time_window.to_i / 60} minutes to retry.", status: :too_many_requests }
|
|
43
|
+
format.json { render json: {}, status: :too_many_requests }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
false
|
|
47
|
+
end
|
|
48
|
+
|
|
33
49
|
def session_create(user_id)
|
|
34
50
|
cookies.encrypted[:lato_session] = { value: Lato::Session.generate_session_per_user(user_id), expires: Lato.config.session_lifetime.from_now }
|
|
35
51
|
@session = Lato::Session.new(cookies.encrypted[:lato_session])
|
|
@@ -4,6 +4,7 @@ module Lato
|
|
|
4
4
|
include Lato::Layoutable
|
|
5
5
|
include Lato::Componentable
|
|
6
6
|
|
|
7
|
+
before_action :override_request_remote_ip
|
|
7
8
|
before_action :set_default_locale
|
|
8
9
|
|
|
9
10
|
def index
|
|
@@ -19,6 +20,15 @@ module Lato
|
|
|
19
20
|
|
|
20
21
|
protected
|
|
21
22
|
|
|
23
|
+
# This method override the request remote ip with the X-Forwarded-For header if exists.
|
|
24
|
+
# This method is used to get the real ip of the user when the application is behind a proxy.
|
|
25
|
+
# For example if the application is behind a nginx proxy the request.remote_ip will be the ip of the proxy and not the ip of the user.
|
|
26
|
+
def override_request_remote_ip
|
|
27
|
+
request.remote_ip = request.headers['X-Forwarded-For'] if request.headers['X-Forwarded-For']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# This method set the default locale for the application.
|
|
31
|
+
# The default locale is the locale of the user if exists, otherwise is the default locale of the application.
|
|
22
32
|
def set_default_locale
|
|
23
33
|
return unless @session.valid?
|
|
24
34
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
module Lato
|
|
2
2
|
class AuthenticationController < ApplicationController
|
|
3
|
+
before_action :limit_requests, only: %i[signin_action signup_action accept_invitation_action recover_password_action update_password_action]
|
|
3
4
|
before_action :not_authenticate_session, only: %i[signin signin_action signup signup_action accept_invitation accept_invitation_action]
|
|
4
5
|
before_action :authenticate_session, only: %i[signout signout_action]
|
|
5
6
|
|
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.1.60
|
|
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-08-
|
|
11
|
+
date: 2023-08-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|