add waffle library, handle file upload, authenticate user with oauth and see if they have the link's email associated to their account
This commit is contained in:
@@ -23,18 +23,27 @@ defmodule EntenduWeb.AuthController do
|
||||
end
|
||||
|
||||
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
|
||||
case UserFromAuth.find_or_create(auth) do
|
||||
{:ok, user} ->
|
||||
# TODO: turn this into plug that only proceeds if current_link session var exists
|
||||
%{ id: link_id, recipient: recipient } = get_session(conn, :current_link)
|
||||
|
||||
with {:ok, user} <- UserFromAuth.find_or_create(auth),
|
||||
true <- UserFromAuth.can_access?(recipient, user.emails) do
|
||||
# TODO: send over encrypted data that the frontend can decrypt
|
||||
conn
|
||||
|> put_flash(:info, "Successfully authenticated.")
|
||||
|> put_session(:current_user, user)
|
||||
|> configure_session(renew: true)
|
||||
|> redirect(to: "/")
|
||||
|> redirect(to: "/just/for/you/#{link_id}")
|
||||
|
||||
else
|
||||
false ->
|
||||
conn
|
||||
|> put_flash(:error, "#{recipient} was not found in your list of verified emails")
|
||||
|> redirect(to: "/just/for/you/#{link_id}")
|
||||
|
||||
{:error, reason} ->
|
||||
conn
|
||||
|> put_flash(:error, reason)
|
||||
|> redirect(to: "/")
|
||||
|> redirect(to: "/just/for/you/#{link_id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -8,7 +8,6 @@ defmodule EntenduWeb.LinkController do
|
||||
|
||||
alias Entendu.Links
|
||||
alias Links.Link
|
||||
alias Ecto.Changeset
|
||||
alias EntenduWeb.FallbackController
|
||||
|
||||
action_fallback(FallbackController)
|
||||
@@ -17,23 +16,13 @@ defmodule EntenduWeb.LinkController do
|
||||
render(conn, "just.html")
|
||||
end
|
||||
|
||||
defparams(
|
||||
first_step(%{
|
||||
burn_after_reading: [field: :boolean, default: false],
|
||||
expires: :utc_datetime,
|
||||
filename: :string,
|
||||
filetype: :string,
|
||||
text_content: :string,
|
||||
file_content: :string
|
||||
})
|
||||
)
|
||||
|
||||
def just(conn, params) do
|
||||
with %Changeset{valid?: true} = changeset <- first_step(params),
|
||||
link_params <- Params.to_map(changeset),
|
||||
{:ok, %Link{} = link} <- Links.create_link(link_params) do
|
||||
with {:ok, %Link{} = link} <- Links.create_link(params) do
|
||||
conn
|
||||
|> render("show_authorized.json", %{link: link})
|
||||
else
|
||||
test ->
|
||||
IO.inspect(test)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,18 +30,9 @@ defmodule EntenduWeb.LinkController do
|
||||
render(conn, "for.html")
|
||||
end
|
||||
|
||||
defparams(
|
||||
second_step(%{
|
||||
service: :string,
|
||||
recipient: :string
|
||||
})
|
||||
)
|
||||
|
||||
def for(conn, %{link_id: link_id} = params) do
|
||||
with %Changeset{valid?: true} = changeset <- first_step(params),
|
||||
link_params <- Params.to_map(changeset),
|
||||
%Link{} = link <- Links.get_link(link_id),
|
||||
Links.update_link(link, link_params) do
|
||||
def for(conn, %{"link_id" => link_id, "recipient" => recipient, "service" => service}) do
|
||||
with %Link{} = link <- Links.get_link(link_id),
|
||||
Links.update_link(link, %{ recipient: recipient, service: service}) do
|
||||
conn
|
||||
|> render("show_authorized.json", %{link: link})
|
||||
end
|
||||
@@ -61,4 +41,12 @@ defmodule EntenduWeb.LinkController do
|
||||
def you_page(conn, _params) do
|
||||
render(conn, "you.html")
|
||||
end
|
||||
|
||||
def auth_page(conn, %{ "id" => link_id}) do
|
||||
with %Link{service: service, recipient: recipient} = link <- Links.get_link(link_id) do
|
||||
conn
|
||||
|> put_session(:current_link, link)
|
||||
|> render("auth.html", %{ service: service, recipient: recipient })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user