Skip to content

Commit

Permalink
fix assign
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht committed Jun 25, 2021
1 parent cfc81bc commit d5e79a2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/plausible_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ defmodule PlausibleWeb.AuthController do

def activate(conn, %{"code" => code}) do
user = conn.assigns[:current_user]
invitation = Repo.get_by(Plausible.Auth.Invitation, email: user.email)
has_invitation =
Repo.exists?(
from i in Plausible.Auth.Invitation,
where: i.email == ^user.email
)
{code, ""} = Integer.parse(code)

case Auth.verify_email(user, code) do
:ok ->
if invitation do
if has_invitation do
redirect(conn, to: "/sites")
else
redirect(conn, to: "/sites/new")
Expand All @@ -171,15 +175,15 @@ defmodule PlausibleWeb.AuthController do
render(conn, "activate.html",
error: "Incorrect activation code",
has_pin: true,
invitation: invitation,
has_invitation: has_invitation,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)

{:error, :expired} ->
render(conn, "activate.html",
error: "Code is expired, please request another one",
has_pin: false,
invitation: invitation,
has_invitation: has_invitation,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
end
Expand Down

0 comments on commit d5e79a2

Please sign in to comment.