yaag 0.0.11 → 0.0.19

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +46 -17
  4. data/Rakefile +7 -9
  5. data/{lib/generators/yaag/templates/app → app}/controllers/sessions_controller.rb +3 -3
  6. data/{lib/generators/yaag/templates/app → app}/controllers/signins_controller.rb +2 -2
  7. data/{lib/generators/yaag/templates/app → app}/mailers/signins_mailer.rb +1 -1
  8. data/{lib/generators/yaag/templates/app → app}/models/user.rb +1 -1
  9. data/{lib/generators/yaag/templates/app → app}/views/signins/new.html.erb +2 -2
  10. data/app/views/signins_mailer/token.html.erb +5 -0
  11. data/app/views/signins_mailer/token.text.erb +4 -0
  12. data/config/locales/en.yml +14 -0
  13. data/config/routes.rb +6 -0
  14. data/db/migrate/20260108164812_create_users.rb +10 -0
  15. data/db/migrate/20260108165215_create_sessions.rb +11 -0
  16. data/lib/generators/{yaag → authentication}/USAGE +2 -1
  17. data/lib/generators/authentication/install_generator.rb +18 -0
  18. data/lib/generators/authentication/templates/README +33 -0
  19. data/lib/tasks/yaag_tasks.rake +4 -0
  20. data/lib/yaag/engine.rb +1 -2
  21. data/lib/yaag/version.rb +1 -3
  22. data/lib/yaag.rb +48 -5
  23. metadata +22 -22
  24. data/.rubocop.yml +0 -8
  25. data/LICENSE.txt +0 -21
  26. data/lib/generators/yaag/install_generator.rb +0 -64
  27. data/lib/generators/yaag/templates/README +0 -1
  28. data/lib/generators/yaag/templates/active_model/passwordless_login.rb +0 -51
  29. data/lib/generators/yaag/templates/app/channels/application_cable/connection.rb +0 -16
  30. data/lib/generators/yaag/templates/app/views/signins_mailer/token.html.erb +0 -8
  31. data/lib/generators/yaag/templates/app/views/signins_mailer/token.text.erb +0 -6
  32. data/mise.toml +0 -2
  33. data/sig/yaag.rbs +0 -4
  34. /data/{lib/generators/yaag/templates/app → app}/controllers/concerns/authentication.rb +0 -0
  35. /data/{lib/generators/yaag/templates/app → app}/models/current.rb +0 -0
  36. /data/{lib/generators/yaag/templates/app → app}/models/session.rb +0 -0
  37. /data/{lib/generators/yaag/templates/app → app}/views/sessions/new.html.erb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2da4ef8b96e8631b9e35d8ffa355325a3f0a0a0dc3c59a439c39e47e624e5e16
4
- data.tar.gz: 40e8a8882b657f30850118b72a132b9e61296381df6b52c908eaf71022c46cdb
3
+ metadata.gz: 38c30b61f84668afa0e65809ee40daedd23bade1abd83915f01db62b80241978
4
+ data.tar.gz: e85146f65486aa58c9df32b42b524121b5196be33fc66f37a620d588e128c421
5
5
  SHA512:
6
- metadata.gz: ca92370e1389ed19923f99a192aa3c87a54c0fd6551620b0ea52edef322a9fa6995aafc6d01ea27044326313f988f884488eac4abae50d9803d24ec790a262b0
7
- data.tar.gz: 1e220e7aa4138f589a274f6a80f4173372087e2fbdf5f7c56dc02683e9951b42f5fefb12a1fd76741a714194c6066c225c6447df32c9737ec68d3ed21d81da9f
6
+ metadata.gz: 92d04143a6e0592b38e19200ba796be3934f671bb3ccb5ab2b471bba34e9388740c3c0094dc17541a286c2dd5ae0ff1f71dcbf926432a4919dd6a2f95ed2300e
7
+ data.tar.gz: cfa7aaea9e9de5e05d51d374fbddcccc764066676aa80948c2a0418046f34692723f8bb7924dc98c6687eb17c69699c7906a5fbe7747e19a0dd3104f09b2927e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,35 +1,64 @@
1
- # Yaag
1
+ # Yet Another Authentication Gem
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Yet Another Authentication Gem (YAAG) provides passwordless authentication for your rails app, all it takes is the user's e-mail address.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yaag`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ No password. No e-mail confirmation. No registration.
6
6
 
