remove unused vars/aliases and fix bug where first authentication doesn't decrypt link
This commit is contained in:
parent
5047ee653b
commit
45bd5ba81a
|
@ -75,6 +75,10 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
alert("Could not find intended link in URL");
|
||||
return null;
|
||||
}
|
||||
if (!user) {
|
||||
// no need to retrieve link if they weren't authenticated
|
||||
return null;
|
||||
}
|
||||
|
||||
const linkResponse = await fetch(`/links/${linkId}`);
|
||||
let linkData: IntendedLink | null;
|
||||
|
|
|
@ -95,6 +95,7 @@ const ForPage = (props: ForPageProps) => {
|
|||
value={serviceSelect}
|
||||
>
|
||||
<option value="github">Github</option>
|
||||
<option value="google">Gmail</option>
|
||||
</Select>
|
||||
<Spacer space="3rem" />
|
||||
<SpaceBetweenContainer>
|
||||
|
|
|
@ -6,7 +6,6 @@ defmodule Entendu.UserFromAuth do
|
|||
require Jason
|
||||
|
||||
alias Ueberauth.Auth
|
||||
alias Entendu.Links.Link
|
||||
|
||||
def find_or_create(%Auth{} = auth) do
|
||||
{:ok, basic_info(auth)}
|
||||
|
|
|
@ -8,8 +8,6 @@ defmodule EntenduWeb.AuthController do
|
|||
plug Ueberauth
|
||||
|
||||
alias Entendu.UserFromAuth
|
||||
alias EntenduWeb.LinkView
|
||||
alias Entendu.EncryptedLink
|
||||
|
||||
def delete(conn, _params) do
|
||||
conn
|
||||
|
@ -27,7 +25,7 @@ defmodule EntenduWeb.AuthController do
|
|||
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
|
||||
link = get_session(conn, :intended_link)
|
||||
|
||||
with %{id: link_id, recipient: recipient} <- link,
|
||||
with %{id: link_id} <- link,
|
||||
{:ok, user} <- UserFromAuth.find_or_create(auth) do
|
||||
# TODO: send over encrypted data that the frontend can decrypt
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ defmodule EntenduWeb.LinkController do
|
|||
alias Entendu.Links
|
||||
alias Links.Link
|
||||
alias EntenduWeb.FallbackController
|
||||
alias Entendu.EncryptedLink
|
||||
alias Entendu.UserFromAuth
|
||||
alias EntenduWeb.Plugs.AuthorizeLink
|
||||
|
||||
plug AuthorizeLink when action in [:text, :file]
|
||||
|
@ -18,7 +16,8 @@ defmodule EntenduWeb.LinkController do
|
|||
action_fallback(FallbackController)
|
||||
|
||||
def just_page(conn, _params) do
|
||||
render(conn, "just.html")
|
||||
conn
|
||||
|> render("just.html")
|
||||
end
|
||||
|
||||
def just(conn, params) do
|
||||
|
@ -46,7 +45,7 @@ defmodule EntenduWeb.LinkController do
|
|||
end
|
||||
|
||||
def auth_page(conn, %{"id" => link_id}) do
|
||||
with %Link{id: id, service: service, recipient: recipient} = link <- Links.get_link(link_id) do
|
||||
with %Link{id: id, service: service, recipient: recipient} <- Links.get_link(link_id) do
|
||||
conn
|
||||
|> put_session(:intended_link, %{id: id, service: service, recipient: recipient})
|
||||
|> render("auth.html", %{intended_link: %{service: service, recipient: recipient}})
|
||||
|
|
|
@ -7,7 +7,6 @@ defmodule EntenduWeb.PageController do
|
|||
|
||||
def index(conn, _params) do
|
||||
conn
|
||||
|> clear_session()
|
||||
|> render("index.html")
|
||||
end
|
||||
|
||||
|
|
|
@ -2,11 +2,9 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
|
|||
import Plug.Conn
|
||||
use EntenduWeb, :controller
|
||||
|
||||
alias Entendu.Repo
|
||||
alias Entendu.UserFromAuth
|
||||
alias Entendu.Links
|
||||
alias Entendu.Links.Link
|
||||
alias EntenduWeb.FallbackController
|
||||
alias EntenduWeb.ErrorView
|
||||
|
||||
def init(_params) do
|
||||
|
@ -23,7 +21,7 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
|
|||
if !user do
|
||||
conn
|
||||
|> put_status(403)
|
||||
|> put_view(EntenduWeb.ErrorView)
|
||||
|> put_view(ErrorView)
|
||||
|> render("error_code.json", message: "Unauthorized", code: 403)
|
||||
|> halt
|
||||
else
|
||||
|
@ -35,21 +33,21 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
|
|||
nil ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> put_view(EntenduWeb.ErrorView)
|
||||
|> put_view(ErrorView)
|
||||
|> render("error_code.json", message: "Link could not be found", code: 404)
|
||||
|> halt
|
||||
|
||||
false ->
|
||||
conn
|
||||
|> put_status(403)
|
||||
|> put_view(EntenduWeb.ErrorView)
|
||||
|> put_view(ErrorView)
|
||||
|> render("error_code.json", message: "Unauthorized", code: 403)
|
||||
|> halt
|
||||
|
||||
{:error, reason} ->
|
||||
conn
|
||||
|> put_status(422)
|
||||
|> put_view(EntenduWeb.ErrorView)
|
||||
|> put_view(ErrorView)
|
||||
|> render("error_code.json", message: reason, code: 422)
|
||||
|> halt
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ defmodule Entendu.EncryptedLink do
|
|||
# end
|
||||
|
||||
# Override the storage directory:
|
||||
def storage_dir(version, {_file, scope}) do
|
||||
def storage_dir(_version, {_file, scope}) do
|
||||
"priv/uploads/links/#{scope.id}"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue