action_auth 0.1.0 → 0.1.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +0 -0
  3. data/README.md +24 -10
  4. data/Rakefile +0 -0
  5. data/app/assets/config/action_auth_manifest.js +0 -0
  6. data/app/assets/stylesheets/action_auth/application.css +0 -0
  7. data/app/controllers/action_auth/application_controller.rb +0 -0
  8. data/app/controllers/action_auth/identity/email_verifications_controller.rb +29 -0
  9. data/app/controllers/action_auth/identity/emails_controller.rb +41 -0
  10. data/app/controllers/action_auth/identity/password_resets_controller.rb +46 -0
  11. data/app/controllers/action_auth/passwords_controller.rb +26 -0
  12. data/app/controllers/action_auth/registrations_controller.rb +30 -0
  13. data/app/controllers/action_auth/sessions_controller.rb +28 -0
  14. data/app/helpers/action_auth/application_helper.rb +0 -0
  15. data/app/jobs/action_auth/application_job.rb +0 -0
  16. data/app/mailers/action_auth/application_mailer.rb +0 -0
  17. data/app/mailers/action_auth/user_mailer.rb +17 -0
  18. data/app/models/action_auth/application_record.rb +0 -0
  19. data/app/models/action_auth/current.rb +12 -0
  20. data/app/models/action_auth/session.rb +10 -0
  21. data/app/models/action_auth/user.rb +30 -0
  22. data/app/views/action_auth/identity/emails/edit.html.erb +43 -0
  23. data/app/views/action_auth/identity/password_resets/edit.html.erb +32 -0
  24. data/app/views/action_auth/identity/password_resets/new.html.erb +14 -0
  25. data/app/views/action_auth/passwords/edit.html.erb +43 -0
  26. data/app/views/action_auth/registrations/new.html.erb +35 -0
  27. data/app/views/action_auth/sessions/index.html.erb +29 -0
  28. data/app/views/action_auth/sessions/new.html.erb +30 -0
  29. data/app/views/action_auth/user_mailer/email_verification.html.erb +11 -0
  30. data/app/views/action_auth/user_mailer/email_verification.text.erb +3 -0
  31. data/app/views/action_auth/user_mailer/password_reset.html.erb +11 -0
  32. data/app/views/action_auth/user_mailer/password_reset.text.erb +3 -0
  33. data/app/views/layouts/action_auth/application.html.erb +0 -0
  34. data/app/views/layouts/action_auth/mailer.html.erb +13 -0
  35. data/app/views/layouts/action_auth/mailer.text.erb +1 -0
  36. data/config/routes.rb +11 -0
  37. data/db/migrate/20231107165548_create_action_auth_users.rb +12 -0
  38. data/db/migrate/20231107170349_create_action_auth_sessions.rb +11 -0
  39. data/lib/action_auth/controllers/helpers.rb +28 -0
  40. data/lib/action_auth/engine.rb +16 -0
  41. data/lib/action_auth/routing/helpers.rb +29 -0
  42. data/lib/action_auth/version.rb +1 -1
  43. data/lib/action_auth.rb +2 -1
  44. data/lib/tasks/action_auth_tasks.rake +0 -0
  45. metadata +43 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c7b9bf432371c7d2d5dce29f8b5e8946064206ef58f6116bd0b66335dbe8061
4
- data.tar.gz: 24d15513648b56084857a68f2f25b61c29a29d63a66e29b1251e8b48a2d2c04d
3
+ metadata.gz: 3745646b8654c9678ab57b1539e7190f3c002f3352dda31cf06a884604f2dfdd
4
+ data.tar.gz: 92f62b3fd0607982f545408db8196f6b24ba43b63df5b166f0262daa77a00013
5
5
  SHA512:
6
- metadata.gz: d5327306545b7798deb20118f940cd2eeff5769f6dec72a4da626264c7e255da0ad715ee87f0dd530314c1d02371a7b53f3a13e6af763256bae6db070f13b8f9
7
- data.tar.gz: 22225ffdaa9e1f0115e461d4b2363f84db5484d1338f84cb49a29ecfccb5085d17fb213705a77114a3fe4ffc2ec9761073078132d6f50ae5c2458f2060e7ad31
6
+ metadata.gz: f422203f6efa8a50d9de3140b0f97ad6eabe7a2d17bf79d36d352e41a08a20fe0bd23ab3f4587563655a2fb52ffc0800d5d1a783f97161a5b773d1df4647c751
7
+ data.tar.gz: 618b27e2c259afcd7018595087fa10cb828d38dee863b3d76f67dfff2f2e37e086bc6c240494769990265130831cd839c46c6edaf43a0c6051c4f58b2f852d4f
data/MIT-LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -5,21 +5,35 @@ This is a placeholder for the ActionAuth gem. It is not yet ready for use.
5
5
  Add this line to your application's Gemfile:
