mirror of
https://github.com/bonfire-networks/bonfire-app.git
synced 2024-05-18 00:52:40 +00:00
refactor
This commit is contained in:
parent
4f67a69f01
commit
bca5a06302
|
@ -1,16 +1,36 @@
|
|||
use Mix.Config
|
||||
|
||||
config :pointers,
|
||||
search_path: [:cpub_core, :vox_publica]
|
||||
search_path: [
|
||||
:cpub_accounts,
|
||||
:cpub_communities,
|
||||
:cpub_emails,
|
||||
:cpub_local_auth,
|
||||
:cpub_profiles,
|
||||
:cpub_users,
|
||||
:vox_publica,
|
||||
]
|
||||
|
||||
# config :cpub_core, CommonsPub.Core.Pseudonym,
|
||||
# regex: ~r/[a-zA-Z_][a-zA-Z0-9_]{5,29}/, # 6-30 characters
|
||||
# canonicalise: &String.lowercase/1
|
||||
alias CommonsPub.Accounts.Account
|
||||
alias CommonsPub.Emails.Email
|
||||
alias CommonsPub.LocalAuth.LoginCredential
|
||||
alias CommonsPub.Profiles.Profile
|
||||
alias CommonsPub.Users.User
|
||||
|
||||
# config :cpub_core, CommonsPub.Core.User,
|
||||
# has_one: [
|
||||
# pseudonym: {CommonsPub.Core.Pseudonym, foreign_key: :id},
|
||||
# ]
|
||||
config :cpub_accounts, Account,
|
||||
has_one: [email: {Email, foreign_key: :id}],
|
||||
has_one: [login_credential: {LoginCredential, foreign_key: :id}]
|
||||
|
||||
config :cpub_local_auth, LoginCredential,
|
||||
belongs_to: [account: {Account, foreign_key: :id, define_field: false}],
|
||||
rename_attrs: [email: :identity],
|
||||
password: [length: [min: 8, max: 64]]
|
||||
|
||||
config :cpub_profiles, Profile,
|
||||
belongs_to: [user: {User, foreign_key: :id, define_field: false}]
|
||||
|
||||
config :cpub_users, User,
|
||||
has_one: [profile: {Profile, foreign_key: :id}]
|
||||
|
||||
config :vox_publica,
|
||||
ecto_repos: [VoxPublica.Repo]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use Mix.Config
|
||||
|
||||
config :logger, level: :warn
|
||||
|
||||
# Configure your database
|
||||
#
|
||||
# The MIX_TEST_PARTITION environment variable can be used
|
||||
|
@ -18,5 +20,6 @@ config :vox_publica, VoxPublica.Web.Endpoint,
|
|||
http: [port: 4002],
|
||||
server: false
|
||||
|
||||
# Print only warnings and errors during test
|
||||
config :logger, level: :warn
|
||||
config :argon2_elixir,
|
||||
t_cost: 1,
|
||||
m_cost: 8
|
||||
|
|
39
lib/accounts.ex
Normal file
39
lib/accounts.ex
Normal file
|
@ -0,0 +1,39 @@
|
|||
defmodule VoxPublica.Accounts do
|
||||
|
||||
alias CommonsPub.Accounts.Account
|
||||
alias Pointers.Changesets
|
||||
alias VoxPublica.Repo
|
||||
import Ecto.Query
|
||||
|
||||
def create(attrs) do
|
||||
create_changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
def create_changeset(attrs) do
|
||||
Account.changeset(attrs)
|
||||
|> Changesets.cast_assoc(:email, attrs)
|
||||
|> Changesets.cast_assoc(:login_credential, attrs)
|
||||
end
|
||||
|
||||
def find_for_login_query(email) when is_binary(email) do
|
||||
from a in Account,
|
||||
join: lc in assoc(a, :login_credential),
|
||||
where: lc.identity == ^email,
|
||||
preload: [login_credential: lc]
|
||||
end
|
||||
|
||||
def authenticate(email, password) do
|
||||
case Repo.one(find_for_login_query(email)) do
|
||||
nil -> Argon2.no_user_verify()
|
||||
account -> auth(account, password)
|
||||
end
|
||||
end
|
||||
|
||||
defp auth(account, password) do
|
||||
if Argon2.verify_pass(password, account.login_credential.password_hash),
|
||||
do: {:ok, account},
|
||||
else: {:error, :not_found}
|
||||
end
|
||||
|
||||
end
|
33
lib/fake.ex
Normal file
33
lib/fake.ex
Normal file
|
@ -0,0 +1,33 @@
|
|||
defmodule VoxPublica.Fake do
|
||||
|
||||
def email, do: Faker.Internet.email()
|
||||
# def location, do: Faker.Pokemon.location()
|
||||
def name, do: Faker.Person.name()
|
||||
def password, do: Faker.random_bytes(10)
|
||||
def summary, do: Faker.Pokemon.name()
|
||||
def username, do: Faker.Internet.user_name()
|
||||
|
||||
def account(base \\ %{}) do
|
||||
base
|
||||
|> Map.put_new_lazy(:email, &email/0)
|
||||
|> Map.put_new_lazy(:password, &password/0)
|
||||
end
|
||||
|
||||
def user(base \\ %{}) do
|
||||
base
|
||||
|> character()
|
||||
|> profile()
|
||||
end
|
||||
|
||||
def character(base \\ %{}) do
|
||||
base
|
||||
|> Map.put_new_lazy(:username, &username/0)
|
||||
end
|
||||
|
||||
def profile(base \\ %{}) do
|
||||
base
|
||||
|> Map.put_new_lazy(:name, &name/0)
|
||||
|> Map.put_new_lazy(:summary, &summary/0)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
defmodule CommonsPub.Core.Character do
|
||||
|
||||
use Pointers.Mixin,
|
||||
otp_app: :cpub_core,
|
||||
source: "cpub_character"
|
||||
|
||||
alias CommonsPub.Core.{Character, UsernameReservation}
|
||||
alias Ecto.Changeset
|
||||
|
||||
mixin_schema do
|
||||
field :username, :string
|
||||
field :username_hash, Cloak.Ecto.SHA256
|
||||
end
|
||||
|
||||
def create(attrs) do
|
||||
%Character{}
|
||||
|> Changeset.cast(attrs, [:id, :username])
|
||||
|> Changeset.validate_required([:id, :username])
|
||||
|> Changeset.unique_constraint([:username])
|
||||
|> Changeset.unique_constraint([:username_hash])
|
||||
|> hash_username()
|
||||
end
|
||||
|
||||
def hash_username(changeset) do
|
||||
value = Changeset.get_field(changeset, :username)
|
||||
Changeset.put_change(changeset, :username_hash, value)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule CommonsPub.Follows.FollowerCount do
|
||||
|
||||
# use Pointers.Schema
|
||||
|
||||
# trait_schema("cpub_follows_follower_count", :follower_count) do
|
||||
# field :follower_count, :integer
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule CommonsPub.Follows.FollowsCount do
|
||||
|
||||
# use Pointers.Schema
|
||||
|
||||
# trait_schema("cpub_follows_follows_count", :follows_count) do
|
||||
# field :follows_count, :integer
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule CommonsPub.Likes.LikerCount do
|
||||
|
||||
# use Pointers.Schema
|
||||
|
||||
# trait_schema("cpub_likes_liker_count", :liker_count) do
|
||||
# field :liker_count, :integer
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule CommonsPub.Likes.LikesCount do
|
||||
|
||||
# use Pointers.Schema
|
||||
|
||||
# trait_schema("cpub_likes_likes_count", :likes_count) do
|
||||
# field :likes_count, :integer
|
||||
# end
|
||||
|
||||
end
|
41
lib/repo.ex
41
lib/repo.ex
|
@ -2,4 +2,45 @@ defmodule VoxPublica.Repo do
|
|||
use Ecto.Repo,
|
||||
otp_app: :vox_publica,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
|
||||
alias Ecto.Changeset
|
||||
|
||||
def transact_with(fun) do
|
||||
transaction fn ->
|
||||
case fun.() do
|
||||
{:ok, val} -> val
|
||||
{:error, val} -> rollback(val)
|
||||
val -> val # naughty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def put(%Changeset{}=changeset) do
|
||||
# with {:error, changeset} <- insert(changeset) do
|
||||
# changes = Enum.reduce(changeset.changes, changeset.changes, fn {k, v} ->
|
||||
# case v do
|
||||
# %Changeset{valid?: false, errors: errors} ->
|
||||
# :ok
|
||||
# end
|
||||
# end)
|
||||
# {:error, %{ changeset | changes: changes }}
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
def insert_many(things) do
|
||||
case Enum.filter(things, fn {_, %Changeset{valid?: v}} -> not v end) do
|
||||
[] -> transact_with(fn -> im(things, %{}) end)
|
||||
failed -> {:error, failed}
|
||||
end
|
||||
end
|
||||
|
||||
defp im([], acc), do: {:ok, acc}
|
||||
defp im([{k, v} | is], acc) do
|
||||
case insert(v) do
|
||||
{:ok, v} -> im(is, Map.put(acc, k, v))
|
||||
{:error, other} -> {:error, {k, other}}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
49
mix.exs
49
mix.exs
|
@ -5,7 +5,7 @@ defmodule VoxPublica.MixProject do
|
|||
[
|
||||
app: :vox_publica,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.7",
|
||||
elixir: "~> 1.10",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
|
||||
start_permanent: Mix.env() == :prod,
|
||||
|
@ -21,13 +21,9 @@ defmodule VoxPublica.MixProject do
|
|||
]
|
||||
end
|
||||
|
||||
# Specifies which paths to compile per environment.
|
||||
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
||||
defp elixirc_paths(_), do: ["lib"]
|
||||
|
||||
# Specifies your project dependencies.
|
||||
#
|
||||
# Type `mix help deps` for examples and options.
|
||||
defp deps do
|
||||
[
|
||||
{:phoenix_live_view, "~> 0.14"},
|
||||
|
@ -42,25 +38,56 @@ defmodule VoxPublica.MixProject do
|
|||
{:telemetry_poller, "~> 0.4"},
|
||||
{:gettext, "~> 0.11"},
|
||||
{:jason, "~> 1.0"},
|
||||
{:cloak_ecto, "~> 1.0"},
|
||||
|
||||
{:pointers_ulid, "~> 0.2"},
|
||||
# {:pointers_ulid, path: "../pointers_ulid", override: true},
|
||||
|
||||
{:pointers, "~> 0.3"},
|
||||
# {:pointers, path: "../pointers", override: true},
|
||||
# {:pointers, "~> 0.4.2"},
|
||||
# {:pointers, git: "https://github.com/commonspub/pointers", branch: "main"},
|
||||
{:pointers, path: "../pointers", override: true},
|
||||
|
||||
{:flexto, "~> 0.2"},
|
||||
# {:flexto, path: "../flexto", override: true},
|
||||
|
||||
# {:cpub_core, "~> 0.1"},
|
||||
# {:cpub_core, path: "../cpub_core"},
|
||||
# {:cpub_accounts, git: "https://github.com/commonspub/cpub_accounts", branch: "main"},
|
||||
{:cpub_accounts, path: "../cpub_accounts", override: true},
|
||||
|
||||
# {:cpub_blocks, git: "https://github.com/commonspub/cpub_blocks", branch: "main"},
|
||||
{:cpub_blocks, path: "../cpub_blocks", override: true},
|
||||
|
||||
# {:cpub_bookmarks, git: "https://github.com/commonspub/cpub_bookmarks", branch: "main"},
|
||||
# # {:cpub_bookmarks, path: "../cpub_bookmarks", override: true},
|
||||
|
||||
# {:cpub_characters, git: "https://github.com/commonspub/cpub_characters", branch: "main"},
|
||||
{:cpub_characters, path: "../cpub_characters", override: true},
|
||||
|
||||
# {:cpub_circles, git: "https://github.com/commonspub/cpub_circles", branch: "main"},
|
||||
# # {:cpub_circles, path: "../cpub_circles", override: true},
|
||||
|
||||
# {:cpub_communities, git: "https://github.com/commonspub/cpub_communities", branch: "main"},
|
||||
{:cpub_communities, path: "../cpub_communities", override: true},
|
||||
|
||||
# {:cpub_emails, git: "https://github.com/commonspub/cpub_emails", branch: "main"},
|
||||
{:cpub_emails, path: "../cpub_emails", override: true},
|
||||
|
||||
# {:cpub_local_auth, git: "https://github.com/commonspub/cpub_local_auth", branch: "main"},
|
||||
{:cpub_local_auth, path: "../cpub_local_auth", override: true},
|
||||
|
||||
# {:cpub_profiles, git: "https://github.com/commonspub/cpub_profiles", branch: "main"},
|
||||
{:cpub_profiles, path: "../cpub_profiles", override: true},
|
||||
|
||||
# {:cpub_users, git: "https://github.com/commonspub/cpub_users", branch: "main"},
|
||||
{:cpub_users, path: "../cpub_users", override: true},
|
||||
|
||||
# {:pager, path: "../pager"},
|
||||
# {:resolute, path: "../resolute"},
|
||||
|
||||
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||
{:faker, "~> 0.14"},
|
||||
|
||||
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||
{:dbg, "~> 1.0", only: [:dev, :test]},
|
||||
{:floki, ">= 0.0.0", only: :test},
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
|
|
23
mix.lock
23
mix.lock
|
@ -1,20 +1,33 @@
|
|||
%{
|
||||
"argon2_elixir": {:hex, :argon2_elixir, "2.3.0", "e251bdafd69308e8c1263e111600e6d68bd44f23d2cccbe43fcb1a417a76bc8e", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "28ccb63bff213aecec1f7f3dde9648418b031f822499973281d8f494b9d5a3b3"},
|
||||
"cloak": {:hex, :cloak, "1.0.2", "331bae964b61d0201b69cc0a5b43d1dacec52b7e4480707eb11a4505d0567cc5", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:pbkdf2, "~> 2.0", [hex: :pbkdf2, repo: "hexpm", optional: true]}], "hexpm", "81c8d6a60de90a53e9c3d1c0d3230efdd50aa4048cd7242ee29d1b6582b3aaf9"},
|
||||
"cloak_ecto": {:hex, :cloak_ecto, "1.0.2", "ab6c71852c9b588e27b8d671f644e1501d23317cae3d20a4ddc0f95564d48a98", [:mix], [{:cloak, "~> 1.0.0", [hex: :cloak, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:pbkdf2, "~> 2.0", [hex: :pbkdf2, repo: "hexpm", optional: true]}], "hexpm", "7cc5c5f5a619b483aa44732e66596896a9572fa877fa0c52553ef2aaafa831e3"},
|
||||
"comeonin": {:hex, :comeonin, "5.3.1", "7fe612b739c78c9c1a75186ef2d322ce4d25032d119823269d0aa1e2f1e20025", [:mix], [], "hexpm", "d6222483060c17f0977fad1b7401ef0c5863c985a64352755f366aee3799c245"},
|
||||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
|
||||
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
|
||||
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
|
||||
"cpub_accounts": {:git, "https://github.com/commonspub/cpub_accounts", "5463b711487f9385990e48ee464739e90b431b1e", [branch: "main"]},
|
||||
"cpub_blocks": {:git, "https://github.com/commonspub/cpub_blocks", "d9144dc0f8ee26a69a90a9a2f51909d7952a8979", [branch: "main"]},
|
||||
"cpub_characters": {:git, "https://github.com/commonspub/cpub_characters", "6f85ddc26eac401e3fdb55d69982bbbfc79562e1", [branch: "main"]},
|
||||
"cpub_communities": {:git, "https://github.com/commonspub/cpub_communities", "13bdf07a9b2a9dd3408bf2f918e07042f722694c", [branch: "main"]},
|
||||
"cpub_core": {:git, "https://github.com/commonspub/cpub_core", "23191431d99fdd09d890bf9607eb0578b556d535", [branch: "main"]},
|
||||
"cpub_local_auth": {:git, "https://github.com/commonspub/cpub_local_auth", "1d482a208edce4c60dd25622aaa1586b1612b095", [branch: "main"]},
|
||||
"cpub_profiles": {:git, "https://github.com/commonspub/cpub_profiles", "b5f24622f039a5cc53337ca12ca369c25bcd0d87", [branch: "main"]},
|
||||
"cpub_users": {:git, "https://github.com/commonspub/cpub_users", "1a4f8323e2eff993c5f0f62eb8886522553334ed", [branch: "main"]},
|
||||
"db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"},
|
||||
"dbg": {:hex, :dbg, "1.0.1", "9c29813e5df8b4d275325416523d511e315656b8ac27a60519791f9cf476d83d", [:mix], [], "hexpm", "866159f496a1ad9b959501f16db3d1338bb6cef029a75a67ca5615d25b38345f"},
|
||||
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
|
||||
"ecto": {:hex, :ecto, "3.4.5", "2bcd262f57b2c888b0bd7f7a28c8a48aa11dc1a2c6a858e45dd8f8426d504265", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8c6d1d4d524559e9b7a062f0498e2c206122552d63eacff0a6567ffe7a8e8691"},
|
||||
"ecto": {:hex, :ecto, "3.4.6", "08f7afad3257d6eb8613309af31037e16c36808dfda5a3cd0cb4e9738db030e4", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6f13a9e2a62e75c2dcfc7207bfc65645ab387af8360db4c89fee8b5a4bf3f70b"},
|
||||
"ecto_sql": {:hex, :ecto_sql, "3.4.5", "30161f81b167d561a9a2df4329c10ae05ff36eca7ccc84628f2c8b9fa1e43323", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31990c6a3579b36a3c0841d34a94c275e727de8b84f58509da5f1b2032c98ac2"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
|
||||
"faker": {:hex, :faker, "0.14.0", "203c586aba7e36567e01e5e786763baf8ce1be4642a96b19ad6d7245976eb973", [:mix], [], "hexpm", "492f8f0e80668e5217ad7eb8519be7640cda29e014fc8763f2e46844edeaa989"},
|
||||
"file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"},
|
||||
"flexto": {:hex, :flexto, "0.2.0", "1a0dd408a5b833fa8310844e68e0cd3d0fac247ea60bafc7e6e390f5a3fac3ef", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm", "268f77e23c56c8545378cec96000bfcdc75f0aa913addbfa7b172a37df51e5db"},
|
||||
"floki": {:hex, :floki, "0.27.0", "6b29a14283f1e2e8fad824bc930eaa9477c462022075df6bea8f0ad811c13599", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "583b8c13697c37179f1f82443bcc7ad2f76fbc0bf4c186606eebd658f7f2631b"},
|
||||
"floki": {:hex, :floki, "0.28.0", "0d0795a17189510ee01323e6990f906309e9fc6e8570219135211f1264d78c7f", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "db1549560874ebba5a6367e46c3aec5fedd41f2757ad6efe567efb04b4d4ee55"},
|
||||
"gettext": {:hex, :gettext, "0.18.1", "89e8499b051c7671fa60782faf24409b5d2306aa71feb43d79648a8bc63d0522", [:mix], [], "hexpm", "e70750c10a5f88cb8dc026fc28fa101529835026dec4a06dba3b614f2a99c7a9"},
|
||||
"html_entities": {:hex, :html_entities, "0.5.1", "1c9715058b42c35a2ab65edc5b36d0ea66dd083767bef6e3edb57870ef556549", [:mix], [], "hexpm", "30efab070904eb897ff05cd52fa61c1025d7f8ef3a9ca250bc4e6513d16c32de"},
|
||||
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
|
||||
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"},
|
||||
"mime": {:hex, :mime, "1.4.0", "5066f14944b470286146047d2f73518cf5cca82f8e4815cf35d196b58cf07c47", [:mix], [], "hexpm", "75fa42c4228ea9a23f70f123c74ba7cece6a03b1fd474fe13f6a7a85c6ea4ff6"},
|
||||
"phoenix": {:hex, :phoenix, "1.5.4", "0fca9ce7e960f9498d6315e41fcd0c80bfa6fbeb5fa3255b830c67fdfb7e703f", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4e516d131fde87b568abd62e1b14aa07ba7d5edfd230bab4e25cc9dedbb39135"},
|
||||
"phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"},
|
||||
"phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"},
|
||||
|
@ -22,10 +35,10 @@
|
|||
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.4", "940c0344b1d66a2e46eef02af3a70e0c5bb45a4db0bf47917add271b76cd3914", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "38f9308357dea4cc77f247e216da99fcb0224e05ada1469167520bed4cb8cccd"},
|
||||
"phoenix_live_view": {:hex, :phoenix_live_view, "0.14.4", "7286a96287cd29b594ce4a7314249cea7311af04a06c0fa3e50932e188e73996", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.3", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 0.5", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc4f8cf205c784eeccee35de8afbfeb995ce5511ac4839db63d6d67a5ba091d1"},
|
||||
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
|
||||
"plug": {:hex, :plug, "1.10.3", "c9cebe917637d8db0e759039cc106adca069874e1a9034fd6e3fdd427fd3c283", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "01f9037a2a1de1d633b5a881101e6a444bcabb1d386ca1e00bb273a1f1d9d939"},
|
||||
"plug": {:hex, :plug, "1.10.4", "41eba7d1a2d671faaf531fa867645bd5a3dce0957d8e2a3f398ccff7d2ef017f", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad1e233fe73d2eec56616568d260777b67f53148a999dc2d048f4eb9778fe4a0"},
|
||||
"plug_cowboy": {:hex, :plug_cowboy, "2.3.0", "149a50e05cb73c12aad6506a371cd75750c0b19a32f81866e1a323dda9e0e99d", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bc595a1870cef13f9c1e03df56d96804db7f702175e4ccacdb8fc75c02a7b97e"},
|
||||
"plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"},
|
||||
"pointers": {:hex, :pointers, "0.3.0", "f27c0f6e702fd283e1f1b860ea59664496c52a8d077f321bd5567adf15092088", [:mix], [{:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:flexto, "~> 0.1", [hex: :flexto, repo: "hexpm", optional: false]}, {:pointers_ulid, "~> 0.2", [hex: :pointers_ulid, repo: "hexpm", optional: false]}], "hexpm", "c7730978cddf9a192b1ebf3d1462a5b83230dc748275970e7b568a3f380b664e"},
|
||||
"pointers": {:git, "https://github.com/commonspub/pointers", "cd9173bf5ba27c81a0c0119a52b1139329662a1d", [branch: "main"]},
|
||||
"pointers_ulid": {:hex, :pointers_ulid, "0.2.2", "305df7d45d5227467bb9b9441f7f06fe5386390f8a4daf8084f28a58ea3e14f7", [:mix], [{:ecto, "~> 3.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "5cca67c892a9af22030930762340d7ce82a0cc91d75559ca085d855cfed3de5b"},
|
||||
"postgrex": {:hex, :postgrex, "0.15.5", "aec40306a622d459b01bff890fa42f1430dac61593b122754144ad9033a2152f", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ed90c81e1525f65a2ba2279dbcebf030d6d13328daa2f8088b9661eb9143af7f"},
|
||||
"protocol_ex": {:hex, :protocol_ex, "0.4.3", "4acbe35da85109dc40315c1139bb7a65ebc7fc102d384cd8b3038384fbb9b282", [:mix], [], "hexpm", "6ca5ddb3505c9c86f17cd3f19838b34bf89966ae17078f79f81983b6a4391fe9"},
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
defmodule VoxPublica.Repo.Migrations.TestMigrations do
|
||||
use Ecto.Migration
|
||||
import Pointers.Migration
|
||||
|
||||
def up() do
|
||||
create_pointable_table("foo", "01EAPGCB6V8GS3D8ZPKDTYDPPW") do
|
||||
|
||||
end
|
||||
create_pointable_table("bar", "01EAPGCJ3VX4B7AV3Y0QKMNKC9") do
|
||||
|
||||
end
|
||||
end
|
||||
def down() do
|
||||
drop_pointable_table("bar", "01EAPGCJ3VX4B7AV3Y0QKMNKC9")
|
||||
drop_pointable_table("foo", "01EAPGCB6V8GS3D8ZPKDTYDPPW")
|
||||
end
|
||||
|
||||
end
|
20
priv/repo/migrations/20200828094943_import_world.exs
Normal file
20
priv/repo/migrations/20200828094943_import_world.exs
Normal file
|
@ -0,0 +1,20 @@
|
|||
defmodule VoxPublica.Repo.Migrations.ImportWorld do
|
||||
use Ecto.Migration
|
||||
|
||||
import CommonsPub.Accounts.Account.Migration
|
||||
import CommonsPub.Emails.Email.Migration
|
||||
import CommonsPub.LocalAuth.LoginCredential.Migration
|
||||
import CommonsPub.Profiles.Profile.Migration
|
||||
import CommonsPub.Users.User.Migration
|
||||
|
||||
def change do
|
||||
# accounts
|
||||
migrate_account()
|
||||
migrate_email()
|
||||
migrate_login_credential()
|
||||
# users
|
||||
migrate_user()
|
||||
migrate_profile()
|
||||
end
|
||||
|
||||
end
|
35
test/accounts_test.exs
Normal file
35
test/accounts_test.exs
Normal file
|
@ -0,0 +1,35 @@
|
|||
defmodule VoxPublica.AccountsTest do
|
||||
|
||||
use VoxPublica.DataCase, async: true
|
||||
alias VoxPublica.{Accounts, Fake, Repo}
|
||||
|
||||
test "creation works" do
|
||||
attrs = Fake.account()
|
||||
assert {:ok, account} = Accounts.create(attrs)
|
||||
assert account.login_credential.identity == attrs[:email]
|
||||
assert Argon2.verify_pass(attrs[:password], account.login_credential.password_hash)
|
||||
end
|
||||
|
||||
test "emails must be unique" do
|
||||
attrs = Fake.account()
|
||||
assert {:ok, account} = Accounts.create(attrs)
|
||||
assert account.login_credential.identity == attrs[:email]
|
||||
assert Argon2.verify_pass(attrs[:password], account.login_credential.password_hash)
|
||||
assert {:error, changeset} = Accounts.create(attrs)
|
||||
assert %{email: email, login_credential: lc} = changeset.changes
|
||||
cond do
|
||||
email.valid? ->
|
||||
assert [identity: {_,_}] = lc.errors
|
||||
lc.valid? ->
|
||||
assert [email: {_,_}] = email.errors
|
||||
end
|
||||
end
|
||||
|
||||
# test "creation works" do
|
||||
# attrs = Fake.account()
|
||||
# assert {:ok, account} = Accounts.create(attrs)
|
||||
# assert account.login_credential.identity == attrs[:email]
|
||||
# assert Argon2.verify_pass(attrs[:password], account.login_credential.password_hash)
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule VoxPublicaWeb.ChannelCase do
|
||||
defmodule VoxPublica.ChannelCase do
|
||||
@moduledoc """
|
||||
This module defines the test case to be used by
|
||||
channel tests.
|
||||
|
@ -21,10 +21,10 @@ defmodule VoxPublicaWeb.ChannelCase do
|
|||
quote do
|
||||
# Import conveniences for testing with channels
|
||||
import Phoenix.ChannelTest
|
||||
import VoxPublicaWeb.ChannelCase
|
||||
import VoxPublica.ChannelCase
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint VoxPublicaWeb.Endpoint
|
||||
@endpoint VoxPublica.Web.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule VoxPublicaWeb.ConnCase do
|
||||
defmodule VoxPublica.ConnCase do
|
||||
@moduledoc """
|
||||
This module defines the test case to be used by
|
||||
tests that require setting up a connection.
|
||||
|
@ -22,12 +22,12 @@ defmodule VoxPublicaWeb.ConnCase do
|
|||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
import Phoenix.ConnTest
|
||||
import VoxPublicaWeb.ConnCase
|
||||
import VoxPublica.ConnCase
|
||||
|
||||
alias VoxPublicaWeb.Router.Helpers, as: Routes
|
||||
alias VoxPublica.Web.Router.Helpers, as: Routes
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint VoxPublicaWeb.Endpoint
|
||||
@endpoint VoxPublica.Web.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
defmodule VoxPublicaWeb.PageLiveTest do
|
||||
use VoxPublicaWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
test "disconnected and connected render", %{conn: conn} do
|
||||
{:ok, page_live, disconnected_html} = live(conn, "/")
|
||||
assert disconnected_html =~ "Welcome to Phoenix!"
|
||||
assert render(page_live) =~ "Welcome to Phoenix!"
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
defmodule VoxPublicaWeb.ErrorViewTest do
|
||||
use VoxPublicaWeb.ConnCase, async: true
|
||||
|
||||
# Bring render/3 and render_to_string/3 for testing custom views
|
||||
import Phoenix.View
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(VoxPublicaWeb.ErrorView, "404.html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(VoxPublicaWeb.ErrorView, "500.html", []) == "Internal Server Error"
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
defmodule VoxPublicaWeb.LayoutViewTest do
|
||||
use VoxPublicaWeb.ConnCase, async: true
|
||||
|
||||
# When testing helpers, you may want to import Phoenix.HTML and
|
||||
# use functions such as safe_to_string() to convert the helper
|
||||
# result into an HTML string.
|
||||
# import Phoenix.HTML
|
||||
end
|
Loading…
Reference in a new issue