-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from daveminer/pow-impl
Pow impl
- Loading branch information
Showing
21 changed files
with
359 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Basket.Users.User do | ||
@moduledoc false | ||
|
||
use Ecto.Schema | ||
use Pow.Ecto.Schema | ||
|
||
use Pow.Extension.Ecto.Schema, | ||
extensions: [PowResetPassword, PowEmailConfirmation] | ||
|
||
def changeset(user_or_changeset, attrs) do | ||
user_or_changeset | ||
|> pow_changeset(attrs) | ||
|> pow_extension_changeset(attrs) | ||
end | ||
|
||
schema "users" do | ||
pow_user_fields() | ||
|
||
timestamps() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule BasketWeb.PowInvitation.InvitationHTML do | ||
use BasketWeb, :html | ||
|
||
embed_templates "invitation_html/*" | ||
end |
35 changes: 35 additions & 0 deletions
35
lib/basket_web/controllers/pow_invitation/invitation_html/edit.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<div class="mx-auto max-w-sm"> | ||
<.header class="text-center"> | ||
Register | ||
<:subtitle> | ||
Already have an account? | ||
<.link | ||
navigate={Pow.Phoenix.Routes.path_for(@conn, Pow.Phoenix.SessionController, :new)} | ||
class="font-semibold text-brand hover:underline" | ||
> | ||
Sign in | ||
</.link> | ||
now. | ||
</:subtitle> | ||
</.header> | ||
|
||
<.simple_form :let={f} for={@changeset} as={:user} action={@action} phx-update="ignore"> | ||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input | ||
field={f[Pow.Ecto.Schema.user_id_field(@changeset)]} | ||
type={(Pow.Ecto.Schema.user_id_field(@changeset) == :email && "email") || "text"} | ||
label={Phoenix.Naming.humanize(Pow.Ecto.Schema.user_id_field(@changeset))} | ||
required | ||
/> | ||
<.input field={f[:password]} type="password" label="Password" required /> | ||
<.input field={f[:password_confirmation]} type="password" label="Confirm password" required /> | ||
|
||
<:actions> | ||
<.button phx-disable-with="Submitting..." class="w-full"> | ||
Submit <span aria-hidden="true">→</span> | ||
</.button> | ||
</:actions> | ||
</.simple_form> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
lib/basket_web/controllers/pow_invitation/invitation_html/new.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="mx-auto max-w-sm"> | ||
<.header class="text-center"> | ||
Invite | ||
</.header> | ||
|
||
<.simple_form :let={f} for={@changeset} as={:user} action={@action} phx-update="ignore"> | ||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input | ||
field={f[Pow.Ecto.Schema.user_id_field(@changeset)]} | ||
type={(Pow.Ecto.Schema.user_id_field(@changeset) == :email && "email") || "text"} | ||
label={Phoenix.Naming.humanize(Pow.Ecto.Schema.user_id_field(@changeset))} | ||
required | ||
/> | ||
|
||
<:actions> | ||
<.button phx-disable-with="Submitting..." class="w-full"> | ||
Submit <span aria-hidden="true">→</span> | ||
</.button> | ||
</:actions> | ||
</.simple_form> | ||
</div> |
42 changes: 42 additions & 0 deletions
42
lib/basket_web/controllers/pow_invitation/invitation_html/show.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div class="mx-auto max-w-sm"> | ||
<.header class="text-center"> | ||
Invitation URL | ||
<:subtitle> | ||
Please send the following URL to the invitee. | ||
</:subtitle> | ||
</.header> | ||
|
||
<div class="space-y-8 bg-white mt-10"> | ||
<div class="flex items-center gap-1 text-sm leading-6 text-zinc-600"> | ||
<.input name="invite-url" type="text" id="invite-url" value={@url} class="mt-0" readonly /> | ||
<.button | ||
phx-click={JS.dispatch("phx:share", to: "#invite-url")} | ||
aria-label="Share" | ||
class="mt-2" | ||
> | ||
<.icon name="hero-arrow-up-on-square" class="w-6 h-6" /> | ||
</.button> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript"> | ||
window.addEventListener("phx:share", (event) => { | ||
let url = event.target.value; | ||
navigator.clipboard.writeText(url).then( | ||
() => { | ||
/* clipboard successfully set */ | ||
}, | ||
() => { | ||
/* clipboard write failed */ | ||
}); | ||
navigator.share({url: url}).then( | ||
() => { | ||
/* share succeeded */ | ||
}, | ||
() => { | ||
/* share failed */ | ||
}); | ||
}) | ||
</script> |
5 changes: 5 additions & 0 deletions
5
lib/basket_web/controllers/pow_reset_password/reset_password_html.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule BasketWeb.PowResetPassword.ResetPasswordHTML do | ||
use BasketWeb, :html | ||
|
||
embed_templates "reset_password_html/*" | ||
end |
34 changes: 34 additions & 0 deletions
34
lib/basket_web/controllers/pow_reset_password/reset_password_html/edit.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="mx-auto max-w-sm"> | ||
<.header class="text-center"> | ||
Reset password | ||
<:subtitle> | ||
Know your password? | ||
<.link | ||
navigate={Pow.Phoenix.Routes.path_for(@conn, Pow.Phoenix.SessionController, :new)} | ||
class="font-semibold text-brand hover:underline" | ||
> | ||
Sign in | ||
</.link> | ||
now. | ||
</:subtitle> | ||
</.header> | ||
|
||
<.simple_form :let={f} for={@changeset} as={:user} action={@action} phx-update="ignore"> | ||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input field={f[:password]} type="password" label="New password" required /> | ||
<.input | ||
field={f[:password_confirmation]} | ||
type="password" | ||
label="Confirm new password" | ||
required | ||
/> | ||
|
||
<:actions> | ||
<.button phx-disable-with="Submitting..." class="w-full"> | ||
Submit <span aria-hidden="true">→</span> | ||
</.button> | ||
</:actions> | ||
</.simple_form> | ||
</div> |
28 changes: 28 additions & 0 deletions
28
lib/basket_web/controllers/pow_reset_password/reset_password_html/new.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="mx-auto max-w-sm"> | ||
<.header class="text-center"> | ||
Reset password | ||
<:subtitle> | ||
Know your password? | ||
<.link | ||
navigate={Pow.Phoenix.Routes.path_for(@conn, Pow.Phoenix.SessionController, :new)} | ||
class="font-semibold text-brand hover:underline" | ||
> | ||
Sign in | ||
</.link> | ||
now. | ||
</:subtitle> | ||
</.header> | ||
|
||
<.simple_form :let={f} for={@changeset} as={:user} action={@action} phx-update="ignore"> | ||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input field={f[:email]} type="email" label="Email" required /> | ||
|
||
<:actions> | ||
<.button phx-disable-with="Submitting..." class="w-full"> | ||
Submit <span aria-hidden="true">→</span> | ||
</.button> | ||
</:actions> | ||
</.simple_form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule MyAppWeb.Pow.Mailer do | ||
@moduledoc """ | ||
Stub mailer implementation for initial Pow config | ||
""" | ||
|
||
use Pow.Phoenix.Mailer | ||
require Logger | ||
|
||
def cast(%{user: user, subject: subject, text: text, html: html, assigns: _assigns}) do | ||
# Build email struct to be used in `process/1` | ||
|
||
%{to: user.email, subject: subject, text: text, html: html} | ||
end | ||
|
||
def process(email) do | ||
# Send email | ||
|
||
Logger.debug("E-mail sent: #{inspect(email)}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule BasketWeb.PowEmailConfirmationMail do | ||
@moduledoc false | ||
|
||
use BasketWeb, :mail | ||
|
||
def email_confirmation(assigns) do | ||
%Pow.Phoenix.Mailer.Template{ | ||
subject: "Confirm your email address", | ||
html: ~H""" | ||
<h3>Hi</h3> | ||
<p>Please use the following link to confirm your e-mail address:</p> | ||
<p><a href="{@url}">{@url}</a></p> | ||
""", | ||
text: ~P""" | ||
Hi, | ||
Please use the following link to confirm your e-mail address: | ||
<%= @url %> | ||
""" | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule BasketWeb.PowInvitationMail do | ||
@moduledoc false | ||
|
||
use BasketWeb, :mail | ||
|
||
def invitation(assigns) do | ||
%Pow.Phoenix.Mailer.Template{ | ||
subject: "You've been invited", | ||
html: ~H""" | ||
<h3>Hi,</h3> | ||
<p> | ||
You've been invited by <strong><%= @invited_by_user_id %></strong>. Please use the following link to accept your invitation: | ||
</p> | ||
<p><a href="{@url}">{@url}</a></p> | ||
""", | ||
text: ~P""" | ||
Hi, | ||
You've been invited by <%= @invited_by_user_id %>. Please use the following link to accept your invitation: | ||
{@url} | ||
""" | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule BasketWeb.PowResetPasswordMail do | ||
@moduledoc false | ||
|
||
use BasketWeb, :mail | ||
|
||
def reset_password(assigns) do | ||
%Pow.Phoenix.Mailer.Template{ | ||
subject: "Reset password link", | ||
html: ~H""" | ||
<h3>Hi,</h3> | ||
<p>Please use the following link to reset your password:</p> | ||
<p><a href="{@url}"><%= @url %></a></p> | ||
<p>You can disregard this email if you didn't request a password reset.</p> | ||
""", | ||
text: ~P""" | ||
Hi, | ||
Please use the following link to reset your password: | ||
<%= @url %> | ||
You can disregard this email if you didn't request a password reset. | ||
""" | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.