rails_simple_auth 1.0.1 → 1.0.2
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/README.md +77 -5
- data/app/controllers/rails_simple_auth/confirmations_controller.rb +19 -17
- data/app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb +6 -4
- data/app/controllers/rails_simple_auth/passwords_controller.rb +13 -12
- data/app/controllers/rails_simple_auth/registrations_controller.rb +6 -4
- data/app/controllers/rails_simple_auth/sessions_controller.rb +21 -16
- data/app/mailers/rails_simple_auth/auth_mailer.rb +10 -7
- data/app/views/rails_simple_auth/confirmations/new.html.erb +2 -2
- data/app/views/rails_simple_auth/passwords/new.html.erb +2 -2
- data/app/views/rails_simple_auth/registrations/new.html.erb +5 -5
- data/app/views/rails_simple_auth/sessions/magic_link_form.html.erb +2 -2
- data/app/views/rails_simple_auth/sessions/new.html.erb +2 -2
- data/lib/generators/rails_simple_auth/css/css_generator.rb +20 -20
- data/lib/generators/rails_simple_auth/install/install_generator.rb +32 -32
- data/lib/generators/rails_simple_auth/install/templates/initializer.rb +3 -3
- data/lib/generators/rails_simple_auth/install/templates/migration.rb +2 -2
- data/lib/generators/rails_simple_auth/temporary_users/USAGE +21 -0
- data/lib/generators/rails_simple_auth/temporary_users/templates/add_temporary_to_users.rb.erb +8 -0
- data/lib/generators/rails_simple_auth/temporary_users/temporary_users_generator.rb +40 -0
- data/lib/generators/rails_simple_auth/views/views_generator.rb +8 -8
- data/lib/rails_simple_auth/configuration.rb +21 -7
- data/lib/rails_simple_auth/controllers/concerns/authentication.rb +17 -18
- data/lib/rails_simple_auth/controllers/concerns/session_management.rb +24 -0
- data/lib/rails_simple_auth/engine.rb +1 -1
- data/lib/rails_simple_auth/models/concerns/authenticatable.rb +13 -5
- data/lib/rails_simple_auth/models/concerns/confirmable.rb +38 -3
- data/lib/rails_simple_auth/models/concerns/oauth_connectable.rb +5 -5
- data/lib/rails_simple_auth/models/concerns/temporary_user.rb +105 -0
- data/lib/rails_simple_auth/models/session.rb +2 -4
- data/lib/rails_simple_auth/routes.rb +15 -15
- data/lib/rails_simple_auth/version.rb +1 -1
- data/lib/rails_simple_auth.rb +14 -12
- metadata +15 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d9299c78e7be2bfe4bc6e338150d03ec03d80e6c624616e09c30b48c5bf16c6
|
|
4
|
+
data.tar.gz: 145ebfad74f0188f138a9e8e006bfac26a6404b89d3690a0a8484246a5b01d9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92302e8e2c6d489ebda9e82b222e0a53f31c52f0b8958bf3af2a4240f654f0de7bd81892e350ee92892df16d747ef88d4b43ae69b6af0e510ee1504925755693
|
|
7
|
+
data.tar.gz: 07d17cb9ca09fe1f01446cf1faf4cc67fb303d5c0553b6e2c242595054700a88fff187838820aed8639c65b3fd839e3679771acb178700f7966cf17f0f1ce258
|
data/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Simple, secure authentication for Rails 8+ applications. Built on Rails primitiv
|
|
|
9
9
|
- **Email confirmation** with signed tokens
|
|
10
10
|
- **Password reset** with signed tokens
|
|
11
11
|
- **OAuth support** (Google, GitHub, etc.)
|
|
12
|
+
- **Temporary users** (guest mode) with conversion to permanent
|
|
12
13
|
- **Rate limiting** built-in
|
|
13
14
|
- **Session tracking** with IP and user agent
|
|
14
15
|
- **Customizable styling** via CSS variables
|
|
@@ -67,7 +68,7 @@ class CreateUsers < ActiveRecord::Migration[8.0]
|
|
|
67
68
|
def change
|
|
68
69
|
create_table :users do |t|
|
|
69
70
|
# Required by gem
|
|
70
|
-
t.string :
|
|
71
|
+
t.string :email, null: false
|
|
71
72
|
t.string :password_digest, null: false
|
|
72
73
|
t.datetime :confirmed_at # if using Confirmable
|
|
73
74
|
|
|
@@ -81,7 +82,7 @@ class CreateUsers < ActiveRecord::Migration[8.0]
|
|
|
81
82
|
t.timestamps
|
|
82
83
|
end
|
|
83
84
|
|
|
84
|
-
add_index :users, :
|
|
85
|
+
add_index :users, :email, unique: true
|
|
85
86
|
end
|
|
86
87
|
end
|
|
87
88
|
```
|
|
@@ -203,6 +204,77 @@ class User < ApplicationRecord
|
|
|
203
204
|
end
|
|
204
205
|
```
|
|
205
206
|
|
|
207
|
+
## Temporary Users (Guest Mode)
|
|
208
|
+
|
|
209
|
+
Allow visitors to try your app without signing up, then convert to permanent accounts later.
|
|
210
|
+
|
|
211
|
+
### Setup
|
|
212
|
+
|
|
213
|
+
1. Generate the migration:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
rails generate rails_simple_auth:temporary_users
|
|
217
|
+
rails db:migrate
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
2. Include the concern in your User model:
|
|
221
|
+
|
|
222
|
+
```ruby
|
|
223
|
+
class User < ApplicationRecord
|
|
224
|
+
include RailsSimpleAuth::Models::Concerns::Authenticatable
|
|
225
|
+
include RailsSimpleAuth::Models::Concerns::TemporaryUser # Add this
|
|
226
|
+
end
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
3. Enable in configuration:
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
RailsSimpleAuth.configure do |config|
|
|
233
|
+
config.temporary_users_enabled = true
|
|
234
|
+
config.temporary_user_cleanup_days = 7 # Auto-cleanup after 7 days
|
|
235
|
+
end
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Creating Temporary Users
|
|
239
|
+
|
|
240
|
+
```ruby
|
|
241
|
+
# Create a temporary user (no email/password required)
|
|
242
|
+
temp_user = User.create!(
|
|
243
|
+
email: "temp_#{SecureRandom.hex(8)}@temp.local",
|
|
244
|
+
password: SecureRandom.hex(16),
|
|
245
|
+
temporary: true
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Converting to Permanent Account
|
|
250
|
+
|
|
251
|
+
```ruby
|
|
252
|
+
# When user decides to sign up for real
|
|
253
|
+
temp_user.convert_to_permanent!(
|
|
254
|
+
email: "real@example.com",
|
|
255
|
+
password: "secure_password"
|
|
256
|
+
)
|
|
257
|
+
# Sends confirmation email automatically if email confirmation is enabled
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Scopes
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
User.temporary # All temporary users
|
|
264
|
+
User.permanent # All permanent users
|
|
265
|
+
User.temporary_expired # Temporary users older than cleanup_days
|
|
266
|
+
User.temporary_expired(14) # Custom days
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Cleanup Task
|
|
270
|
+
|
|
271
|
+
Add to your scheduler (cron, Sidekiq, etc.):
|
|
272
|
+
|
|
273
|
+
```ruby
|
|
274
|
+
# Delete expired temporary users
|
|
275
|
+
User.temporary_expired.destroy_all
|
|
276
|
+
```
|
|
277
|
+
|
|
206
278
|
## Controller Customization
|
|
207
279
|
|
|
208
280
|
Subclass controllers for custom behavior:
|
|
@@ -266,19 +338,19 @@ class UserMailer < ApplicationMailer
|
|
|
266
338
|
def confirmation(user, token)
|
|
267
339
|
@user = user
|
|
268
340
|
@confirmation_url = edit_confirmation_url(token: token)
|
|
269
|
-
mail(to: user.
|
|
341
|
+
mail(to: user.email, subject: "Confirm your email")
|
|
270
342
|
end
|
|
271
343
|
|
|
272
344
|
def magic_link(user, token)
|
|
273
345
|
@user = user
|
|
274
346
|
@magic_link_url = magic_link_login_url(token: token)
|
|
275
|
-
mail(to: user.
|
|
347
|
+
mail(to: user.email, subject: "Your sign-in link")
|
|
276
348
|
end
|
|
277
349
|
|
|
278
350
|
def password_reset(user, token)
|
|
279
351
|
@user = user
|
|
280
352
|
@reset_url = edit_password_url(token: token)
|
|
281
|
-
mail(to: user.
|
|
353
|
+
mail(to: user.email, subject: "Reset your password")
|
|
282
354
|
end
|
|
283
355
|
end
|
|
284
356
|
```
|
|
@@ -6,33 +6,35 @@ module RailsSimpleAuth
|
|
|
6
6
|
|
|
7
7
|
unless Rails.env.local?
|
|
8
8
|
rate_limit to: 3, within: 1.hour, by: -> { client_ip }, only: :create,
|
|
9
|
-
with:
|
|
9
|
+
with: lambda {
|
|
10
|
+
redirect_to new_confirmation_path, alert: 'Too many confirmation requests. Please try again later.'
|
|
11
|
+
}
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def
|
|
14
|
+
def show
|
|
15
|
+
user = user_class.find_signed(params[:token], purpose: :confirm_email)
|
|
16
|
+
|
|
17
|
+
if user
|
|
18
|
+
user.confirm! if user.respond_to?(:confirm!)
|
|
19
|
+
run_after_confirmation_callback(user)
|
|
20
|
+
redirect_to resolve_path(:after_confirmation_path), notice: 'Email confirmed! You can now sign in.'
|
|
21
|
+
else
|
|
22
|
+
redirect_to new_confirmation_path, alert: 'Invalid or expired confirmation link.'
|
|
23
|
+
end
|
|
13
24
|
end
|
|
14
25
|
|
|
26
|
+
def new; end
|
|
27
|
+
|
|
15
28
|
def create
|
|
16
|
-
user = user_class.
|
|
29
|
+
user = user_class.find_by(email: params[:email])
|
|
17
30
|
|
|
18
|
-
if user
|
|
31
|
+
if user.respond_to?(:unconfirmed_or_reconfirming?) && user.unconfirmed_or_reconfirming?
|
|
19
32
|
token = user.generate_confirmation_token
|
|
20
33
|
RailsSimpleAuth.configuration.mailer.confirmation(user, token).deliver_later
|
|
21
34
|
end
|
|
22
35
|
|
|
23
|
-
redirect_to new_session_path,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def show
|
|
27
|
-
user = user_class.find_signed(params[:token], purpose: :email_confirmation)
|
|
28
|
-
|
|
29
|
-
if user
|
|
30
|
-
user.confirm! if user.respond_to?(:confirm!)
|
|
31
|
-
run_after_confirmation_callback(user)
|
|
32
|
-
redirect_to resolve_path(:after_confirmation_path), notice: "Email confirmed! You can now sign in."
|
|
33
|
-
else
|
|
34
|
-
redirect_to new_confirmation_path, alert: "Invalid or expired confirmation link."
|
|
35
|
-
end
|
|
36
|
+
redirect_to new_session_path,
|
|
37
|
+
notice: 'If an unconfirmed account exists with that email, confirmation instructions have been sent.'
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
private
|
|
@@ -6,27 +6,29 @@ module RailsSimpleAuth
|
|
|
6
6
|
skip_before_action :verify_authenticity_token, only: :create
|
|
7
7
|
|
|
8
8
|
def create
|
|
9
|
-
auth_hash = request.env[
|
|
9
|
+
auth_hash = request.env['omniauth.auth']
|
|
10
10
|
provider = params[:provider]
|
|
11
11
|
|
|
12
12
|
unless RailsSimpleAuth.configuration.oauth_provider_enabled?(provider)
|
|
13
|
-
redirect_to new_session_path, alert:
|
|
13
|
+
redirect_to new_session_path, alert: 'OAuth provider not enabled.'
|
|
14
14
|
return
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
user = user_class.from_oauth(auth_hash)
|
|
18
18
|
|
|
19
19
|
if user&.persisted?
|
|
20
|
+
destroy_temporary_user_session(user)
|
|
20
21
|
create_session_for(user)
|
|
21
22
|
run_after_sign_in_callback(user)
|
|
22
|
-
redirect_to resolve_path(:after_sign_in_path),
|
|
23
|
+
redirect_to resolve_path(:after_sign_in_path),
|
|
24
|
+
notice: "Signed in successfully with #{provider.to_s.capitalize}."
|
|
23
25
|
else
|
|
24
26
|
redirect_to new_session_path, alert: "Could not authenticate with #{provider.to_s.capitalize}."
|
|
25
27
|
end
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def failure
|
|
29
|
-
redirect_to new_session_path, alert:
|
|
31
|
+
redirect_to new_session_path, alert: 'Authentication failed. Please try again.'
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
34
|
end
|
|
@@ -7,31 +7,32 @@ module RailsSimpleAuth
|
|
|
7
7
|
|
|
8
8
|
unless Rails.env.local?
|
|
9
9
|
rate_limit to: 3, within: 1.hour, by: -> { client_ip }, only: :create,
|
|
10
|
-
with:
|
|
10
|
+
with: lambda {
|
|
11
|
+
redirect_to new_password_path, alert: 'Too many password reset requests. Please try again later.'
|
|
12
|
+
}
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def new
|
|
14
|
-
|
|
15
|
+
def new; end
|
|
16
|
+
|
|
17
|
+
def edit; end
|
|
15
18
|
|
|
16
19
|
def create
|
|
17
|
-
user = user_class.
|
|
20
|
+
user = user_class.find_by(email: params[:email])
|
|
18
21
|
|
|
19
22
|
if user && can_reset_password?(user)
|
|
20
23
|
token = user.generate_password_reset_token
|
|
21
24
|
RailsSimpleAuth.configuration.mailer.password_reset(user, token).deliver_later
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
redirect_to new_session_path,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def edit
|
|
27
|
+
redirect_to new_session_path,
|
|
28
|
+
notice: 'If an account exists with that email, password reset instructions have been sent.'
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def update
|
|
31
32
|
ActiveRecord::Base.transaction do
|
|
32
33
|
if @user.update(password_params)
|
|
33
34
|
@user.invalidate_all_sessions!
|
|
34
|
-
redirect_to new_session_path, notice:
|
|
35
|
+
redirect_to new_session_path, notice: 'Password has been reset. Please sign in with your new password.'
|
|
35
36
|
else
|
|
36
37
|
render :edit, status: :unprocessable_content
|
|
37
38
|
raise ActiveRecord::Rollback
|
|
@@ -42,14 +43,14 @@ module RailsSimpleAuth
|
|
|
42
43
|
"[RailsSimpleAuth] Session invalidation failed after password reset for user #{@user.id}: #{e.message}"
|
|
43
44
|
)
|
|
44
45
|
# Password was rolled back due to transaction, redirect with error
|
|
45
|
-
redirect_to new_password_path, alert:
|
|
46
|
+
redirect_to new_password_path, alert: 'Password reset failed. Please try again.'
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
private
|
|
49
50
|
|
|
50
51
|
def set_user_from_token
|
|
51
52
|
@user = user_class.find_signed(params[:token], purpose: :password_reset)
|
|
52
|
-
redirect_to new_password_path, alert:
|
|
53
|
+
redirect_to new_password_path, alert: 'Invalid or expired password reset link.' unless @user
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
def can_reset_password?(user)
|
|
@@ -60,7 +61,7 @@ module RailsSimpleAuth
|
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
def password_params
|
|
63
|
-
params.
|
|
64
|
+
params.expect(user: %i[password password_confirmation])
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
end
|
|
@@ -6,7 +6,7 @@ module RailsSimpleAuth
|
|
|
6
6
|
|
|
7
7
|
unless Rails.env.local?
|
|
8
8
|
rate_limit to: 5, within: 1.hour, by: -> { client_ip }, only: :create,
|
|
9
|
-
with: -> { redirect_to sign_up_path, alert:
|
|
9
|
+
with: -> { redirect_to sign_up_path, alert: 'Too many sign up attempts. Please try again later.' }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def new
|
|
@@ -27,18 +27,20 @@ module RailsSimpleAuth
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
29
|
def registration_params
|
|
30
|
-
params.
|
|
30
|
+
params.expect(user: %i[email password])
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def after_successful_registration
|
|
34
|
+
destroy_temporary_user_session(@user)
|
|
35
|
+
|
|
34
36
|
if RailsSimpleAuth.configuration.email_confirmation_enabled
|
|
35
37
|
send_confirmation_email(@user)
|
|
36
38
|
run_after_sign_up_callback(@user)
|
|
37
|
-
redirect_to new_session_path, notice:
|
|
39
|
+
redirect_to new_session_path, notice: 'Account created! Please check your email to confirm your account.'
|
|
38
40
|
else
|
|
39
41
|
create_session_for(@user)
|
|
40
42
|
run_after_sign_up_callback(@user)
|
|
41
|
-
redirect_to resolve_path(:after_sign_up_path), notice:
|
|
43
|
+
redirect_to resolve_path(:after_sign_up_path), notice: 'Account created successfully!'
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
@@ -8,13 +8,17 @@ module RailsSimpleAuth
|
|
|
8
8
|
|
|
9
9
|
unless Rails.env.local?
|
|
10
10
|
rate_limit to: 5, within: 15.minutes, by: -> { client_ip }, only: :create,
|
|
11
|
-
with: -> { redirect_to new_session_path, alert:
|
|
11
|
+
with: -> { redirect_to new_session_path, alert: 'Too many login attempts. Please try again later.' }
|
|
12
12
|
|
|
13
|
-
rate_limit to: 3, within: 10.minutes, by: -> { params[:
|
|
14
|
-
with:
|
|
13
|
+
rate_limit to: 3, within: 10.minutes, by: -> { params[:email].to_s.downcase }, only: :request_magic_link,
|
|
14
|
+
with: lambda {
|
|
15
|
+
redirect_to new_session_path, alert: 'Too many magic link requests. Please try again later.'
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
rate_limit to: 5, within: 15.minutes, by: -> { client_ip }, only: :magic_link_login,
|
|
17
|
-
with:
|
|
19
|
+
with: lambda {
|
|
20
|
+
redirect_to new_session_path, alert: 'Too many magic link attempts. Please try again later.'
|
|
21
|
+
}
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
def new
|
|
@@ -22,20 +26,20 @@ module RailsSimpleAuth
|
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def create
|
|
25
|
-
user = user_class.
|
|
29
|
+
user = user_class.find_by(email: params[:email]) || user_class.new(password: SecureRandom.hex(32))
|
|
26
30
|
|
|
27
31
|
if user.authenticate(params[:password]) && user.persisted?
|
|
28
32
|
if confirmation_required_for?(user)
|
|
29
|
-
@error_message =
|
|
30
|
-
@previous_email = params[:
|
|
33
|
+
@error_message = 'Please confirm your email before signing in.'
|
|
34
|
+
@previous_email = params[:email]
|
|
31
35
|
render :new, status: :unprocessable_content
|
|
32
36
|
else
|
|
33
37
|
sign_in_and_redirect(user)
|
|
34
38
|
end
|
|
35
39
|
else
|
|
36
|
-
Rails.logger.warn("Failed login attempt for email: #{params[:
|
|
37
|
-
@error_message =
|
|
38
|
-
@previous_email = params[:
|
|
40
|
+
Rails.logger.warn("Failed login attempt for email: #{params[:email]} from IP: #{client_ip}")
|
|
41
|
+
@error_message = 'Invalid email or password'
|
|
42
|
+
@previous_email = params[:email]
|
|
39
43
|
render :new, status: :unprocessable_content
|
|
40
44
|
end
|
|
41
45
|
end
|
|
@@ -44,7 +48,7 @@ module RailsSimpleAuth
|
|
|
44
48
|
user = current_user
|
|
45
49
|
destroy_current_session
|
|
46
50
|
run_after_sign_out_callback(user) if user
|
|
47
|
-
redirect_to resolve_path(:after_sign_out_path), notice:
|
|
51
|
+
redirect_to resolve_path(:after_sign_out_path), notice: 'Signed out successfully.'
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
def magic_link_form
|
|
@@ -52,14 +56,14 @@ module RailsSimpleAuth
|
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
def request_magic_link
|
|
55
|
-
user = user_class.
|
|
59
|
+
user = user_class.find_by(email: params[:email])
|
|
56
60
|
|
|
57
|
-
if user
|
|
61
|
+
if user.respond_to?(:generate_magic_link_token)
|
|
58
62
|
token = user.generate_magic_link_token
|
|
59
63
|
RailsSimpleAuth.configuration.mailer.magic_link(user, token).deliver_later
|
|
60
64
|
end
|
|
61
65
|
|
|
62
|
-
redirect_to new_session_path, notice:
|
|
66
|
+
redirect_to new_session_path, notice: 'If an account exists with that email, a magic link has been sent.'
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
def magic_link_login
|
|
@@ -69,7 +73,7 @@ module RailsSimpleAuth
|
|
|
69
73
|
user.confirm! if user.respond_to?(:confirm!) && user.respond_to?(:unconfirmed?) && user.unconfirmed?
|
|
70
74
|
sign_in_and_redirect(user)
|
|
71
75
|
else
|
|
72
|
-
redirect_to new_session_path, alert:
|
|
76
|
+
redirect_to new_session_path, alert: 'Invalid or expired magic link.'
|
|
73
77
|
end
|
|
74
78
|
end
|
|
75
79
|
|
|
@@ -82,9 +86,10 @@ module RailsSimpleAuth
|
|
|
82
86
|
end
|
|
83
87
|
|
|
84
88
|
def sign_in_and_redirect(user)
|
|
89
|
+
destroy_temporary_user_session(user)
|
|
85
90
|
create_session_for(user)
|
|
86
91
|
run_after_sign_in_callback(user)
|
|
87
|
-
redirect_to stored_location_or_default, notice:
|
|
92
|
+
redirect_to stored_location_or_default, notice: 'Signed in successfully.'
|
|
88
93
|
end
|
|
89
94
|
end
|
|
90
95
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RailsSimpleAuth
|
|
4
|
-
class AuthMailer <
|
|
4
|
+
class AuthMailer < ApplicationMailer
|
|
5
5
|
default from: -> { RailsSimpleAuth.configuration.mailer_sender }
|
|
6
6
|
|
|
7
7
|
def confirmation(user, token)
|
|
@@ -9,9 +9,12 @@ module RailsSimpleAuth
|
|
|
9
9
|
@token = token
|
|
10
10
|
@confirmation_url = main_app.confirmation_url(token: token)
|
|
11
11
|
|
|
12
|
+
# Use confirmable_email for reconfirmation (email change) scenarios
|
|
13
|
+
recipient = user.respond_to?(:confirmable_email) ? user.confirmable_email : user.email
|
|
14
|
+
|
|
12
15
|
mail(
|
|
13
|
-
to:
|
|
14
|
-
subject:
|
|
16
|
+
to: recipient,
|
|
17
|
+
subject: 'Confirm your email'
|
|
15
18
|
)
|
|
16
19
|
end
|
|
17
20
|
|
|
@@ -21,8 +24,8 @@ module RailsSimpleAuth
|
|
|
21
24
|
@magic_link_url = main_app.magic_link_url(token: token)
|
|
22
25
|
|
|
23
26
|
mail(
|
|
24
|
-
to: user.
|
|
25
|
-
subject:
|
|
27
|
+
to: user.email,
|
|
28
|
+
subject: 'Sign in to your account'
|
|
26
29
|
)
|
|
27
30
|
end
|
|
28
31
|
|
|
@@ -32,8 +35,8 @@ module RailsSimpleAuth
|
|
|
32
35
|
@password_reset_url = main_app.edit_password_url(token: token)
|
|
33
36
|
|
|
34
37
|
mail(
|
|
35
|
-
to: user.
|
|
36
|
-
subject:
|
|
38
|
+
to: user.email,
|
|
39
|
+
subject: 'Reset your password'
|
|
37
40
|
)
|
|
38
41
|
end
|
|
39
42
|
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
<%= form_with url: main_app.confirmations_path, class: "rsa-auth-form__form" do |form| %>
|
|
10
10
|
<div class="rsa-auth-form__group">
|
|
11
|
-
<%= form.label :
|
|
12
|
-
<%= form.email_field :
|
|
11
|
+
<%= form.label :email, "Email", class: "rsa-auth-form__label" %>
|
|
12
|
+
<%= form.email_field :email,
|
|
13
13
|
class: "rsa-auth-form__input",
|
|
14
14
|
required: true,
|
|
15
15
|
autofocus: true %>
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
<%= form_with url: main_app.passwords_path, class: "rsa-auth-form__form" do |form| %>
|
|
10
10
|
<div class="rsa-auth-form__group">
|
|
11
|
-
<%= form.label :
|
|
12
|
-
<%= form.email_field :
|
|
11
|
+
<%= form.label :email, "Email", class: "rsa-auth-form__label" %>
|
|
12
|
+
<%= form.email_field :email,
|
|
13
13
|
class: "rsa-auth-form__input",
|
|
14
14
|
required: true,
|
|
15
15
|
autofocus: true %>
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
<%= form_with model: @user, url: main_app.sign_up_path, class: "rsa-auth-form__form" do |form| %>
|
|
6
6
|
<div class="rsa-auth-form__group">
|
|
7
|
-
<%= form.label :
|
|
8
|
-
<%= form.email_field :
|
|
9
|
-
class: "rsa-auth-form__input #{@user.errors[:
|
|
7
|
+
<%= form.label :email, "Email", class: "rsa-auth-form__label" %>
|
|
8
|
+
<%= form.email_field :email,
|
|
9
|
+
class: "rsa-auth-form__input #{@user.errors[:email].any? ? 'rsa-auth-form__input--error' : ''}",
|
|
10
10
|
required: true,
|
|
11
11
|
autofocus: true %>
|
|
12
|
-
<% if @user.errors[:
|
|
13
|
-
<p class="rsa-auth-form__error"><%= @user.errors[:
|
|
12
|
+
<% if @user.errors[:email].any? %>
|
|
13
|
+
<p class="rsa-auth-form__error"><%= @user.errors[:email].first %></p>
|
|
14
14
|
<% end %>
|
|
15
15
|
</div>
|
|
16
16
|
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
<%= form_with url: main_app.request_magic_link_path, class: "rsa-auth-form__form" do |form| %>
|
|
10
10
|
<div class="rsa-auth-form__group">
|
|
11
|
-
<%= form.label :
|
|
12
|
-
<%= form.email_field :
|
|
11
|
+
<%= form.label :email, "Email", class: "rsa-auth-form__label" %>
|
|
12
|
+
<%= form.email_field :email,
|
|
13
13
|
class: "rsa-auth-form__input",
|
|
14
14
|
required: true,
|
|
15
15
|
autofocus: true %>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
<%= form_with url: main_app.session_path, class: "rsa-auth-form__form" do |form| %>
|
|
6
6
|
<div class="rsa-auth-form__group">
|
|
7
|
-
<%= form.label :
|
|
8
|
-
<%= form.email_field :
|
|
7
|
+
<%= form.label :email, "Email", class: "rsa-auth-form__label" %>
|
|
8
|
+
<%= form.email_field :email,
|
|
9
9
|
class: "rsa-auth-form__input #{@error_message.present? ? 'rsa-auth-form__input--error' : ''}",
|
|
10
10
|
required: true,
|
|
11
11
|
autofocus: true,
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'rails/generators'
|
|
4
4
|
|
|
5
5
|
module RailsSimpleAuth
|
|
6
6
|
module Generators
|
|
7
7
|
class CssGenerator < Rails::Generators::Base
|
|
8
|
-
source_root File.expand_path(
|
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
|
9
9
|
|
|
10
|
-
class_option :path, type: :string, default:
|
|
11
|
-
|
|
10
|
+
class_option :path, type: :string, default: 'app/assets/stylesheets',
|
|
11
|
+
desc: 'Path to copy CSS to'
|
|
12
12
|
|
|
13
13
|
def copy_css
|
|
14
|
-
template
|
|
14
|
+
template 'rails_simple_auth.css', "#{options[:path]}/rails_simple_auth.css"
|
|
15
15
|
|
|
16
|
-
say
|
|
16
|
+
say ''
|
|
17
17
|
say "CSS copied to #{options[:path]}/rails_simple_auth.css", :green
|
|
18
|
-
say
|
|
19
|
-
say
|
|
20
|
-
say
|
|
21
|
-
say
|
|
18
|
+
say ''
|
|
19
|
+
say 'To use this CSS:'
|
|
20
|
+
say ''
|
|
21
|
+
say ' 1. Include in your application.css or layout:'
|
|
22
22
|
say " <%= stylesheet_link_tag 'rails_simple_auth' %>"
|
|
23
|
-
say
|
|
24
|
-
say
|
|
25
|
-
say
|
|
26
|
-
say
|
|
27
|
-
say
|
|
28
|
-
say
|
|
29
|
-
say
|
|
30
|
-
say
|
|
31
|
-
say
|
|
32
|
-
say
|
|
23
|
+
say ''
|
|
24
|
+
say ' 2. Customize by overriding CSS variables in your own stylesheet:'
|
|
25
|
+
say ''
|
|
26
|
+
say ' :root {'
|
|
27
|
+
say ' --rsa-color-primary: #your-brand-color;'
|
|
28
|
+
say ' --rsa-color-background-form: #your-form-bg;'
|
|
29
|
+
say ' }'
|
|
30
|
+
say ''
|
|
31
|
+
say ' 3. Or edit rails_simple_auth.css directly.'
|
|
32
|
+
say ''
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|