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:
@@ -1,5 +1,7 @@
|
||||
defmodule Entendu.Links.Link do
|
||||
use Ecto.Schema
|
||||
use Waffle.Ecto.Schema
|
||||
alias Entendu.EncryptedLink
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, Ecto.UUID, autogenerate: true}
|
||||
@@ -9,8 +11,8 @@ defmodule Entendu.Links.Link do
|
||||
field :expires, :utc_datetime
|
||||
field :filename, :string
|
||||
field :filetype, :string
|
||||
field :text_content, :string
|
||||
field :file_content, :string
|
||||
field :text_content, EncryptedLink.Type
|
||||
field :file_content, EncryptedLink.Type
|
||||
field :recipient, :string
|
||||
field :service, :string
|
||||
|
||||
@@ -25,10 +27,10 @@ defmodule Entendu.Links.Link do
|
||||
:burn_after_reading,
|
||||
:filename,
|
||||
:filetype,
|
||||
:text_content,
|
||||
:file_content,
|
||||
:recipient,
|
||||
:service
|
||||
])
|
||||
|> cast_attachments(attrs, [:text_content, :file_content])
|
||||
|
||||
end
|
||||
end
|
||||
|
@@ -6,6 +6,7 @@ defmodule Entendu.UserFromAuth do
|
||||
require Jason
|
||||
|
||||
alias Ueberauth.Auth
|
||||
alias Entendu.Links.Link
|
||||
|
||||
def find_or_create(%Auth{} = auth) do
|
||||
{:ok, basic_info(auth)}
|
||||
@@ -24,9 +25,15 @@ defmodule Entendu.UserFromAuth do
|
||||
nil
|
||||
end
|
||||
|
||||
defp emails_from_auth(%Auth{ extra: %Auth.Extra{ raw_info: %{ user: %{ "emails" => emails}}}}), do: emails
|
||||
|
||||
defp emails_from_auth(%Auth{ info: %{ email: email }}), do: [email]
|
||||
|
||||
defp emails_from_auth(_auth), do: []
|
||||
|
||||
defp basic_info(auth) do
|
||||
IO.inspect(auth)
|
||||
%{id: auth.uid, name: name_from_auth(auth), avatar: avatar_from_auth(auth)}
|
||||
%{id: auth.uid, name: name_from_auth(auth), avatar: avatar_from_auth(auth), emails: emails_from_auth(auth)}
|
||||
end
|
||||
|
||||
defp name_from_auth(auth) do
|
||||
@@ -44,4 +51,9 @@ defmodule Entendu.UserFromAuth do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def can_access?(recipient, emails) do
|
||||
emails
|
||||
|> Enum.any?(&( &1["verified"] == true and &1["email"] == recipient))
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user