Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-09 17:52:26 +01:00
parent 8ac705d8c2
commit 92d2045735
97 changed files with 18243 additions and 1544 deletions

View File

@@ -10,7 +10,7 @@ defmodule Eventos.Repo.Migrations.CreateAccounts do
add :private_key, :text
add :public_key, :text, null: false
add :suspended, :boolean, default: false, null: false
add :uri, :string, null: false
add :uri, :string
add :url, :string
timestamps()

View File

@@ -5,8 +5,8 @@ defmodule Eventos.Repo.Migrations.CreateUsers do
create table(:users) do
add :email, :string, null: false
add :role, :integer, default: 0, null: false
add :password_hash, :string
add :account_id, references(:accounts, on_delete: :delete_all, null: false)
add :password_hash, :string, null: false
add :account_id, references(:accounts, on_delete: :delete_all), null: false
timestamps()
end

View File

@@ -9,9 +9,29 @@
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
import Logger
Eventos.Repo.delete_all Eventos.Accounts.User
Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{email: "testuser@example.com", password: "secret", password_confirmation: "secret"})
|> Eventos.Repo.insert!
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
account = Ecto.Changeset.change(%Eventos.Accounts.Account{}, %{
username: "tcit",
description: "myaccount",
display_name: "Thomas Citharel",
domain: nil,
private_key: privkey,
public_key: pubkey,
uri: "",
url: ""
})
user = Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{
email: "tcit@tcit.fr",
password: "tcittcit",
password_confirmation: "tcittcit"
})
account_with_user = Ecto.Changeset.put_assoc(account, :user, user)
Eventos.Repo.insert!(account_with_user)