yaag 0.3.0 → 0.5.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: 9574bdab53be3c4f08a3b5d53a94c13c4112250d508a285ca15a0d2d92eadecb
4
- data.tar.gz: '0396903f2a8a2f9995e9cfeedb97714fc712bf91db65f0485bfa9bb81f4f6a75'
3
+ metadata.gz: ef8eaf9e91e728a74a3bd0c16909872b49fb41b64f21b72c92cf2c5f6a22a16f
4
+ data.tar.gz: 5993f5e5bf4c8e673acf2681ced1b1fba7045cd0ef0ee81accab7ede25f596b9
5
5
  SHA512:
6
- metadata.gz: 4250c7ab8385ebd4ae19737ad206f5cc7ec4fb24708f88cb50fd44d7b176ed55983028b862580710bb933995bc35366b7470b5fa3669b9a0c132befcb2ef4567
7
- data.tar.gz: 4e28c123f2295fe0933b2324ce6add25cd64548570bd0e4434f9ee84fcfb1c148b198e2768b1a1092b268c77c7f211ccaf926e38864b3e2e686473b26204f440
6
+ metadata.gz: e2ae3ce9d801ac9995c66ecef56c7f6503220d1afd28756abcd129e5e5849bef47989e49a2b7b82ab12e02fa2e580a389370c3ca895eae1fd4056424a3b6318d
7
+ data.tar.gz: 7bcd88fc4e182b0bcd4072af9059391f52c726f791dcbede06499ff8f0579ff54fe4ca0ce510a3c06e80aa5f06fd79751b7be3e36e7ab4310c34dd121534e3b3
data/README.md CHANGED
@@ -76,6 +76,12 @@ For controllers (including concerns):
76
76
  rails g authentication:copy:controllers
77
77
  ```
78
78
 
79
+ For channels (application_cable/connection.rb):
80
+
81
+ ```bash
82
+ rails g authentication:copy:channels
83
+ ```
84
+
79
85
  For mailers:
80
86
 
81
87
  ```bash
@@ -88,6 +94,8 @@ For models:
88
94
  rails g authentication:copy:models
89
95
  ```
90
96
 
97
+ Note: some generators may copy several files into the application folder, it's safe to delete the ones that don't require modification.
98
+
91
99
  ### Test helper
92
100
 
93
101
  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 your test class to access the methods `sign_in_as` and `sign_out`:
@@ -0,0 +1,16 @@
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
@@ -17,6 +17,10 @@ module Authentication
17
17
  resume_session
18
18
  end
19
19
 
20
+ def current_user
21
+ Current.user
22
+ end
23
+
20
24
  def require_authentication
21
25
  resume_session || request_authentication
22
26
  end
data/app/models/user.rb CHANGED
@@ -1,7 +1,3 @@
1
1
  class User < ApplicationRecord
2
2
  include Yaag::PasswordlessLogin
3
- has_passwordless_login
4
- has_many :sessions, dependent: :destroy
5
-
6
- normalizes :email_address, with: ->(e) { e.strip.downcase }
7
3
  end
@@ -0,0 +1,11 @@
1
+ module Authentication
2
+ module Copy
3
+ class ChannelsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../../../", __dir__)
5
+
6
+ def copy_channels
7
+ copy_file "app/channels/application_cable/connection.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -16,6 +16,11 @@ module Yaag
16
16
  end
17
17
 
18
18
  alias :sign_in :sign_in_as
19
+
20
+ def assert_notice(text)
21
+ follow_redirect!
22
+ assert_select "div", /#{text}/
23
+ end
19
24
  end
20
25
  end
21
26
  end
data/lib/yaag/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaag
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/yaag.rb CHANGED
@@ -9,6 +9,12 @@ module Yaag
9
9
  module PasswordlessLogin
10
10
  extend ActiveSupport::Concern
11
11
 
12
+ included do
13
+ has_passwordless_login
14
+ has_many :sessions, dependent: :destroy
15
+ normalizes :email_address, with: ->(e) { e.strip.downcase }
16
+ end
17
+
12
18
  DEFAULT_LOGIN_TOKEN_EXPIRES_IN = 15.minutes
13
19
 
14
20
  class << self
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.3.0
4
+ version: 0.5.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-14 00:00:00.000000000 Z
11
+ date: 2026-02-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Yet Another Authentication Gem (YAAG) provides passwordless authentication
14
14
  for your Ruby on Rails app, all it takes is the user's e-mail address.
@@ -21,6 +21,7 @@ files:
21
21
  - MIT-LICENSE
22
22
  - README.md
23
23
  - Rakefile
24
+ - app/channels/application_cable/connection.rb
24
25
  - app/controllers/concerns/authentication.rb
25
26
  - app/controllers/sessions_controller.rb
26
27
  - app/controllers/signins_controller.rb
@@ -37,6 +38,7 @@ files:
37
38
  - db/migrate/20260108164812_create_users.rb
38
39
  - db/migrate/20260108165215_create_sessions.rb
39
40
  - lib/generators/authentication/USAGE
41
+ - lib/generators/authentication/copy/channels_generator.rb
40
42
  - lib/generators/authentication/copy/controllers_generator.rb
41
43
  - lib/generators/authentication/copy/mailers_generator.rb
42
44
  - lib/generators/authentication/copy/models_generator.rb