Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/731
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Dec 16, 2024
1 parent a7ea899 commit c2f463b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 55 deletions.
112 changes: 59 additions & 53 deletions lib/components/login/login_view_live.sface
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
class="w-full md:ml-0"
opts={[id: "login-form"]}
>
<input type="hidden" name="go" value={e(@form, :changes, :go, nil)}>
<input
type="hidden"
name="go"
value={e(debug(@form), :params, :go, nil) || e(debug(@form), :source, :changes, :go, nil)}
/>
{!-- <%= hidden_input f, :go %> --}

<StatelessComponent
Expand All @@ -14,62 +18,64 @@
/>
{!-- <%= f = form_for @form, path(:login, :create), class: "w-full md:ml-0" %> --}
{!-- <%= case @form.errors[:form] do %> --}
{#case @error || @form.errors[:form]}
{#match {"not_found", _}}
{!-- <%= {"not_found",_} -> %> --}
<div role="status" class="alert alert-warning">
<div class="flex flex-1">
<label>
{l("Account not found. Either your username or password was incorrect. Did you want to ")} <LinkLive to={path(:signup)} class="font-bold underline text-neutral">sign up</LinkLive> ?
</label>
</div>
</div>
{#match {"email_not_confirmed", _}}
{!-- <%= {"email_not_confirmed",_} -> %> --}
<div role="status" class="alert alert-warning">
<div class="flex flex-1">
<label>
{l(
"You need to to click the link in the email you should have received to verify your email address. Need to have it "
)} <LinkLive
to={path(Bonfire.UI.Me.ConfirmEmailController)}
class="font-bold underline text-neutral"
>resent</LinkLive> ?
</label>
{#for {_key, error} <- Enums.filter_empty(@form.errors, nil) || [error: @error]}
{#case error}
{#match {"not_found", _}}
{!-- <%= {"not_found",_} -> %> --}
<div role="status" class="alert alert-warning">
<div class="flex flex-1">
<label>
{l("Account not found. Either your username or password was incorrect. Did you want to ")} <LinkLive to={path(:signup)} class="font-bold underline text-neutral">sign up</LinkLive> ?
</label>
</div>
</div>
</div>
{#match {error, _}}
{!-- <%= {error,_} -> %> --}
<div role="status" class="p-4 mb-4 rounded-md bg-yellow-50">
<div class="flex">
<div class="flex-shrink-0">
{!-- Heroicon name: exclamation --}
<svg
class="w-5 h-5 text-yellow-400"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
clip-rule="evenodd"
/>
</svg>
{#match {"email_not_confirmed", _}}
{!-- <%= {"email_not_confirmed",_} -> %> --}
<div role="status" class="alert alert-warning">
<div class="flex flex-1">
<label>
{l(
"You need to to click the link in the email you should have received to verify your email address. Need to have it "
)} <LinkLive
to={path(Bonfire.UI.Me.ConfirmEmailController)}
class="font-bold underline text-neutral"
>resent</LinkLive> ?
</label>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800">
{l("There was an error")} ({error}), {l("please try again.")}
</h3>
</div>
{#match {error, _}}
{!-- <%= {error,_} -> %> --}
<div role="status" class="p-4 mb-4 rounded-md bg-yellow-50">
<div class="flex">
<div class="flex-shrink-0">
{!-- Heroicon name: exclamation --}
<svg
class="w-5 h-5 text-yellow-400"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
clip-rule="evenodd"
/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800">
{l("There was an error:")} ({error}), {l("please try again.")}
</h3>
</div>
</div>
</div>
</div>
{#match nil}
<div />
{!-- <%= nil -> %> --}
{!-- <% end %> --}
{/case}
{#match nil}
<div />
{!-- <%= nil -> %> --}
{!-- <% end %> --}
{/case}
{/for}

<.input
field={@form[:email_or_username]}
Expand Down
6 changes: 5 additions & 1 deletion lib/plugs/load_current_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ defmodule Bonfire.UI.Me.Plugs.LoadCurrentAccount do
end

def call(conn, _opts) do
current_account_id =
get_session(conn, :current_account_id)
|> debug("current_account_id in session")

assign_global(
conn,
:current_account,
Accounts.get_current(get_session(conn, :current_account_id))
Accounts.get_current(current_account_id)
)
end
end
1 change: 1 addition & 0 deletions lib/plugs/load_current_user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Bonfire.UI.Me.Plugs.LoadCurrentUser do
def call(conn, opts) do
case get_session(conn, :current_user_id) do
nil ->
debug(get_session(conn), "no current_user_id in session")
Bonfire.UI.Me.Plugs.LoadCurrentAccount.call(conn, opts)

current_user_id ->
Expand Down
2 changes: 1 addition & 1 deletion lib/views/login/login_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule Bonfire.UI.Me.LoginController do
# )
# to support redirect after a POST
|> Plug.Conn.put_status(303)
|> redirect_to_previous_go(form, "/", "/login")
|> redirect_to_previous_go(debug(form), "/", "/login")
end

def form_cs(params \\ %{}), do: Accounts.changeset(:login, params)
Expand Down

0 comments on commit c2f463b

Please sign in to comment.