revise_auth 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/controllers/revise_auth/registrations_controller.rb +1 -4
- data/app/controllers/revise_auth/sessions_controller.rb +4 -6
- data/app/controllers/revise_auth_controller.rb +0 -5
- data/app/views/revise_auth/registrations/new.html.erb +1 -2
- data/config/i18n-tasks.yml +3 -2
- data/config/locales/cs.yml +1 -0
- data/config/locales/de.yml +1 -0
- data/config/locales/el.yml +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/fr.yml +1 -0
- data/config/locales/nl.yml +1 -0
- data/config/locales/pt.yml +1 -0
- data/config/locales/tr.yml +1 -0
- data/config/locales/zh-TW.yml +1 -0
- data/lib/revise_auth/authentication.rb +25 -5
- data/lib/revise_auth/version.rb +1 -1
- data/lib/revise_auth.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71fda2f113599eedcf1149b7875e3ed902a34f25612b357090997f9dbef2755c
|
4
|
+
data.tar.gz: a0c7efefe1c554681d61dcecd319c0b13a8db42dc10e5e67ca7f252e39940413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50583c21daaa058fe253945ce034b04742126a665a31dfb1a56219c45ee7199b521f7af006fffe833e7ccb4b4f4c6b356aff3604479306c6dea121d9adddbdbd
|
7
|
+
data.tar.gz: e7debb89b6652c443c8c07f3c8ad9cb594faaa9748ffb6f8ebb5f04205a8494f9fbca9293b183941831473134969a604ad1a1bc909f73a26106183769cbe7be5
|
data/README.md
CHANGED
@@ -63,6 +63,17 @@ revise_auth
|
|
63
63
|
|
64
64
|
You will want to define a root path. After login (see below), the user will be redirected to the root path.
|
65
65
|
|
66
|
+
### Views
|
67
|
+
|
68
|
+
ReviseAuth uses the flash to display notices and alerts, so make sure flash messages are rendered by your application:
|
69
|
+
|
70
|
+
```erb
|
71
|
+
<%# views/layouts/application.html.erb %>
|
72
|
+
|
73
|
+
<%= tag.div notice if notice %>
|
74
|
+
<%= tag.div alert if alert %>
|
75
|
+
```
|
76
|
+
|
66
77
|
### Filters and Helpers
|
67
78
|
|
68
79
|
To protect your actions from unauthenticated users, you can use the `authenticate_user!` filter:
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class ReviseAuth::RegistrationsController < ReviseAuthController
|
2
2
|
before_action :authenticate_user!, except: [:new, :create]
|
3
|
+
before_action :require_unauthenticated, only: [:new, :create]
|
3
4
|
|
4
5
|
def new
|
5
6
|
@user = User.new
|
@@ -41,8 +42,4 @@ class ReviseAuth::RegistrationsController < ReviseAuthController
|
|
41
42
|
def profile_params
|
42
43
|
params.require(:user).permit(ReviseAuth.update_params)
|
43
44
|
end
|
44
|
-
|
45
|
-
def resolve_after_register_path
|
46
|
-
try(:after_register_path) || return_to_location || root_path
|
47
|
-
end
|
48
45
|
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
class ReviseAuth::SessionsController < ReviseAuthController
|
2
|
+
before_action :require_unauthenticated, only: [:new, :create]
|
3
|
+
|
4
|
+
rate_limit(**ReviseAuth.login_rate_limit) if respond_to?(:rate_limit) && ReviseAuth.login_rate_limit.present?
|
5
|
+
|
2
6
|
def new
|
3
7
|
end
|
4
8
|
|
@@ -16,10 +20,4 @@ class ReviseAuth::SessionsController < ReviseAuthController
|
|
16
20
|
logout
|
17
21
|
redirect_to root_path
|
18
22
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def resolve_after_login_path
|
23
|
-
try(:after_login_path) || return_to_location || root_path
|
24
|
-
end
|
25
23
|
end
|
data/config/i18n-tasks.yml
CHANGED
data/config/locales/cs.yml
CHANGED
data/config/locales/de.yml
CHANGED
data/config/locales/el.yml
CHANGED
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
data/config/locales/fr.yml
CHANGED
data/config/locales/nl.yml
CHANGED
data/config/locales/pt.yml
CHANGED
data/config/locales/tr.yml
CHANGED
data/config/locales/zh-TW.yml
CHANGED
@@ -9,6 +9,12 @@ module ReviseAuth
|
|
9
9
|
helper_method :current_user
|
10
10
|
end
|
11
11
|
|
12
|
+
class_methods do
|
13
|
+
def authenticate_user!(with: :login, return_to: true, **options)
|
14
|
+
before_action -> { authenticate_user!(with: with, return_to: return_to) }, **options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
# Returns a boolean whether the user is signed in or not
|
13
19
|
def user_signed_in?
|
14
20
|
!!current_user
|
@@ -21,8 +27,15 @@ module ReviseAuth
|
|
21
27
|
end
|
22
28
|
|
23
29
|
# Authenticates a user or redirects to the login page
|
24
|
-
def authenticate_user!
|
25
|
-
|
30
|
+
def authenticate_user!(with: :login, return_to: true)
|
31
|
+
return if user_signed_in?
|
32
|
+
stash_return_to_location(request.fullpath) if return_to && request.get?
|
33
|
+
path = (with == :sign_up) ? sign_up_path : login_path
|
34
|
+
redirect_to path, alert: t("revise_auth.sign_up_or_login")
|
35
|
+
end
|
36
|
+
|
37
|
+
def require_unauthenticated
|
38
|
+
redirect_to resolve_after_login_path, alert: t("revise_auth.shared.already_authenticated") if user_signed_in?
|
26
39
|
end
|
27
40
|
|
28
41
|
# Authenticates the current user
|
@@ -61,9 +74,16 @@ module ReviseAuth
|
|
61
74
|
session[:user_return_to] = path
|
62
75
|
end
|
63
76
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
77
|
+
def return_to_location
|
78
|
+
session.delete(:user_return_to)
|
79
|
+
end
|
80
|
+
|
81
|
+
def resolve_after_register_path
|
82
|
+
try(:after_register_path) || return_to_location || root_path
|
83
|
+
end
|
84
|
+
|
85
|
+
def resolve_after_login_path
|
86
|
+
try(:after_login_path) || return_to_location || root_path
|
67
87
|
end
|
68
88
|
|
69
89
|
# Return true if it's a revise_auth_controller. false to all controllers unless
|
data/lib/revise_auth/version.rb
CHANGED
data/lib/revise_auth.rb
CHANGED
@@ -17,4 +17,5 @@ module ReviseAuth
|
|
17
17
|
config_accessor :sign_up_params, default: [:email, :password, :password_confirmation]
|
18
18
|
config_accessor :update_params, default: []
|
19
19
|
config_accessor :minimum_password_length, default: 12
|
20
|
+
config_accessor :login_rate_limit, default: {to: 10, within: 3.minutes, only: :create}
|
20
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revise_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.5.
|
112
|
+
rubygems_version: 3.5.16
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Simple authentication for Ruby on Rails apps
|