authtown 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b75bcb24f21f87172f654d1d987c6fba611ffdd03b6a4bc65dc5e8aeed65324c
4
- data.tar.gz: 62111ad44b4391e6a2300e38ede4e55638c4239a3d1f71fd74ce5a22613c9a53
3
+ metadata.gz: 5618c4b915887279ad6bfd3ba639756a63b92d1361fe3c5ef7d64fc1a9787f08
4
+ data.tar.gz: 488925cf2004d158d77893acfa68566469e19b29e03abfe48d6469b4a00ebbf8
5
5
  SHA512:
6
- metadata.gz: f9bd62d8b2e309d9adf91d8751d5d7a8843f7306220052790f98baf97b1c929140fb3f4661ed724df83417cf196a7f4590803f354f7524903e2213de7c59bbdf
7
- data.tar.gz: d34c203ead7a8ae36a0e064cc2c4764d186705d95addc83b1c7d9c3a0ed2896e16e162a2eb80e2784a9ea9a93ece6da075b6466e21266a95fc1e4fb2abf9ea89
6
+ metadata.gz: 89644f9c86b9202faa8616c868956aa59a1f668418737092cb27181ba2a4d147886b6566a24c7110f3d91176acb279b92999c2cdd07b476b16466a9d4cdca1ea
7
+ data.tar.gz: 7323afa6ab4142c31a4eaf5f3e22d64fa8a7b0a106075328b299413bf2e7569ddad1017c7b428ca00a44938fd1a703b722def67e258c772816f75b8b3118b9cb
data/CHANGELOG.md CHANGED
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- - ...
10
+ ## [0.2.0] - 2024-04-03
11
+
12
+ - Integration with new bridgetown_sequel gem tested
11
13
 
12
14
  ## [0.1.0] - YYYY-MM-DD
13
15
 
@@ -9,7 +9,11 @@ module Authtown
9
9
  rodauth.load_memory
10
10
 
11
11
  init_current_user
12
- Lifeform::Form.rodauth = rodauth
12
+
13
+ # hook :authtown, :initialized do |rodauth|
14
+ # Lifeform::Form.rodauth = rodauth
15
+ # end
16
+ Bridgetown::Hooks.trigger(:authtown, :initialized, rodauth)
13
17
 
14
18
  r.on "auth" do
15
19
  r.rodauth
@@ -20,7 +24,8 @@ module Authtown
20
24
  Authtown::Current.user =
21
25
  if rodauth.logged_in?
22
26
  account_id = rodauth.account_from_session[:id]
23
- User.find(account_id)
27
+ user_class = bridgetown_site.config.authtown.user_class_resolver.()
28
+ user_class[account_id]
24
29
  end
25
30
  end
26
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authtown
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/authtown.rb CHANGED
@@ -5,35 +5,50 @@ require "mail"
5
5
  require "authtown/builder"
6
6
  require "authtown/view_mixin"
7
7
 
8
- # REQUIRES:
9
- # init :"bridgetown-activerecord", sequel_support: :postgres
10
-
11
- # ActiveRecord schema:
8
+ # rubocop:disable Layout/LineLength
9
+ ### Simple migration strategy:
12
10
  #
13
- # class CreateUsers < ActiveRecord::Migration[7.0]
14
- # def change
15
- # create_table :users do |t|
16
- # t.string :email, null: false, index: { unique: true }
17
- # t.string :first_name
18
- # t.string :password_hash, null: false
19
- # t.timestamps
11
+ # Sequel.migration do
12
+ # change do
13
+ # extension :date_arithmetic
14
+
15
+ # create_table(:users) do
16
+ # primary_key :id, type: :Bignum
17
+ # citext :email, null: false
18
+ # constraint :valid_email, email: /^[^,;@ \r\n]+@[^,@; \r\n]+\.[^,@; \r\n]+$/
19
+ # String :first_name
20
+ # String :password_hash, null: false
21
+ # index :email, unique: true
20
22
  # end
21
- # end
22
- # end
23
- #
24
- # class CreateAccountRememberKeys < ActiveRecord::Migration[7.0]
25
- # def change
26
- # create_table :account_remember_keys do |t|
27
- # t.foreign_key :users, column: :id
28
- # t.string :key, null: false
29
- # t.datetime :deadline, null: false
23
+
24
+ # # Used by the remember me feature
25
+ # create_table(:account_remember_keys) do
26
+ # foreign_key :id, :users, primary_key: true, type: :Bignum
27
+ # String :key, null: false
28
+ # DateTime :deadline, { null: false, default: Sequel.date_add(Sequel::CURRENT_TIMESTAMP, days: 30) }
29
+ # end
30
+
31
+ # create_table(:account_password_reset_keys) do
32
+ # foreign_key :id, :users, primary_key: true, type: :Bignum
33
+ # String :key, null: false
34
+ # DateTime :deadline, { null: false, default: Sequel.date_add(Sequel::CURRENT_TIMESTAMP, days: 1) }
35
+ # DateTime :email_last_sent, null: false, default: Sequel::CURRENT_TIMESTAMP
30
36
  # end
31
37
  # end
32
38
  # end
39
+ # rubocop:enable Layout/LineLength
33
40
 
34
- class Authtown::Current < ActiveSupport::CurrentAttributes
35
- # @!parse def self.user = User.new
36
- attribute :user
41
+ Thread.attr_accessor :authtown_state
42
+ class Authtown::Current
43
+ class << self
44
+ def thread_state = Thread.current.authtown_state ||= {}
45
+
46
+ def user=(new_user)
47
+ thread_state[:user] = new_user
48
+ end
49
+
50
+ def user = thread_state[:user]
51
+ end
37
52
  end
38
53
 
39
54
  # rubocop:disable Metrics/BlockLength
@@ -42,9 +57,13 @@ end
42
57
  Bridgetown.initializer :authtown do |
43
58
  config,
44
59
  rodauth_config: nil,
45
- account_landing_page: "/account/profile"
60
+ account_landing_page: "/account/profile",
61
+ user_class_resolver: -> { User }
46
62
  |
47
63
 
64
+ config.authtown ||= {}
65
+ config.authtown.user_class_resolver ||= user_class_resolver
66
+
48
67
  config.only :server do
49
68
  require "authtown/routes/rodauth"
50
69
 
@@ -56,9 +75,11 @@ Bridgetown.initializer :authtown do |
56
75
  app.plugin(:sessions, secret:)
57
76
 
58
77
  app.plugin :rodauth do
59
- enable :login, :logout, :create_account, :remember, :reset_password
78
+ enable :login, :logout, :create_account, :remember, :reset_password, :internal_request
60
79
  hmac_secret secret
61
80
 
81
+ base_url config.url
82
+
62
83
  prefix "/auth"
63
84
 
64
85
  login_redirect account_landing_page
@@ -92,7 +113,7 @@ Bridgetown.initializer :authtown do |
92
113
  # Make sure timestamps get saved
93
114
  account[:created_at] = account[:updated_at] = Time.now
94
115
 
95
- account[:first_name] = param(:first_name)
116
+ account[:first_name] = param(:first_name) if param(:first_name)
96
117
  end
97
118
 
98
119
  after_login do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authtown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-27 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.3.3
157
+ rubygems_version: 3.5.3
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Rodauth integration for Bridgetown