lato 0.1.58 → 0.1.59
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cc5abe2007e8028c5de1b2e4f76a4a9b93412e862059cb69b36e4940a37650f
|
4
|
+
data.tar.gz: d89a0f0b13c2e994c063f6659f8e4456bbc695e701b0934d5686be005f0ca618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582c91f202e59201d654e1f3582070ee8c8a43797d44ca5c387a2732220b48c34487856175748eb4be480f418f94be3c4ee1abc03e601fbffef2b267f08957bd
|
7
|
+
data.tar.gz: e3798419615b5a8ac29ba9e824ca2fa6fa030567902edda06e1ac0d890d36c57db14f878f3da75a498ee6238d32e796d04d43310d1f027f700a62fd2c3bd74e8
|
@@ -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,12 +20,37 @@ 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
|
|
25
35
|
I18n.locale = @session.user.locale || I18n.default_locale
|
26
36
|
end
|
27
37
|
|
38
|
+
# This method limit the number of requests for a specific action.
|
39
|
+
# Usage: before_action :limit_requests, only: %i[:action_name]
|
40
|
+
def limit_requests(limit = 10, time_window = 10.minutes)
|
41
|
+
cache_key = "Lato::ApplicationController.limit_requests/#{controller_name}/#{action_name}/#{request.remote_ip}"
|
42
|
+
attempts = Rails.cache.read(cache_key) || 0
|
43
|
+
|
44
|
+
attempts += 1
|
45
|
+
Rails.cache.write(cache_key, attempts, expires_in: time_window)
|
46
|
+
return unless attempts >= limit
|
47
|
+
|
48
|
+
respond_to do |format|
|
49
|
+
format.html { render plain: "Too many requests, please wait #{time_window.to_i / 60} minutes to retry.", status: :too_many_requests }
|
50
|
+
format.json { render json: {}, status: :too_many_requests }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
28
54
|
def respond_to_with_not_found
|
29
55
|
respond_to do |format|
|
30
56
|
format.html { render plain: '', status: :not_found }
|
@@ -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.59
|
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
|