yaag 0.0.19 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38c30b61f84668afa0e65809ee40daedd23bade1abd83915f01db62b80241978
4
- data.tar.gz: e85146f65486aa58c9df32b42b524121b5196be33fc66f37a620d588e128c421
3
+ metadata.gz: d12d4feb11b2bf161940d8925180dc1bf27a57029521197bef08bac48c5a8997
4
+ data.tar.gz: a26d2996a3aa9fe193a074c0f9f745b977a048f33df2e13d479a5ec5d267a87f
5
5
  SHA512:
6
- metadata.gz: 92d04143a6e0592b38e19200ba796be3934f671bb3ccb5ab2b471bba34e9388740c3c0094dc17541a286c2dd5ae0ff1f71dcbf926432a4919dd6a2f95ed2300e
7
- data.tar.gz: cfa7aaea9e9de5e05d51d374fbddcccc764066676aa80948c2a0418046f34692723f8bb7924dc98c6687eb17c69699c7906a5fbe7747e19a0dd3104f09b2927e
6
+ metadata.gz: abc264f8d2def0f837f46056fa41811ce8dbf9cdd7cc69cca56153edff8d6eb67e76b721427051a467724945cd21d771fc4dba5b03a143373dfe460735898549
7
+ data.tar.gz: 1ce0344f09b9c879b0d23f6ba4d055a8fbceabb06a813770033734600e6dac2fff242e3df34c4655cf009bc2fa67e54f1ee30c2e7b532beeb1bff980e3986753
data/README.md CHANGED
@@ -32,10 +32,10 @@ bundle
32
32
 
33
33
  Generate the authentication components (migrations, etc):
34
34
  ```bash
35
- $ gem install authentication:install
35
+ rails g authentication:install
36
36
  ```
37
37
 
38
- Follow the instructions post-installation.
38
+ Follow the on-screen post-installation instructions.
39
39
 
40
40
  ## Usage
41
41
 
@@ -60,5 +60,39 @@ class MyController < ApplicationController
60
60
  end