7
- ## Installation
7
+ ## TL;DR
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ ```
10
+ bundle add yaag
11
+ bundle install
10
12
 
11
- Install the gem and add to the application's Gemfile by executing:
13
+ rails g authentication:install
14
+ rails db:migrate
15
+ ```
12
16
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ## How it works
14
18
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
19
+ It's the same mechanics of password reset in traditional authentication: the user provides an e-amil address and receives a link with a token to sign in. At its core, it implements the same logic of the built-in rails authentication (in fact most of the gem's code came from the rails library).
16
20
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ## Installation
22
+ Add this line to your application's Gemfile:
18
23
 
19
- ## Usage
24
+ ```bash
25
+ bundle add yaag
26
+ ```
20
27
 
21
- TODO: Write usage instructions here
28
+ And then execute:
29
+ ```bash
30
+ bundle
31
+ ```
22
32
 
23
- ## Development
33
+ Generate the authentication components (migrations, etc):
34
+ ```bash
35
+ $ gem install authentication:install
36
+ ```
24
37
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ Follow the instructions post-installation.
26
39
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+ ## Usage
28
41
 
29
- ## Contributing
42
+ By default, all controllers require signing in via the inclusion of `include Authentication` in the `ApplicationController`. If you have a route that doesn't require signing in, add `allow_unauthenticated_access` to it:
30
43
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yaag.
44
+ ```
45
+ class GuestController < ApplicationController
46
+ allow_unauthenticated_access only: %i[ index ]
47
+ ...
48
+ end
49
+ ```
32
50
 
33
- ## License
51
+ Get the current user with `Current.user` and the current session with `Current.session`
52
+
53
+ ```
54
+ class MyController < ApplicationController
55
+ def something
56
+ user = Current.user
57
+ session = Current.session
58
+ ...
59
+ end
60
+ end
61
+ ```
34
62
 
63
+ ## License
35
64
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- # frozen_string_literal: true
1
+ require "bundler/setup"
2
2
 
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
5
-
6
- Minitest::TestTask.create
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
7
5
 
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
6
+ require "bundler/gem_tasks"
11
7
 
12
- task default: %i[test rubocop]
8
+ task :version do
9
+ p "v#{Yaag::VERSION}"
10
+ end
@@ -1,7 +1,7 @@
1
1
  class SessionsController < ApplicationController
2
2
  allow_unauthenticated_access only: %i[ new create ]
3
3
  before_action :set_user_by_token, only: %i[ create ]
4
- rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
4
+ rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: I18n.t("yaag.errors.rate_limit") }
5
5
 
6
6
  def new
7
7
  end
@@ -13,12 +13,12 @@ class SessionsController < ApplicationController
13
13
 
14
14
  def destroy
15
15
  terminate_session
16
- redirect_to new_signin_path, status: :see_other
16
+ redirect_to new_signin_path, notice: I18n.t("yaag.sessions.successful"), status: :see_other
17
17
  end
18
18
  private
19
19
  def set_user_by_token
20
20
  @user = User.find_by_email_address_login_token!(params[:token])
21
21
  rescue ActiveSupport::MessageVerifier::InvalidSignature
22
- redirect_to new_signin_path, alert: "Signin link is invalid or has expired."
22
+ redirect_to new_signin_path, alert: I18n.t("yaag.errors.invalid_token"), status: :see_other
23
23
  end
24
24
  end
@@ -1,12 +1,12 @@
1
1
  class SigninsController < ApplicationController
2
2
  allow_unauthenticated_access
3
- rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_signin_path, alert: "Try again later." }
3
+ rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_signin_path, alert: I18n.t("yaag.errors.rate_limit") }
4
4
  def new
5
5
  end
6
6
 
7
7
  def create
8
8
  user = User.find_or_create_by(email_address: params[:email_address])
9
9
  SigninsMailer.token(user).deliver_now
10
- redirect_to new_session_path, notice: "Sign in address sent to provided e-mail."
10
+ redirect_to new_session_path, notice: I18n.t("yaag.signins.email_sent"), status: :see_other
11
11
  end
12
12
  end
@@ -1,6 +1,6 @@
1
1
  class SigninsMailer < ApplicationMailer
2
2
  def token(user)
3
3
  @user = user
4
- mail subject: "Sign in link", to: user.email_address
4
+ mail subject: I18n.t("yaag.signins.email_subject"), to: user.email_address
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  class User < ApplicationRecord
2
- include ActiveModel::PasswordlessLogin
2
+ include Yaag::PasswordlessLogin
3
3
  has_passwordless_login
4
4
  has_many :sessions, dependent: :destroy
5
5
 
@@ -2,7 +2,7 @@
2
2
  <%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
3
3
 
4
4
  <%= form_with url: signin_path do |form| %>
