rails_simple_auth 1.0.5 → 1.0.7
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 +4 -4
- data/CHANGELOG.md +21 -0
- data/app/controllers/rails_simple_auth/sessions_controller.rb +6 -2
- data/lib/generators/rails_simple_auth/temporary_users/templates/add_temporary_to_users.rb.erb +1 -0
- data/lib/rails_simple_auth/controllers/concerns/authentication.rb +31 -0
- data/lib/rails_simple_auth/controllers/concerns/session_management.rb +1 -1
- data/lib/rails_simple_auth/models/concerns/temporary_user.rb +1 -1
- data/lib/rails_simple_auth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a168e835a568c68794da8d69b24fe33d8a99ece8e14277e3676668ae62d0d284
|
|
4
|
+
data.tar.gz: e8d4947a07f36d2f9f9a45ed0d8b98966adb8e1d4084657da00ee7050393c56b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc07416640d3ae37febfce98d74ab212b35469ff29145441cb1ed0c260e7ac4e0eafa3d2edbc870fb46d30c847d9669ce5be6b4135ba677bb4fafe5855c44b31
|
|
7
|
+
data.tar.gz: 0d5ce6bddec0962b6f4d065cc72b9b88772c25326bbfcefc0dc28b3b61739419ea12ed0538ab59be8b18da233054fc2a8d87625959f77e571a54d7dd27834e59
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.7] - 2026-01-19
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **Temporary users can now access sign-in page** - Previously, temporary users clicking "Sign in" were redirected away because `user_signed_in?` returned true. Now checks `permanent_user_signed_in?` instead, allowing temporary users to sign in with a real account.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Referrer-based redirect after sign-in** - When users voluntarily click "Sign in" (not forced by `require_authentication`), their referring page is stored so they're redirected back after signing in. Security: only stores referrer from same origin.
|
|
19
|
+
- `permanent_user_signed_in?` helper method - Returns true only if user is signed in AND permanent (or doesn't respond to `permanent?`)
|
|
20
|
+
|
|
21
|
+
## [1.0.6] - 2025-01-19
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- **Database-level email uniqueness** - Partial unique index ensures permanent users have unique emails at database level (not just Rails validation)
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Simplified `temporary?` method for cleaner implementation
|
|
30
|
+
|
|
10
31
|
## [1.0.5] - 2025-01-19
|
|
11
32
|
|
|
12
33
|
### Added
|
|
@@ -22,7 +22,9 @@ module RailsSimpleAuth
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def new
|
|
25
|
-
redirect_to resolve_path(:after_sign_in_path) if
|
|
25
|
+
return redirect_to resolve_path(:after_sign_in_path) if permanent_user_signed_in?
|
|
26
|
+
|
|
27
|
+
store_referrer_for_redirect
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def create
|
|
@@ -52,7 +54,9 @@ module RailsSimpleAuth
|
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
def magic_link_form
|
|
55
|
-
redirect_to resolve_path(:after_sign_in_path) if
|
|
57
|
+
return redirect_to resolve_path(:after_sign_in_path) if permanent_user_signed_in?
|
|
58
|
+
|
|
59
|
+
store_referrer_for_redirect
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
def request_magic_link
|
data/lib/generators/rails_simple_auth/temporary_users/templates/add_temporary_to_users.rb.erb
CHANGED
|
@@ -4,5 +4,6 @@ class AddTemporaryToUsers < ActiveRecord::Migration[<%= Rails::VERSION::MAJOR %>
|
|
|
4
4
|
def change
|
|
5
5
|
add_column :users, :temporary, :boolean, default: false, null: false
|
|
6
6
|
add_index :users, [:temporary, :created_at], name: "index_users_on_temporary_and_created_at"
|
|
7
|
+
add_index :users, :email_address, unique: true, where: "temporary = false", name: "index_users_on_email_address_permanent_unique"
|
|
7
8
|
end
|
|
8
9
|
end
|
|
@@ -44,6 +44,10 @@ module RailsSimpleAuth
|
|
|
44
44
|
current_user.present?
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def permanent_user_signed_in?
|
|
48
|
+
user_signed_in? && (!current_user.respond_to?(:permanent?) || current_user.permanent?)
|
|
49
|
+
end
|
|
50
|
+
|
|
47
51
|
def store_location_for_redirect
|
|
48
52
|
return unless request.get?
|
|
49
53
|
|
|
@@ -57,6 +61,33 @@ module RailsSimpleAuth
|
|
|
57
61
|
session[:return_to] = path
|
|
58
62
|
end
|
|
59
63
|
|
|
64
|
+
def store_referrer_for_redirect
|
|
65
|
+
# Don't overwrite existing stored location (e.g., from require_authentication)
|
|
66
|
+
return if session[:return_to].present?
|
|
67
|
+
|
|
68
|
+
referrer = request.referer
|
|
69
|
+
return if referrer.blank?
|
|
70
|
+
|
|
71
|
+
# SECURITY: Only store referrer if it's from the same origin
|
|
72
|
+
begin
|
|
73
|
+
referrer_uri = URI.parse(referrer)
|
|
74
|
+
request_uri = URI.parse(request.url)
|
|
75
|
+
|
|
76
|
+
return unless referrer_uri.host == request_uri.host
|
|
77
|
+
|
|
78
|
+
path = referrer_uri.path
|
|
79
|
+
path += "?#{referrer_uri.query}" if referrer_uri.query.present?
|
|
80
|
+
|
|
81
|
+
# SECURITY: Validate path to prevent open redirect attacks
|
|
82
|
+
return unless path.start_with?('/')
|
|
83
|
+
return if path.start_with?('//')
|
|
84
|
+
|
|
85
|
+
session[:return_to] = path
|
|
86
|
+
rescue URI::InvalidURIError
|
|
87
|
+
# Invalid referrer, ignore
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
60
91
|
def stored_location_or_default
|
|
61
92
|
session.delete(:return_to) || resolve_path(:after_sign_in_path)
|
|
62
93
|
end
|
|
@@ -58,7 +58,7 @@ module RailsSimpleAuth
|
|
|
58
58
|
temp_user.destroy!
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
Rails.logger.info
|
|
61
|
+
Rails.logger.info "[RailsSimpleAuth] Destroyed temporary user #{temp_user_id} on sign in"
|
|
62
62
|
rescue ActiveRecord::RecordNotDestroyed => e
|
|
63
63
|
Rails.logger.error("[RailsSimpleAuth] Failed to destroy temporary user #{temp_user_id}: #{e.message}")
|
|
64
64
|
end
|