From e2fd8de68481a11bd560d8f82cff51a734d95833 Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 12:39:31 -0500
Subject: [PATCH 01/37] Add Pow
---
registrations/lib/registrations/users/user.ex | 10 ++++++++++
registrations/mix.exs | 1 +
registrations/mix.lock | 1 +
.../migrations/20240714173901_create_users.exs | 14 ++++++++++++++
4 files changed, 26 insertions(+)
create mode 100644 registrations/lib/registrations/users/user.ex
create mode 100644 registrations/priv/repo/migrations/20240714173901_create_users.exs
diff --git a/registrations/lib/registrations/users/user.ex b/registrations/lib/registrations/users/user.ex
new file mode 100644
index 00000000..483e483d
--- /dev/null
+++ b/registrations/lib/registrations/users/user.ex
@@ -0,0 +1,10 @@
+defmodule Registrations.Users.User do
+ use Ecto.Schema
+ use Pow.Ecto.Schema
+
+ schema "users" do
+ pow_user_fields()
+
+ timestamps()
+ end
+end
diff --git a/registrations/mix.exs b/registrations/mix.exs
index 90ffc737..b8a18220 100644
--- a/registrations/mix.exs
+++ b/registrations/mix.exs
@@ -42,6 +42,7 @@ defmodule Registrations.Mixfile do
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:plug_cowboy, "~> 2.1"},
{:plug, "~> 1.7"},
+ {:pow, "~> 1.0.28"},
{:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false},
{:hound, github: "backspace/hound", ref: "malgasm-plus-warning-fixes", only: :test},
{:ex_machina, "~> 2.7.0", only: :test},
diff --git a/registrations/mix.lock b/registrations/mix.lock
index d9593f67..f004fae1 100644
--- a/registrations/mix.lock
+++ b/registrations/mix.lock
@@ -45,6 +45,7 @@
"plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"},
"plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"},
"postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"},
+ "pow": {:hex, :pow, "1.0.28", "b2cc32673e3fd138db6bd7e0656d826b287800d60f4139ed3c3fa6df926f1250", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.3.0 and < 1.8.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 2.0.0 and < 4.0.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, ">= 1.5.0 and < 2.0.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "e03f6ae9a536153f8491e3ef7bb0908f5494756905997611abb204ce23b4d64d"},
"premailex": {:hex, :premailex, "0.3.19", "c26ff9c712c08e574d1792f2cfed638e7c7a5e353b5a4db7a40487c8130fa37c", [:mix], [{:certifi, ">= 0.0.0", [hex: :certifi, repo: "hexpm", optional: true]}, {:floki, "~> 0.19", [hex: :floki, repo: "hexpm", optional: false]}, {:meeseeks, "~> 0.11", [hex: :meeseeks, repo: "hexpm", optional: true]}, {:ssl_verify_fun, ">= 0.0.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: true]}], "hexpm", "18f3772f4b30ffe82f670c2714b2d3221eb9face69e38bb1674b6e570b7c0aff"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
diff --git a/registrations/priv/repo/migrations/20240714173901_create_users.exs b/registrations/priv/repo/migrations/20240714173901_create_users.exs
new file mode 100644
index 00000000..867eaa2e
--- /dev/null
+++ b/registrations/priv/repo/migrations/20240714173901_create_users.exs
@@ -0,0 +1,14 @@
+defmodule Registrations.Repo.Migrations.CreateUsers do
+ use Ecto.Migration
+
+ def change do
+ create table(:users) do
+ add :email, :string, null: false
+ add :password_hash, :string
+
+ timestamps()
+ end
+
+ create unique_index(:users, [:email])
+ end
+end
From 4c1c813a97b066405f8043608b120db6562081ba Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 12:39:54 -0500
Subject: [PATCH 02/37] Add Pow session to endpoint
It failed to insert this automatically, formatting?
---
registrations/lib/registrations_web/endpoint.ex | 2 ++
1 file changed, 2 insertions(+)
diff --git a/registrations/lib/registrations_web/endpoint.ex b/registrations/lib/registrations_web/endpoint.ex
index 246314da..a40606ab 100644
--- a/registrations/lib/registrations_web/endpoint.ex
+++ b/registrations/lib/registrations_web/endpoint.ex
@@ -43,5 +43,7 @@ defmodule RegistrationsWeb.Endpoint do
max_age: 60 * 60 * 24 * 365
)
+ plug(Pow.Plug.Session, otp_app: :registrations)
+
plug(RegistrationsWeb.Router)
end
From dfd435763444276921f70840c567f0eb13d28b48 Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 12:47:56 -0500
Subject: [PATCH 03/37] Change migration
This adapts the existing table, although do I really need
that? Maybe, probably.
---
.../migrations/20240714173901_create_users.exs | 14 --------------
.../20240714173901_update_users_for_pow.exs | 11 +++++++++++
2 files changed, 11 insertions(+), 14 deletions(-)
delete mode 100644 registrations/priv/repo/migrations/20240714173901_create_users.exs
create mode 100644 registrations/priv/repo/migrations/20240714173901_update_users_for_pow.exs
diff --git a/registrations/priv/repo/migrations/20240714173901_create_users.exs b/registrations/priv/repo/migrations/20240714173901_create_users.exs
deleted file mode 100644
index 867eaa2e..00000000
--- a/registrations/priv/repo/migrations/20240714173901_create_users.exs
+++ /dev/null
@@ -1,14 +0,0 @@
-defmodule Registrations.Repo.Migrations.CreateUsers do
- use Ecto.Migration
-
- def change do
- create table(:users) do
- add :email, :string, null: false
- add :password_hash, :string
-
- timestamps()
- end
-
- create unique_index(:users, [:email])
- end
-end
diff --git a/registrations/priv/repo/migrations/20240714173901_update_users_for_pow.exs b/registrations/priv/repo/migrations/20240714173901_update_users_for_pow.exs
new file mode 100644
index 00000000..9884a92b
--- /dev/null
+++ b/registrations/priv/repo/migrations/20240714173901_update_users_for_pow.exs
@@ -0,0 +1,11 @@
+defmodule Registrations.Repo.Migrations.CreateUsers do
+ use Ecto.Migration
+
+ def change do
+ rename table(:users), :crypted_password, to: :password_hash
+
+ alter table(:users) do
+ modify :email, :string, null: false
+ end
+ end
+end
From 0d0e37352e39d3391228530d2e072b16ab53a2d4 Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 13:26:19 -0500
Subject: [PATCH 04/37] Add more blueprint changes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
I ran the install command in a fresh application to see
some of these… sad
---
registrations/config/config.exs | 4 ++++
registrations/lib/registrations/users/user.ex | 10 ----------
registrations/lib/registrations_web/models/user.ex | 12 ++++--------
registrations/lib/registrations_web/router.ex | 7 +++++++
4 files changed, 15 insertions(+), 18 deletions(-)
delete mode 100644 registrations/lib/registrations/users/user.ex
diff --git a/registrations/config/config.exs b/registrations/config/config.exs
index 2038425b..1461586e 100644
--- a/registrations/config/config.exs
+++ b/registrations/config/config.exs
@@ -34,6 +34,10 @@ import_config "#{Mix.env()}.exs"
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
+config :registrations, :pow,
+ user: Registrations.User,
+ repo: Registrations.Repo
+
# Configure phoenix generators
config :phoenix, :generators,
migration: true,
diff --git a/registrations/lib/registrations/users/user.ex b/registrations/lib/registrations/users/user.ex
deleted file mode 100644
index 483e483d..00000000
--- a/registrations/lib/registrations/users/user.ex
+++ /dev/null
@@ -1,10 +0,0 @@
-defmodule Registrations.Users.User do
- use Ecto.Schema
- use Pow.Ecto.Schema
-
- schema "users" do
- pow_user_fields()
-
- timestamps()
- end
-end
diff --git a/registrations/lib/registrations_web/models/user.ex b/registrations/lib/registrations_web/models/user.ex
index 2f647d8c..9a974373 100644
--- a/registrations/lib/registrations_web/models/user.ex
+++ b/registrations/lib/registrations_web/models/user.ex
@@ -1,18 +1,14 @@
defmodule RegistrationsWeb.User do
+ use Ecto.Schema
+ use Pow.Ecto.Schema
+
use RegistrationsWeb, :model
alias Registrations.Repo
@primary_key {:id, :binary_id, autogenerate: true}
schema "users" do
- field(:email, RegistrationsWeb.DowncasedString)
- field(:crypted_password, :string)
- field(:password, :string, virtual: true)
- field(:recovery_hash, :string)
-
- field(:new_password, :string, virtual: true)
- field(:new_password_confirmation, :string, virtual: true)
- field(:current_password, :string, virtual: true)
+ pow_user_fields()
field(:admin, :boolean)
diff --git a/registrations/lib/registrations_web/router.ex b/registrations/lib/registrations_web/router.ex
index f3a6b804..d7297a38 100644
--- a/registrations/lib/registrations_web/router.ex
+++ b/registrations/lib/registrations_web/router.ex
@@ -1,5 +1,6 @@
defmodule RegistrationsWeb.Router do
use RegistrationsWeb, :router
+ use Pow.Phoenix.Router
pipeline :browser do
plug(:accepts, ["html"])
@@ -17,6 +18,12 @@ defmodule RegistrationsWeb.Router do
plug(RegistrationsWeb.Plugs.CurrentUser)
end
+ scope "/" do
+ pipe_through :browser
+
+ pow_routes()
+ end
+
scope "/", RegistrationsWeb do
# Use the default browser stack
pipe_through(:browser)
From fda8c70d2bbf3385535cf1c95c4dc4c067dc6aea Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 13:32:04 -0500
Subject: [PATCH 05/37] Fix Pow config for module name
---
registrations/config/config.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/registrations/config/config.exs b/registrations/config/config.exs
index 1461586e..adda72cd 100644
--- a/registrations/config/config.exs
+++ b/registrations/config/config.exs
@@ -35,7 +35,7 @@ import_config "#{Mix.env()}.exs"
config :phoenix, :json_library, Jason
config :registrations, :pow,
- user: Registrations.User,
+ user: RegistrationsWeb.User,
repo: Registrations.Repo
# Configure phoenix generators
From 19f4112c4fda3439d9d0546fb28df2ddd1bda028 Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 13:46:31 -0500
Subject: [PATCH 06/37] Rename existing User changeset function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This was clashing and the hash wasn’t saving.
---
.../registrations_web/controllers/registration_controller.ex | 4 ++--
registrations/lib/registrations_web/models/user.ex | 2 +-
registrations/test/models/user_test.exs | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/registrations/lib/registrations_web/controllers/registration_controller.ex b/registrations/lib/registrations_web/controllers/registration_controller.ex
index 1f857526..bcdc6a62 100644
--- a/registrations/lib/registrations_web/controllers/registration_controller.ex
+++ b/registrations/lib/registrations_web/controllers/registration_controller.ex
@@ -3,7 +3,7 @@ defmodule RegistrationsWeb.RegistrationController do
alias RegistrationsWeb.User
def new(conn, _params) do
- changeset = User.changeset(%User{})
+ changeset = User.old_changeset(%User{})
conn =
case Application.get_env(:registrations, :registration_closed) do
@@ -22,7 +22,7 @@ defmodule RegistrationsWeb.RegistrationController do
end
def create(conn, %{"user" => user_params}) do
- changeset = User.changeset(%User{}, user_params)
+ changeset = User.old_changeset(%User{}, user_params)
case RegistrationsWeb.Registration.create(changeset, Registrations.Repo) do
{:ok, user} ->
diff --git a/registrations/lib/registrations_web/models/user.ex b/registrations/lib/registrations_web/models/user.ex
index 9a974373..1e5b8dd0 100644
--- a/registrations/lib/registrations_web/models/user.ex
+++ b/registrations/lib/registrations_web/models/user.ex
@@ -40,7 +40,7 @@ defmodule RegistrationsWeb.User do
If no params are provided, an invalid changeset is returned
with no validation performed.
"""
- def changeset(model, params \\ %{}) do
+ def old_changeset(model, params \\ %{}) do
model
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
diff --git a/registrations/test/models/user_test.exs b/registrations/test/models/user_test.exs
index aba67b87..fad08fdd 100644
--- a/registrations/test/models/user_test.exs
+++ b/registrations/test/models/user_test.exs
@@ -8,12 +8,12 @@ defmodule RegistrationsWeb.UserTest do
@invalid_attrs %{}
test "changeset with valid attributes" do
- changeset = User.changeset(%User{}, @valid_attrs)
+ changeset = User.old_changeset(%User{}, @valid_attrs)
assert changeset.valid?
end
test "changeset with invalid attributes" do
- changeset = User.changeset(%User{}, @invalid_attrs)
+ changeset = User.old_changeset(%User{}, @invalid_attrs)
refute changeset.valid?
end
From 8d2c2e7468de312e60e729855be7deb77c100b3e Mon Sep 17 00:00:00 2001
From: Buck Doyle
Date: Sun, 14 Jul 2024 14:51:19 -0500
Subject: [PATCH 07/37] Add overridden templates
---
registrations/config/config.exs | 1 +
.../templates/pow/registration/edit.html.eex | 37 +++++++++++++++++++
.../templates/pow/registration/new.html.eex | 32 ++++++++++++++++
.../templates/pow/session/new.html.eex | 28 ++++++++++++++
.../views/pow/registration_view.ex | 3 ++
.../views/pow/session_view.ex | 3 ++
6 files changed, 104 insertions(+)
create mode 100644 registrations/lib/registrations_web/templates/pow/registration/edit.html.eex
create mode 100644 registrations/lib/registrations_web/templates/pow/registration/new.html.eex
create mode 100644 registrations/lib/registrations_web/templates/pow/session/new.html.eex
create mode 100644 registrations/lib/registrations_web/views/pow/registration_view.ex
create mode 100644 registrations/lib/registrations_web/views/pow/session_view.ex
diff --git a/registrations/config/config.exs b/registrations/config/config.exs
index adda72cd..22bd0c2f 100644
--- a/registrations/config/config.exs
+++ b/registrations/config/config.exs
@@ -35,6 +35,7 @@ import_config "#{Mix.env()}.exs"
config :phoenix, :json_library, Jason
config :registrations, :pow,
+ web_module: RegistrationsWeb,
user: RegistrationsWeb.User,
repo: Registrations.Repo
diff --git a/registrations/lib/registrations_web/templates/pow/registration/edit.html.eex b/registrations/lib/registrations_web/templates/pow/registration/edit.html.eex
new file mode 100644
index 00000000..f6fc6a56
--- /dev/null
+++ b/registrations/lib/registrations_web/templates/pow/registration/edit.html.eex
@@ -0,0 +1,37 @@
+ The secret society is so secret that the venue for initiation cannot be shared publicly. Once it is decided, it will be shared with those who <%= link "register", to: Routes.registration_path(@conn, :new) %>. If you have questions about travel, please write to us after registering. The secret society is so secret that the venue for initiation cannot be shared publicly. Once it is decided, it will be shared with those who <%= link "register", to: Routes.pow_registration_path(@conn, :new) %>. If you have questions about travel, please write to us after registering. The adventure will begin at <%= start_time() %>. If you have obligations that prevent you from being present at the beginning let us know and we can discuss how to accommodate you. Do you have accessibility needs we should know about? Please tell us <%= link "when you register", to: Routes.registration_path(@conn, :new) %> and we will work with you to ensure you can participate. Do you have accessibility needs we should know about? Please tell us <%= link "when you register", to: Routes.pow_registration_path(@conn, :new) %> and we will work with you to ensure you can participate. You must <%= link "register", to: Routes.registration_path(@conn, :new) %> to attend the event, as scheduling each rendezvous depends on knowing who will attend. If you’re uncertain whether you can make it, register anyway; you can cancel up until the day before. You must <%= link "register", to: Routes.pow_registration_path(@conn, :new) %> to attend the event, as scheduling each rendezvous depends on knowing who will attend. If you’re uncertain whether you can make it, register anyway; you can cancel up until the day before.
To learn more about our technique, please
- <%= link "register", to: Routes.registration_path(@conn, :new) %>
+ <%= link "register", to: Routes.pow_registration_path(@conn, :new) %>
to attend the participatory demonstration
evening on FIXME, location to be announced.
Do you have accessibility needs we should know about? Please tell us
- <%= link "when you register", to: Routes.registration_path(@conn, :new) %>
+ <%= link "when you register", to: Routes.pow_registration_path(@conn, :new) %>
and we will work with you to ensure you can participate.
Change Password
+
+ <%= form_for @changeset, @action, [as: :user], fn f -> %>
+ <%= render RegistrationsWeb.SharedView, "errors.html", changeset: @changeset, f: f %>
+
+ Register
+
+ <%= form_for @changeset, Routes.registration_path(@conn, :create), fn f -> %>
+ <%= render RegistrationsWeb.SharedView, "errors.html", changeset: @changeset, f: f %>
+
+ Sign in
+
+
+ <%= link "Forgot your password?", to: Routes.reset_path(@conn, :new), class: "forgot" %>
+ <%= link "Register", to: Routes.pow_registration_path(@conn, :new) %>
+ <%= form_for @changeset, @action, [as: :user], fn f -> %>
+ <%= render RegistrationsWeb.SharedView, "errors.html", changeset: @changeset, f: f %>
+
+ When and where?
- Accessibility
- Registration
- Tell me more!
Accessibility
Registration
You must - <%= link "register", to: Routes.registration_path(@conn, :new) %> + <%= link "register", to: Routes.pow_registration_path(@conn, :new) %> to attend the event, as each therapeutic journey is hand-tuned. If you’re uncertain whether you can make it, register anyway; you can cancel up until the day before. diff --git a/registrations/lib/registrations_web/templates/pow/registration/new.html.eex b/registrations/lib/registrations_web/templates/pow/registration/new.html.eex index 9d96fe34..0d8db6ab 100644 --- a/registrations/lib/registrations_web/templates/pow/registration/new.html.eex +++ b/registrations/lib/registrations_web/templates/pow/registration/new.html.eex @@ -2,7 +2,7 @@
This is not the registration form, that’s <%= link "here", to: Routes.registration_path(@conn, :new) %>.
+This is not the registration form, that’s <%= link "here", to: Routes.pow_registration_path(@conn, :new) %>.
<%= form_for @conn, Routes.page_path(@conn, :questions), [as: :question], fn f -> %>Oops, something went wrong! Please check the errors below.
+Oops, something went wrong! Please check the errors below.
+Oops, something went wrong! Please check the errors below.
-Oops, something went wrong! Please check the errors below.
-Registration is closed; however, you may continue and we will email you
+