5
- <%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
6
- <%= form.submit "Sign in" %>
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
7
  <% end %>
8
8
  <br>
@@ -0,0 +1,5 @@
1
+ <p>
2
+ You can signin <%= link_to "with this link", create_session_url(@user.email_address_login_token) %>.
3
+
4
+ This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
5
+ </p>
@@ -0,0 +1,4 @@
1
+ You can signin with the following link:
2
+ <%= create_session_url(@user.email_address_login_token) %>
3
+
4
+ This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
@@ -0,0 +1,14 @@
1
+
2
+ en:
3
+ yaag:
4
+ errors:
5
+ invalid_token: "Signin link is invalid or has expired."
6
+ rate_limit: "Try again later."
7
+ forms:
8
+ signin_button: "Sign in"
9
+ signin_placeholder: "Enter your email address"
10
+ sessions:
11
+ successful: "Signed in successfully."
12
+ signins:
13
+ email_sent: "Sign in address sent to provided e-mail."
14
+ email_subject: "Sign in link"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ resource :signin, only: [ :new, :create ]
3
+ resource :session, only: [ :new, :destroy ] do
4
+ get "/:token/create" => "sessions#create", as: :create
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateUsers < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :email_address, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ add_index :users, :email_address, unique: true
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSessions < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :sessions do |t|
4
+ t.references :user, null: false, foreign_key: true
5
+ t.string :ip_address
6
+ t.string :user_agent
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -2,4 +2,5 @@ Description:
2
2
  Generates a basic passwordless authentication system with users and sessions.
3
3
 
4
4
  Example:
5
- `bin/rails generate yaag:install`
5
+ bin/rails generate authentication:install
6
+
@@ -0,0 +1,18 @@
1
+ module Authentication
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ def configure_application_controller
6
+ inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include Authentication\n"
7
+ end
8
+
9
+ def generate_migrations
10
+ generate "migration", "CreateUsers", "email_address:string!:uniq", "--force"
11
+ generate "migration", "CreateSessions", "user:references ip_address:string user_agent:string", "--force"
12
+ end
13
+
14
+ def show_readme
15
+ readme "README" if behavior == :invoke
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+
2
+ Yet Another Authentication Gem (YAAG)
3
+
4
+ ===============================================================
5
+
6
+ To complete the installation, run a database migration:
7
+
8
+ ./bin/rails db:migrate
9
+
10
+ ===============================================================
11
+
12
+ Make sure root route is present in config/routes.rb. Example:
13
+
14
+ Rails.application.routes.draw do
15
+ ...
16
+ root "controller#action"
17
+ ...
18
+ end
19
+
20
+ ===============================================================
21
+
22
+ By default, all controllers require user signin.
23
+
24
+ To allow unauthenticated access, add allow_unauthenticated_access to your controller. Example:
25
+
26
+ class MyController < ApplicationController
27
+ allow_unauthenticated_access only: %i[ index ]
28
+ ...
29
+ end
30
+
31
+ ===============================================================
32
+
33
+ See more at: https://github.com/nu12/yaag
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :yaag do
3
+ # # Task goes here
4
+ # end
data/lib/yaag/engine.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Yaag
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace Yaag
4
3
  end
5
- end
4
+ end
data/lib/yaag/version.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Yaag
4
- VERSION = "0.0.11"
2
+ VERSION = "0.0.19"
5
3
  end
data/lib/yaag.rb CHANGED
@@ -1,8 +1,51 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "yaag/version"
1
+ require "yaag/version"
2
+ require "yaag/engine"
4
3
 
5
4
  module Yaag