6
6
 
7
7
  ```ruby
8
- gem "action_auth"
8
+ bundle add action_auth
9
+ bin/rails action_auth:install:migrations
9
10
  ```
10
11
 
11
- And then execute:
12
- ```bash
13
- $ bundle
14
- ```
12
+ Modify config/routes.rb to include the following:
15
13
 
16
- Or install it yourself as:
17
- ```bash
18
- $ gem install action_auth
14
+ ```ruby
15
+ mount ActionAuth::Engine => 'action_auth'
19
16
  ```
20
17
 
21
- ## Contributing
22
- Contribution directions go here.
18
+ ## Usage
19
+
20
+ ### Routes
21
+
22
+ Within your application, you'll have access to these routes. They have been styled to be consistent with Devise.
23
+
24
+ Method Verb Params Description
25
+ user_sessions_path GET Device session management
26
+ user_session_path DELETE [:id] Log Out
27
+ new_user_session_path GET Log in
28
+ new_user_registration_path GET Sign Up
29
+
30
+ ### Helper Methods
31
+
32
+ Method Description
33
+ current_user Returns the currently logged in user
34
+ user_signed_in? Returns true if the user is logged in
35
+ current_session Returns the current session
36
+
23
37
 
24
38
  ## License
25
39
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
File without changes
File without changes
File without changes
@@ -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
@@ -0,0 +1,26 @@
1
+ module ActionAuth
2
+ class PasswordsController < ApplicationController
3
+ before_action :set_user
4
+
5
+ def edit
6
+ end
7
+
8
+ def update
9
+ if @user.update(user_params)
10
+ redirect_to main_app.root_path, notice: "Your password has been changed"
11
+ else
12
+ render :edit, status: :unprocessable_entity
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def set_user
19
+ @user = Current.user
20
+ end
21
+
22
+ def user_params
23
+ params.permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module ActionAuth
2
+ class RegistrationsController < ApplicationController
3
+ def new
4
+ @user = User.new
5
+ end
6
+
7
+ def create
8
+ @user = User.new(user_params)
9
+
10
+ if @user.save
11
+ session_record = @user.action_auth_sessions.create!
12
+ cookies.signed.permanent[:session_token] = { value: session_record.id, httponly: true }
13
+
14
+ send_email_verification
15
+ redirect_to main_app.root_path, notice: "Welcome! You have signed up successfully"
16
+ else
17
+ render :new, status: :unprocessable_entity
18
+ end
19
+ end
20
+
21
+ private
22
+ def user_params
23
+ params.permit(:email, :password, :password_confirmation)
24
+ end
25
+
26
+ def send_email_verification
27
+ UserMailer.with(user: @user).email_verification.deliver_later
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ module ActionAuth
2
+ class SessionsController < ApplicationController
3
+ before_action :set_current_request_details
4
+
5
+ def index
6
+ @sessions = Current.user.action_auth_sessions.order(created_at: :desc)
7
+ end
8
+
9
+ def new
10
+ end
11
+
12
+ def create
13
+ if user = User.authenticate_by(email: params[:email], password: params[:password])
14
+ @session = user.action_auth_sessions.create
15
+ cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true }
16
+ redirect_to main_app.root_path, notice: "Signed in successfully"
17
+ else
18
+ redirect_to sign_in_path(email_hint: params[:email]), alert: "That email or password is incorrect"
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ session = Current.user.action_auth_sessions.find(params[:id])
24
+ session.destroy
25
+ redirect_to(main_app.root_path, notice: "That session has been logged out")
26
+ end
27
+ end
28
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ module ActionAuth
2
+ class UserMailer < ApplicationMailer
3
+ def password_reset
4
+ @user = params[:user]
5
+ @signed_id = @user.generate_token_for(:password_reset)
6
+
7
+ mail to: @user.email, subject: "Reset your password"
8
+ end
9
+
10
+ def email_verification
11
+ @user = params[:user]
12
+ @signed_id = @user.generate_token_for(:email_verification)
13
+
14
+ mail to: @user.email, subject: "Verify your email"
15
+ end
16
+ end
17
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ module ActionAuth
2
+ class Current < ActiveSupport::CurrentAttributes
3
+ attribute :session
4
+ attribute :user_agent, :ip_address
5
+
6
+ delegate :action_auth_user, to: :session, allow_nil: true
7
+
8
+ def user
9
+ action_auth_user
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module ActionAuth
2
+ class Session < ApplicationRecord
3
+ belongs_to :action_auth_user, class_name: "ActionAuth::User", foreign_key: "action_auth_user_id"
4
+
5
+ before_create do
6
+ self.user_agent = Current.user_agent
7
+ self.ip_address = Current.ip_address
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ module ActionAuth
2
+ class User < ApplicationRecord
3
+ has_secure_password
4
+
5
+ generates_token_for :email_verification, expires_in: 2.days do
6
+ email
7
+ end
8
+
9
+ generates_token_for :password_reset, expires_in: 20.minutes do
10
+ password_salt.last(10)
11
+ end
12
+
13
+
14
+ has_many :action_auth_sessions, dependent: :destroy, class_name: "ActionAuth::Session", foreign_key: "action_auth_user_id"
15
+
16
+ validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
17
+ validates :password, allow_nil: true, length: { minimum: 12 }
18
+
19
+ normalizes :email, with: -> email { email.strip.downcase }
20
+
21
+
22
+ before_validation if: :email_changed?, on: :update do
23
+ self.verified = false
24
+ end
25
+
26
+ after_update if: :password_digest_previously_changed? do
27
+ action_auth_sessions.where.not(id: Current.session).delete_all
28
+ end
29
+ end
30
+ 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 %>
@@ -0,0 +1,43 @@
1
+ <p style="color: red"><%= alert %></p>
2
+
3
+ <h1>Change your password</h1>
4
+
5
+ <%= form_with(url: password_path, method: :patch) do |form| %>
6
+ <% if @user.errors.any? %>
7
+ <div style="color: red">
8
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
9
+
10
+ <ul>
11
+ <% @user.errors.each do |error| %>
12
+ <li><%= error.full_message %></li>
13
+ <% end %>
14
+ </ul>
15
+ </div>
16
+ <% end %>
17
+
18
+ <div>
19
+ <%= form.label :password_challenge, style: "display: block" %>
20
+ <%= form.password_field :password_challenge, required: true, autofocus: true, autocomplete: "current-password" %>
21
+ </div>
22
+
23
+ <div>
24
+ <%= form.label :password, "New password", style: "display: block" %>
25
+ <%= form.password_field :password, required: true, autocomplete: "new-password" %>
26
+ <div>12 characters minimum.</div>
27
+ </div>
28
+
29
+ <div>
30
+ <%= form.label :password_confirmation, "Confirm new password", style: "display: block" %>
31
+ <%= form.password_field :password_confirmation, required: true, autocomplete: "new-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,35 @@
1
+ <h1>Sign up</h1>
2
+
3
+ <%= form_with(url: sign_up_path) 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
+ <div>
17
+ <%= form.label :email, style: "display: block" %>
18
+ <%= form.email_field :email, value: @user.email, required: true, autofocus: true, autocomplete: "email" %>
19
+ </div>
20
+
21
+ <div>
22
+ <%= form.label :password, style: "display: block" %>
23
+ <%= form.password_field :password, required: true, autocomplete: "new-password" %>
24
+ <div>12 characters minimum.</div>
25
+ </div>
26
+
27
+ <div>
28
+ <%= form.label :password_confirmation, style: "display: block" %>
29
+ <%= form.password_field :password_confirmation, required: true, autocomplete: "new-password" %>
30
+ </div>
31
+
32
+ <div>
33
+ <%= form.submit "Sign up" %>
34
+ </div>
35
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <h1>Devices & Sessions</h1>
4
+
5
+ <div id="sessions">
6
+ <% @sessions.each do |session| %>
7
+ <div id="<%= dom_id session %>">
8
+ <p>
9
+ <strong>User Agent:</strong>
10
+ <%= session.user_agent %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Ip Address:</strong>
15
+ <%= session.ip_address %>
16
+ </p>
17
+
18
+ <p>
19
+ <strong>Created at:</strong>
20
+ <%= session.created_at %>
21
+ </p>
22
+
23
+ </div>
24
+ <p>
25
+ <%= button_to "Log out", session, method: :delete %>
26
+ </p>
27
+ <% end %>
28
+ </div>
29
+
@@ -0,0 +1,30 @@
1
+ <p style="color: green"><%= notice %></p>
2
+ <p style="color: red"><%= alert %></p>
3
+
4
+ <h1>Sign in</h1>
5
+
6
+ <%= form_with(url: sign_in_path) do |form| %>
7
+ <div>
8
+ <%= form.label :email, style: "display: block" %>
9
+ <%= form.email_field :email, value: params[:email_hint], required: true, autofocus: true, autocomplete: "email" %>
10
+ </div>
11
+
12
+ <div>
13
+ <%= form.label :password, style: "display: block" %>
14
+ <%= form.password_field :password, required: true, autocomplete: "current-password" %>
15
+ </div>
16
+
17
+ <div>
18
+ <%= form.submit "Sign in" %>
19
+ </div>
20
+ <% end %>
21
+
22
+ <br>
23
+
24
+
25
+ <br>
26
+
27
+ <div>
28
+ <%= link_to "Sign up", sign_up_path %> |
29
+ <%# link_to "Forgot your password?", new_identity_password_reset_path %>
30
+ </div>
@@ -0,0 +1,11 @@
1
+ <p>Hey there,</p>
2
+
3
+ <p>This is to confirm that <%= @user.email %> is the email you want to use on your account. If you ever lose your password, that's where we'll email a reset link.</p>
4
+
5
+ <p><strong>You must hit the link below to confirm that you received this email.</strong></p>
6
+
7
+ <p><%# link_to "Yes, use this email for my account", identity_email_verification_url(sid: @signed_id) %></p>
8
+
9
+ <hr>
10
+
11
+ <p>Have questions or need help? Just reply to this email and our support team will help you sort it out.</p>
@@ -0,0 +1,3 @@
1
+ User#email_verification
2
+
3
+ <%= @greeting %>, find me in app/views/action_auth/user_mailer/email_verification.text.erb
@@ -0,0 +1,11 @@
1
+ <p>Hey there,</p>
2
+
3
+ <p>Can't remember your password for <strong><%= @user.email %></strong>? That's OK, it happens. Just hit the link below to set a new one.</p>
4
+
5
+ <p><%# link_to "Reset my password", edit_identity_password_reset_url(sid: @signed_id) %></p>
6
+
7
+ <p>If you did not request a password reset you can safely ignore this email, it expires in 20 minutes. Only someone with access to this email account can reset your password.</p>
8
+
9
+ <hr>
10
+
11
+ <p>Have questions or need help? Just reply to this email and our support team will help you sort it out.</p>
@@ -0,0 +1,3 @@
1
+ User#password_reset
2
+
3
+ <%= @greeting %>, find me in app/views/action_auth/user_mailer/password_reset.text.erb
File without changes
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
data/config/routes.rb CHANGED
@@ -1,2 +1,13 @@
1
1
  ActionAuth::Engine.routes.draw do
2
+ get "sign_in", to: "sessions#new"
3
+ post "sign_in", to: "sessions#create"
4
+ get "sign_up", to: "registrations#new"
5
+ post "sign_up", to: "registrations#create"
6
+ resources :sessions, only: [:index, :show, :destroy]
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
2
13
  end
@@ -0,0 +1,12 @@
1
+ class CreateActionAuthUsers < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :action_auth_users do |t|
4
+ t.string :email
5
+ t.string :password_digest
6
+ t.boolean :verified
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :action_auth_users, :email, unique: true
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateActionAuthSessions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :action_auth_sessions do |t|
4
+ t.references :action_auth_user, null: false, foreign_key: true
5
+ t.string :user_agent
6
+ t.string :ip_address
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module ActionAuth
2
+ module Controllers
3
+ module Helpers
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :set_current_request_details
8
+
9
+ def current_user; Current.user; end
10
+ helper_method :current_user
11
+
12
+ def current_session; Current.session; end
13
+ helper_method :current_session
14
+
15
+ def user_signed_in?; Current.user.present?; end
16
+ helper_method :user_signed_in?
17
+ end
18
+
19
+ private
20
+
21
+ def set_current_request_details
22
+ Current.session = Session.find_by(id: cookies.signed[:session_token])
23
+ Current.user_agent = request.user_agent
24
+ Current.ip_address = request.ip
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,21 @@
1
+ require 'action_auth/controllers/helpers'
2
+ require 'action_auth/routing/helpers'
3
+
1
4
  module ActionAuth
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace ActionAuth
7
+
8
+ ActiveSupport.on_load(:action_controller_base) do
9
+ include ActionAuth::Controllers::Helpers
10
+ include ActionAuth::Routing::Helpers
11
+ end
12
+
13
+ initializer 'action_auth.add_helpers' do |app|
14
+ ActiveSupport.on_load :action_controller_base do
15
+ helper_method :user_sessions_path, :user_session_path, :new_user_session_path
16
+ helper_method :new_user_registration_path
17
+ helper_method :edit_user_password_path
18
+ end
19
+ end
4
20
  end
5
21
  end
@@ -0,0 +1,29 @@
1
+ module ActionAuth
2
+ module Routing
3
+ module Helpers
4
+ def user_sessions_path
5
+ action_auth.sessions_path
6
+ end
7
+
8
+ def user_session_path(session_id)
9
+ action_auth.session_path(session_id)
10
+ end
11
+
12
+ def new_user_session_path
13
+ action_auth.sign_in_path
14
+ end
15
+
16
+ def new_user_registration_path
17
+ action_auth.sign_up_path
18
+ end
19
+
20
+ def edit_password_path
21
+ action_auth.edit_password_path
22
+ end
23
+
24
+ def password_path
25
+ action_auth.password_path
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ActionAuth
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/action_auth.rb CHANGED
@@ -2,5 +2,6 @@ require "action_auth/version"
2
2
  require "action_auth/engine"
3
3
 
4
4
  module ActionAuth
5
- # Your code goes here...
5
+ module Controllers
6
+ end
6
7
  end
File without changes
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.0
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-07 00:00:00.000000000 Z
11
+ date: 2023-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bcrypt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
27
41
  description: Using the built in features of Rails, ActionAuth provides a simple way
28
42
  to authorize users to perform actions on your application.
29
43
  email:
@@ -38,14 +52,41 @@ files:
38
52
  - app/assets/config/action_auth_manifest.js
39
53
  - app/assets/stylesheets/action_auth/application.css
40
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
58
+ - app/controllers/action_auth/passwords_controller.rb
59
+ - app/controllers/action_auth/registrations_controller.rb
60
+ - app/controllers/action_auth/sessions_controller.rb
41
61
  - app/helpers/action_auth/application_helper.rb
42
62
  - app/jobs/action_auth/application_job.rb
43
63
  - app/mailers/action_auth/application_mailer.rb
64
+ - app/mailers/action_auth/user_mailer.rb
44
65
  - app/models/action_auth/application_record.rb
66
+ - app/models/action_auth/current.rb
67
+ - app/models/action_auth/session.rb
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
72
+ - app/views/action_auth/passwords/edit.html.erb
73
+ - app/views/action_auth/registrations/new.html.erb
74
+ - app/views/action_auth/sessions/index.html.erb
75
+ - app/views/action_auth/sessions/new.html.erb
76
+ - app/views/action_auth/user_mailer/email_verification.html.erb
77
+ - app/views/action_auth/user_mailer/email_verification.text.erb
78
+ - app/views/action_auth/user_mailer/password_reset.html.erb
79
+ - app/views/action_auth/user_mailer/password_reset.text.erb
45
80
  - app/views/layouts/action_auth/application.html.erb
81
+ - app/views/layouts/action_auth/mailer.html.erb
82
+ - app/views/layouts/action_auth/mailer.text.erb
46
83
  - config/routes.rb
84
+ - db/migrate/20231107165548_create_action_auth_users.rb
85
+ - db/migrate/20231107170349_create_action_auth_sessions.rb
47
86
  - lib/action_auth.rb
87
+ - lib/action_auth/controllers/helpers.rb
48
88
  - lib/action_auth/engine.rb
89
+ - lib/action_auth/routing/helpers.rb
49
90
  - lib/action_auth/version.rb
50
91
  - lib/tasks/action_auth_tasks.rake
51
92
  homepage: https://www.github.com/kobaltz/action_auth