yaag 0.2.0 → 0.4.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 +4 -4
- data/README.md +23 -1
- data/app/channels/application_cable/connection.rb +16 -0
- data/app/models/user.rb +0 -4
- data/lib/generators/authentication/copy/channels_generator.rb +11 -0
- data/lib/generators/authentication/copy/mailers_generator.rb +11 -0
- data/lib/generators/authentication/copy/models_generator.rb +13 -0
- data/lib/yaag/test/sessions_helper.rb +2 -0
- data/lib/yaag/version.rb +1 -1
- data/lib/yaag.rb +7 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18c1b6d3d23b55ad72cad5da0351887ef2342ef4ebeb98a58fd9866315e96a25
|
|
4
|
+
data.tar.gz: eedaef3e610a375ca2ab348f88883ac2205e0ba8c9984f029739755071637d70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a0eb30c69ce82211abbcf60cd54799e51ca9faadf06919d00e362eadb9e881c35a372674d74d306f112d76afc6daf9152042e3a972f38d74cf4e6ec359a83d7
|
|
7
|
+
data.tar.gz: 8653b74715e0ef3ccd4075182ff111b18f11dcf089804c0d736b74b2340926ce5455b14f58cba127b19d71916e5ce1db20ca73ef5bac9a055cd991266fab8e44
|
data/README.md
CHANGED
|
@@ -76,9 +76,29 @@ 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
|
+
|
|
85
|
+
For mailers:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
rails g authentication:copy:mailers
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For models:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
rails g authentication:copy:models
|
|
95
|
+
```
|
|
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
|
+
|
|
79
99
|
### Test helper
|
|
80
100
|
|
|
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`:
|
|
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`:
|
|
82
102
|
|
|
83
103
|
```
|
|
84
104
|
class MyControllerTest < ActionDispatch::IntegrationTest
|
|
@@ -88,6 +108,8 @@ class MyControllerTest < ActionDispatch::IntegrationTest
|
|
|
88
108
|
end
|
|
89
109
|
```
|
|
90
110
|
|
|
111
|
+
Note: the example above requires users fixtures to exist, which are not provided by this gem.
|
|
112
|
+
|
|
91
113
|
## Release
|
|
92
114
|
|
|
93
115
|
```bash
|
|
@@ -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
|
data/app/models/user.rb
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Authentication
|
|
2
|
+
module Copy
|
|
3
|
+
class ModelsGenerator < Rails::Generators::Base
|
|
4
|
+
source_root File.expand_path("../../../../", __dir__)
|
|
5
|
+
|
|
6
|
+
def copy_models
|
|
7
|
+
copy_file "app/models/current.rb"
|
|
8
|
+
copy_file "app/models/session.rb"
|
|
9
|
+
copy_file "app/models/user.rb"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/yaag/version.rb
CHANGED
data/lib/yaag.rb
CHANGED
|
@@ -5,9 +5,16 @@ module Yaag
|
|
|
5
5
|
module Test
|
|
6
6
|
autoload :SessionsHelper, "yaag/test/sessions_helper"
|
|
7
7
|
end
|
|
8
|
+
|
|
8
9
|
module PasswordlessLogin
|
|
9
10
|
extend ActiveSupport::Concern
|
|
10
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
|
+
|
|
11
18
|
DEFAULT_LOGIN_TOKEN_EXPIRES_IN = 15.minutes
|
|
12
19
|
|
|
13
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.
|
|
4
|
+
version: 0.4.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-
|
|
11
|
+
date: 2026-01-14 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,7 +38,10 @@ 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
|
|
43
|
+
- lib/generators/authentication/copy/mailers_generator.rb
|
|
44
|
+
- lib/generators/authentication/copy/models_generator.rb
|
|
41
45
|
- lib/generators/authentication/copy/views_generator.rb
|
|
42
46
|
- lib/generators/authentication/install_generator.rb
|
|
43
47
|
- lib/generators/authentication/templates/README
|