action_auth 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/controllers/action_auth/identity/email_verifications_controller.rb +29 -0
- data/app/controllers/action_auth/identity/emails_controller.rb +41 -0
- data/app/controllers/action_auth/identity/password_resets_controller.rb +46 -0
- data/app/controllers/action_auth/passwords_controller.rb +1 -1
- data/app/controllers/action_auth/registrations_controller.rb +1 -1
- data/app/controllers/action_auth/sessions_controller.rb +1 -0
- data/app/views/action_auth/identity/emails/edit.html.erb +43 -0
- data/app/views/action_auth/identity/password_resets/edit.html.erb +32 -0
- data/app/views/action_auth/identity/password_resets/new.html.erb +14 -0
- data/app/views/action_auth/passwords/edit.html.erb +1 -1
- data/config/routes.rb +5 -0
- data/lib/action_auth/controllers/helpers.rb +0 -1
- data/lib/action_auth/engine.rb +1 -0
- data/lib/action_auth/routing/helpers.rb +8 -0
- data/lib/action_auth/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3745646b8654c9678ab57b1539e7190f3c002f3352dda31cf06a884604f2dfdd
|
4
|
+
data.tar.gz: 92f62b3fd0607982f545408db8196f6b24ba43b63df5b166f0262daa77a00013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f422203f6efa8a50d9de3140b0f97ad6eabe7a2d17bf79d36d352e41a08a20fe0bd23ab3f4587563655a2fb52ffc0800d5d1a783f97161a5b773d1df4647c751
|
7
|
+
data.tar.gz: 618b27e2c259afcd7018595087fa10cb828d38dee863b3d76f67dfff2f2e37e086bc6c240494769990265130831cd839c46c6edaf43a0c6051c4f58b2f852d4f
|
data/README.md
CHANGED
@@ -8,6 +8,13 @@ Add this line to your application's Gemfile:
|
|
8
8
|
bundle add action_auth
|
9
9
|
bin/rails action_auth:install:migrations
|
10
10
|
```
|
11
|
+
|
12
|
+
Modify config/routes.rb to include the following:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
mount ActionAuth::Engine => 'action_auth'
|
16
|
+
```
|
17
|
+
|
11
18
|
## Usage
|
12
19
|
|
13
20
|
### Routes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActionAuth
|
2
|
+
module Identity
|
3
|
+
class EmailVerificationsController < ApplicationController
|
4
|
+
before_action :set_user, only: :show
|
5
|
+
|
6
|
+
def show
|
7
|
+
@user.update! verified: true
|
8
|
+
redirect_to main_app.root_path, notice: "Thank you for verifying your email address"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
send_email_verification
|
13
|
+
redirect_to main_app.root_path, notice: "We sent a verification email to your email address"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_user
|
19
|
+
@user = ActionAuth::User.find_by_token_for!(:email_verification, params[:sid])
|
20
|
+
rescue StandardError
|
21
|
+
redirect_to edit_identity_email_path, alert: "That email verification link is invalid"
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_email_verification
|
25
|
+
UserMailer.with(user: Current.user).email_verification.deliver_later
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActionAuth
|
2
|
+
module Identity
|
3
|
+
class EmailsController < ApplicationController
|
4
|
+
before_action :set_user
|
5
|
+
|
6
|
+
def edit
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
if @user.update(user_params)
|
11
|
+
redirect_to_root
|
12
|
+
else
|
13
|
+
render :edit, status: :unprocessable_entity
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_user
|
20
|
+
@user = Current.user
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_params
|
24
|
+
params.permit(:email, :password_challenge).with_defaults(password_challenge: "")
|
25
|
+
end
|
26
|
+
|
27
|
+
def redirect_to_root
|
28
|
+
if @user.email_previously_changed?
|
29
|
+
resend_email_verification
|
30
|
+
redirect_to main_app.root_path, notice: "Your email has been changed"
|
31
|
+
else
|
32
|
+
redirect_to main_app.root_path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def resend_email_verification
|
37
|
+
UserMailer.with(user: @user).email_verification.deliver_later
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActionAuth
|
2
|
+
module Identity
|
3
|
+
class PasswordResetsController < ApplicationController
|
4
|
+
before_action :set_user, only: %i[ edit update ]
|
5
|
+
|
6
|
+
def new
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
if @user = ActionAuth::User.find_by(email: params[:email], verified: true)
|
14
|
+
send_password_reset_email
|
15
|
+
redirect_to sign_in_path, notice: "Check your email for reset instructions"
|
16
|
+
else
|
17
|
+
redirect_to new_identity_password_reset_path, alert: "You can't reset your password until you verify your email"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
if @user.update(user_params)
|
23
|
+
redirect_to sign_in_path, notice: "Your password was reset successfully. Please sign in"
|
24
|
+
else
|
25
|
+
render :edit, status: :unprocessable_entity
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def set_user
|
32
|
+
@user = ActionAuth::User.find_by_token_for!(:password_reset, params[:sid])
|
33
|
+
rescue StandardError
|
34
|
+
redirect_to new_identity_password_reset_path, alert: "That password reset link is invalid"
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_params
|
38
|
+
params.permit(:password, :password_confirmation)
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_password_reset_email
|
42
|
+
UserMailer.with(user: @user).password_reset.deliver_later
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -7,7 +7,7 @@ module ActionAuth
|
|
7
7
|
|
8
8
|
def update
|
9
9
|
if @user.update(user_params)
|
10
|
-
redirect_to root_path, notice: "Your password has been changed"
|
10
|
+
redirect_to main_app.root_path, notice: "Your password has been changed"
|
11
11
|
else
|
12
12
|
render :edit, status: :unprocessable_entity
|
13
13
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<p style="color: red"><%= alert %></p>
|
2
|
+
|
3
|
+
<% if ActionAuth::Current.user.verified? %>
|
4
|
+
<h1>Change your email</h1>
|
5
|
+
<% else %>
|
6
|
+
<h1>Verify your email</h1>
|
7
|
+
<p>We sent a verification email to the address below. Check that email and follow those instructions to confirm it's your email address.</p>
|
8
|
+
<p><%= button_to "Re-send verification email", identity_email_verification_path %></p>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<%= form_with(url: identity_email_path, method: :patch) do |form| %>
|
12
|
+
<% if @user.errors.any? %>
|
13
|
+
<div style="color: red">
|
14
|
+
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
15
|
+
|
16
|
+
<ul>
|
17
|
+
<% @user.errors.each do |error| %>
|
18
|
+
<li><%= error.full_message %></li>
|
19
|
+
<% end %>
|
20
|
+
</ul>
|
21
|
+
</div>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<div>
|
25
|
+
<%= form.label :email, "New email", style: "display: block" %>
|
26
|
+
<%= form.email_field :email, required: true, autofocus: true %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div>
|
30
|
+
<%= form.label :password_challenge, style: "display: block" %>
|
31
|
+
<%= form.password_field :password_challenge, required: true, autocomplete: "current-password" %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<div>
|
35
|
+
<%= form.submit "Save changes" %>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<br>
|
40
|
+
|
41
|
+
<div>
|
42
|
+
<%= link_to "Back", main_app.root_path %>
|
43
|
+
</div>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h1>Reset your password</h1>
|
2
|
+
|
3
|
+
<%= form_with(url: identity_password_reset_path, method: :patch) do |form| %>
|
4
|
+
<% if @user.errors.any? %>
|
5
|
+
<div style="color: red">
|
6
|
+
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
7
|
+
|
8
|
+
<ul>
|
9
|
+
<% @user.errors.each do |error| %>
|
10
|
+
<li><%= error.full_message %></li>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<%= form.hidden_field :sid, value: params[:sid] %>
|
17
|
+
|
18
|
+
<div>
|
19
|
+
<%= form.label :password, "New password", style: "display: block" %>
|
20
|
+
<%= form.password_field :password, required: true, autofocus: true, autocomplete: "new-password" %>
|
21
|
+
<div>12 characters minimum.</div>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div>
|
25
|
+
<%= form.label :password_confirmation, "Confirm new password", style: "display: block" %>
|
26
|
+
<%= form.password_field :password_confirmation, required: true, autocomplete: "new-password" %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div>
|
30
|
+
<%= form.submit "Save changes" %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<p style="color: red"><%= alert %></p>
|
2
|
+
|
3
|
+
<h1>Forgot your password?</h1>
|
4
|
+
|
5
|
+
<%= form_with(url: identity_password_reset_path) do |form| %>
|
6
|
+
<div>
|
7
|
+
<%= form.label :email, style: "display: block" %>
|
8
|
+
<%= form.email_field :email, required: true, autofocus: true %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div>
|
12
|
+
<%= form.submit "Send password reset email" %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -5,4 +5,9 @@ ActionAuth::Engine.routes.draw do
|
|
5
5
|
post "sign_up", to: "registrations#create"
|
6
6
|
resources :sessions, only: [:index, :show, :destroy]
|
7
7
|
resource :password, only: [:edit, :update]
|
8
|
+
namespace :identity do
|
9
|
+
resource :email, only: [:edit, :update]
|
10
|
+
resource :email_verification, only: [:show, :create]
|
11
|
+
resource :password_reset, only: [:new, :edit, :create, :update]
|
12
|
+
end
|
8
13
|
end
|
data/lib/action_auth/engine.rb
CHANGED
data/lib/action_auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Kimura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,9 @@ files:
|
|
52
52
|
- app/assets/config/action_auth_manifest.js
|
53
53
|
- app/assets/stylesheets/action_auth/application.css
|
54
54
|
- app/controllers/action_auth/application_controller.rb
|
55
|
+
- app/controllers/action_auth/identity/email_verifications_controller.rb
|
56
|
+
- app/controllers/action_auth/identity/emails_controller.rb
|
57
|
+
- app/controllers/action_auth/identity/password_resets_controller.rb
|
55
58
|
- app/controllers/action_auth/passwords_controller.rb
|
56
59
|
- app/controllers/action_auth/registrations_controller.rb
|
57
60
|
- app/controllers/action_auth/sessions_controller.rb
|
@@ -63,6 +66,9 @@ files:
|
|
63
66
|
- app/models/action_auth/current.rb
|
64
67
|
- app/models/action_auth/session.rb
|
65
68
|
- app/models/action_auth/user.rb
|
69
|
+
- app/views/action_auth/identity/emails/edit.html.erb
|
70
|
+
- app/views/action_auth/identity/password_resets/edit.html.erb
|
71
|
+
- app/views/action_auth/identity/password_resets/new.html.erb
|
66
72
|
- app/views/action_auth/passwords/edit.html.erb
|
67
73
|
- app/views/action_auth/registrations/new.html.erb
|
68
74
|
- app/views/action_auth/sessions/index.html.erb
|