61
61
  ```
62
62
 
63
+ ### Generators
64
+
65
+ Here is a list of generator available in case any of the components of the gem need to be customized to specific application needs.
66
+
67
+ For views:
68
+
69
+ ```bash
70
+ rails g authentication:copy:views
71
+ ```
72
+
73
+ For controllers (including concerns):
74
+
75
+ ```bash
76
+ rails g authentication:copy:controllers
77
+ ```
78
+
79
+ ### Test helper
80
+
81
+ To be able to perform tasks as an authenticated user, a helper is available to be used in tests. Add `include Yaag::Test::SessionsHelper` to access the methods `sign_in_as` and `sign_out`:
82
+
83
+ ```
84
+ class MyControllerTest < ActionDispatch::IntegrationTest
85
+ include Yaag::Test::SessionsHelper
86
+ setup { sign_in_as(User.take) }
87
+ ...
88
+ end
89
+ ```
90
+
91
+ ## Release
92
+
93
+ ```bash
94
+ git tag $(bundle exec rake version | tr -d '"') && git push --tags
95
+ ```
96
+
63
97
  ## License
64
98
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ require "bundler/gem_tasks"
7
7
 
8
8
  task :version do
9
9
  p "v#{Yaag::VERSION}"
10
- end
10
+ end
@@ -8,12 +8,12 @@ class SessionsController < ApplicationController
8
8
 
9
9
  def create
10
10
  start_new_session_for @user
11
- redirect_to after_authentication_url
11
+ redirect_to after_authentication_url, notice: I18n.t("yaag.sessions.successful")
12
12
  end
13
13
 
14
14
  def destroy
15
15
  terminate_session
16
- redirect_to new_signin_path, notice: I18n.t("yaag.sessions.successful"), status: :see_other
16
+ redirect_to new_signin_path, notice: I18n.t("yaag.sessions.destroy"), status: :see_other
17
17
  end
18
18
  private
19
19
  def set_user_by_token
@@ -1,8 +1,14 @@
1
1
  <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
2
2
  <%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
3
3
 
4
- <%= form_with url: signin_path do |form| %>
5
- <%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t("yaag.forms.signin_placeholder"), value: params[:email_address] %><br>
6
- <%= form.submit t("yaag.forms.signin_button") %>
7
- <% end %>
8
- <br>
4
+ <div class="container w-50 ">
5
+ <h2>Sign In</h2>
6
+ <%= form_with url: signin_path do |form| %>
7
+ <div class="field mt-3">
8
+ <%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t("yaag.forms.signin_placeholder"), value: params[:email_address], class: "form-control" %><br>
9
+ </div>
10
+ <div class="actions mb-3">
11
+ <%= form.submit t("yaag.forms.signin_button"), class: "form-control btn btn-primary" %>
12
+ </div>
13
+ <% end %>
14
+ </div>
@@ -1,5 +1,6 @@
1
1
  <p>
2
- You can signin <%= link_to "with this link", create_session_url(@user.email_address_login_token) %>.
3
-
2
+ Click <%= link_to "here", create_session_url(@user.email_address_login_token) %> to sign in.
3
+ </p>
4
+ <p>
4
5
  This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
5
6
  </p>
@@ -1,4 +1,5 @@
1
- You can signin with the following link:
1
+ You can sign in with the following link (copy and paste in the browser):
2
+
2
3
  <%= create_session_url(@user.email_address_login_token) %>
3
4
 
4
5
  This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
@@ -9,6 +9,7 @@ en:
9
9
  signin_placeholder: "Enter your email address"
10
10
  sessions:
11
11
  successful: "Signed in successfully."
12
+ destroy: "Signed out successfully."
12
13
  signins:
13
14
  email_sent: "Sign in address sent to provided e-mail."
14
15
  email_subject: "Sign in link"
@@ -0,0 +1,13 @@
1
+ module Authentication
2
+ module Copy
3
+ class ControllersGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../../../", __dir__)
5
+
6
+ def copy_controllers
7
+ copy_file "app/controllers/concerns/authentication.rb"
8
+ copy_file "app/controllers/sessions_controller.rb"
9
+ copy_file "app/controllers/signins_controller.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Authentication
2
+ module Copy
3
+ class ViewsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../../../", __dir__)
5
+
6
+ def copy_views
7
+ copy_file "app/views/sessions/new.html.erb"
8
+ copy_file "app/views/signins/new.html.erb"
9
+ copy_file "app/views/signins_mailer/token.html.erb"
10
+ copy_file "app/views/signins_mailer/token.text.erb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -30,4 +30,10 @@ end
30
30
 
31
31
  ===============================================================
32
32
 
33
+ More generators available for customizations:
34
+
35
+ ./bin/rails db:migrate g authentication:copy:views
36
+
37
+ ===============================================================
38
+
33
39
  See more at: https://github.com/nu12/yaag
@@ -0,0 +1,19 @@
1
+ module Yaag
2
+ module Test
3
+ module SessionsHelper
4
+ def sign_in_as(user)
5
+ Current.session = user.sessions.create!
6
+
7
+ ActionDispatch::TestRequest.create.cookie_jar.tap do |cookie_jar|
8
+ cookie_jar.signed[:session_id] = Current.session.id
9
+ cookies["session_id"] = cookie_jar[:session_id]
10
+ end
11
+ end
12
+
13
+ def sign_out
14
+ Current.session&.destroy!
15
+ cookies.delete("session_id")
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/yaag/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaag
2
- VERSION = "0.0.19"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/yaag.rb CHANGED
@@ -2,6 +2,9 @@ require "yaag/version"
2
2
  require "yaag/engine"
3
3
 
4
4
  module Yaag
5
+ module Test
6
+ autoload :SessionsHelper, "yaag/test/sessions_helper"
7
+ end
5
8
  module PasswordlessLogin
6
9
  extend ActiveSupport::Concern
7
10
 
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nu12
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-09 00:00:00.000000000 Z
11
+ date: 2026-01-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Passwordless authentication.
13
+ description: Yet Another Authentication Gem (YAAG) provides passwordless authentication
14
+ for your Ruby on Rails app, all it takes is the user's e-mail address.
14
15
  email:
15
16
  - 34694287+nu12@users.noreply.github.com
16
17
  executables: []
@@ -36,11 +37,14 @@ files:
36
37
  - db/migrate/20260108164812_create_users.rb
37
38
  - db/migrate/20260108165215_create_sessions.rb
38
39
  - lib/generators/authentication/USAGE
40
+ - lib/generators/authentication/copy/controllers_generator.rb
41
+ - lib/generators/authentication/copy/views_generator.rb
39
42
  - lib/generators/authentication/install_generator.rb
40
43
  - lib/generators/authentication/templates/README
41
44
  - lib/tasks/yaag_tasks.rake
42
45
  - lib/yaag.rb
43
46
  - lib/yaag/engine.rb
47
+ - lib/yaag/test/sessions_helper.rb
44
48
  - lib/yaag/version.rb
45
49
  homepage: https://github.com/nu12/yaag
46
50
  licenses:
@@ -66,5 +70,5 @@ requirements: []
66
70
  rubygems_version: 3.4.19
67
71
  signing_key:
68
72
  specification_version: 4
69
- summary: Passwordless authentication.
73
+ summary: Passwordless authentication for your Ruby on Rails app.
70
74
  test_files: []