6
- class Error < StandardError; end
7
- # Your code goes here...
5
+ module PasswordlessLogin
6
+ extend ActiveSupport::Concern
7
+
8
+ DEFAULT_LOGIN_TOKEN_EXPIRES_IN = 15.minutes
9
+
10
+ class << self
11
+ end
12
+
13
+ module ClassMethods
14
+ def has_passwordless_login(attribute = :email_address)
15
+ include InstanceMethodsOnActivation.new(attribute)
16
+
17
+ if respond_to?(:generates_token_for)
18
+ login_token_expires_in = DEFAULT_LOGIN_TOKEN_EXPIRES_IN
19
+
20
+ silence_redefinition_of_method(:"#{attribute}_login_token_expires_in")
21
+ define_method(:"#{attribute}_login_token_expires_in") { login_token_expires_in }
22
+
23
+ generates_token_for :"#{attribute}_login", expires_in: login_token_expires_in do
24
+ public_send(:"#{attribute}")&.first(10)
25
+ end
26
+
27
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
28
+ silence_redefinition_of_method :find_by_#{attribute}_login_token
29
+ def self.find_by_#{attribute}_login_token(token)
30
+ find_by_token_for(:#{attribute}_login, token)
31
+ end
32
+
33
+ silence_redefinition_of_method :find_by_#{attribute}_login_token!
34
+ def self.find_by_#{attribute}_login_token!(token)
35
+ find_by_token_for!(:#{attribute}_login, token)
36
+ end
37
+ RUBY
38
+ end
39
+ end
40
+ end
41
+
42
+ class InstanceMethodsOnActivation < Module
43
+ def initialize(attribute)
44
+ # attr_accessor attribute
45
+ define_method("#{attribute}_login_token") do
46
+ generate_token_for(:"#{attribute}_login")
47
+ end
48
+ end
49
+ end
50
+ end
8
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.19
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-06 00:00:00.000000000 Z
11
+ date: 2026-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Passwordless authentication.
14
14
  email:
@@ -17,31 +17,31 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".rubocop.yml"
21
- - LICENSE.txt
20
+ - MIT-LICENSE
22
21
  - README.md
23
22
  - Rakefile
24
- - lib/generators/yaag/USAGE
25
- - lib/generators/yaag/install_generator.rb
26
- - lib/generators/yaag/templates/README
27
- - lib/generators/yaag/templates/active_model/passwordless_login.rb
28
- - lib/generators/yaag/templates/app/channels/application_cable/connection.rb
29
- - lib/generators/yaag/templates/app/controllers/concerns/authentication.rb
30
- - lib/generators/yaag/templates/app/controllers/sessions_controller.rb
31
- - lib/generators/yaag/templates/app/controllers/signins_controller.rb
32
- - lib/generators/yaag/templates/app/mailers/signins_mailer.rb
33
- - lib/generators/yaag/templates/app/models/current.rb
34
- - lib/generators/yaag/templates/app/models/session.rb
35
- - lib/generators/yaag/templates/app/models/user.rb
36
- - lib/generators/yaag/templates/app/views/sessions/new.html.erb
37
- - lib/generators/yaag/templates/app/views/signins/new.html.erb
38
- - lib/generators/yaag/templates/app/views/signins_mailer/token.html.erb
39
- - lib/generators/yaag/templates/app/views/signins_mailer/token.text.erb
23
+ - app/controllers/concerns/authentication.rb
24
+ - app/controllers/sessions_controller.rb
25
+ - app/controllers/signins_controller.rb
26
+ - app/mailers/signins_mailer.rb
27
+ - app/models/current.rb
28
+ - app/models/session.rb
29
+ - app/models/user.rb
30
+ - app/views/sessions/new.html.erb
31
+ - app/views/signins/new.html.erb
32
+ - app/views/signins_mailer/token.html.erb
33
+ - app/views/signins_mailer/token.text.erb
34
+ - config/locales/en.yml
35
+ - config/routes.rb
36
+ - db/migrate/20260108164812_create_users.rb
37
+ - db/migrate/20260108165215_create_sessions.rb
38
+ - lib/generators/authentication/USAGE
39
+ - lib/generators/authentication/install_generator.rb
40
+ - lib/generators/authentication/templates/README
41
+ - lib/tasks/yaag_tasks.rake
40
42
  - lib/yaag.rb
41
43
  - lib/yaag/engine.rb
42
44
  - lib/yaag/version.rb
43
- - mise.toml
44
- - sig/yaag.rbs
45
45
  homepage: https://github.com/nu12/yaag
46
46
  licenses:
47
47
  - MIT
data/.rubocop.yml DELETED
@@ -1,8 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.0
3
-
4
- Style/StringLiterals:
5
- EnforcedStyle: double_quotes
6
-
7
- Style/StringLiteralsInInterpolation:
8
- EnforcedStyle: double_quotes
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 nu12
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/bundle_helper"
4
-
5
- module Yaag
6
- module Generators
7
- class InstallGenerator < Rails::Generators::Base # :nodoc:
8
- include Rails::Generators::BundleHelper
9
- source_root File.expand_path("../templates", __FILE__)
10
-
11
- class_option :api, type: :boolean,
12
- desc: "Generate API-only controllers and models, with no view templates"
13
-
14
- # hook_for :template_engine do |template_engine|
15
- #invoke template_engine unless options.api?
16
- # end
17
-
18
- def create_authentication_files
19
-
20
- template "app/models/session.rb"
21
- template "app/models/user.rb"
22
- template "app/models/current.rb"
23
-
24
- template "app/controllers/signins_controller.rb"
25
- template "app/controllers/sessions_controller.rb"
26
- template "app/controllers/concerns/authentication.rb"
27
-
28
- template "app/channels/application_cable/connection.rb" # if defined?(ActionCable::Engine)
29
-
30
- copy_file "app/views/sessions/new.html.erb"
31
- copy_file "app/views/signins/new.html.erb"
32
-
33
- #if defined?(ActionMailer::Railtie)
34
- template "app/mailers/signins_mailer.rb"
35
-
36
- copy_file "app/views/signins_mailer/token.html.erb"
37
- copy_file "app/views/signins_mailer/token.text.erb"
38
- #end
39
-
40
- template "active_model/passwordless_login.rb", "lib/active_model/passwordless_login.rb"
41
- end
42
-
43
- def configure_application_controller
44
- inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include Authentication\n" # if File.exist? "app/controllers/application_controller.rb"
45
- end
46
-
47
- def configure_authentication_routes
48
- route "resource :signin, only: [:new, :create]" # if File.exist? "config/routes.rb"
49
- route "resource :session, only: [:new, :destroy] do\n get \"/:token/create\" => \"sessions#create\", as: :create\nend" # if File.exist? "config/routes.rb"
50
- end
51
-
52
- def add_migrations
53
- generate "migration", "CreateUsers", "email_address:string!:uniq", "--force"
54
- generate "migration", "CreateSessions", "user:references ip_address:string user_agent:string", "--force"
55
- end
56
-
57
- def show_readme
58
- readme "README" if behavior == :invoke
59
- end
60
-
61
- #hook_for :test_framework
62
- end
63
- end
64
- end
@@ -1 +0,0 @@
1
- ===============================================================================
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveModel
4
- module PasswordlessLogin
5
- extend ActiveSupport::Concern
6
-
7
- DEFAULT_LOGIN_TOKEN_EXPIRES_IN = 15.minutes
8
-
9
- class << self
10
- end
11
-
12
- module ClassMethods
13
- def has_passwordless_login(attribute = :email_address)
14
- include InstanceMethodsOnActivation.new(attribute)
15
-
16
- if respond_to?(:generates_token_for)
17
- login_token_expires_in = DEFAULT_LOGIN_TOKEN_EXPIRES_IN
18
-
19
- silence_redefinition_of_method(:"#{attribute}_login_token_expires_in")
20
- define_method(:"#{attribute}_login_token_expires_in") { login_token_expires_in }
21
-
22
- generates_token_for :"#{attribute}_login", expires_in: login_token_expires_in do
23
- public_send(:"#{attribute}")&.first(10)
24
- end
25
-
26
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
27
- silence_redefinition_of_method :find_by_#{attribute}_login_token
28
- def self.find_by_#{attribute}_login_token(token)
29
- find_by_token_for(:#{attribute}_login, token)
30
- end
31
-
32
- silence_redefinition_of_method :find_by_#{attribute}_login_token!
33
- def self.find_by_#{attribute}_login_token!(token)
34
- find_by_token_for!(:#{attribute}_login, token)
35
- end
36
- RUBY
37
- end
38
- end
39
- end
40
-
41
- class InstanceMethodsOnActivation < Module
42
- def initialize(attribute)
43
- attr_reader attribute
44
-
45
- define_method("#{attribute}_login_token") do
46
- generate_token_for(:"#{attribute}_login")
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,16 +0,0 @@
1
- module ApplicationCable
2
- class Connection < ActionCable::Connection::Base
3
- identified_by :current_user
4
-
5
- def connect
6
- set_current_user || reject_unauthorized_connection
7
- end
8
-
9
- private
10
- def set_current_user
11
- if session = Session.find_by(id: cookies.signed[:session_id])
12
- self.current_user = session.user
13
- end
14
- end
15
- end
16
- end
@@ -1,8 +0,0 @@
1
- <% if @user %>
2
- <p>
3
- You can reset your password on
4
- <%= link_to "this password reset page", create_session_url(@user.email_address_login_token) %>.
5
-
6
- This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
7
- </p>
8
- <% end %>
@@ -1,6 +0,0 @@
1
- <% if @user %>
2
- You can reset your password on
3
- <%= create_session_url(@user.email_address_login_token) %>
4
-
5
- This link will expire in <%= distance_of_time_in_words(0, @user.email_address_login_token_expires_in) %>.
6
- <% end %>
data/mise.toml DELETED
@@ -1,2 +0,0 @@
1
- [tools]
2
- ruby = "3.2.8"
data/sig/yaag.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Yaag
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end