Update user gen
This commit is contained in:
parent
564c11b2d3
commit
beb9d0f112
3 changed files with 34 additions and 21 deletions
|
@ -88,9 +88,9 @@ defmodule ChoreTracker.Accounts do
|
|||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def register_user(attrs) do
|
||||
def register_user(attrs, opts) do
|
||||
%User{}
|
||||
|> User.registration_changeset(attrs)
|
||||
|> User.registration_changeset(attrs, opts)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
|
|
|
@ -54,7 +54,13 @@ defmodule ChoreTracker.Accounts.User do
|
|||
defp validate_password(changeset, opts) do
|
||||
changeset
|
||||
|> validate_required([:password])
|
||||
|> validate_length(:password, min: 12, max: 72)
|
||||
|> then(fn changeset ->
|
||||
if opts[:disable_password_validation] do
|
||||
changeset
|
||||
else
|
||||
changeset |> validate_length(:password, min: 12, max: 72)
|
||||
end
|
||||
end)
|
||||
# Examples of additional password validation:
|
||||
# |> validate_format(:password, ~r/[a-z]/, message: "at least one lower case character")
|
||||
# |> validate_format(:password, ~r/[A-Z]/, message: "at least one upper case character")
|
||||
|
|
|
@ -10,28 +10,35 @@
|
|||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
|
||||
alias ChoreTracker.Helpers
|
||||
|
||||
admin_password = Helpers.random_string(16)
|
||||
admin_password = "secret"
|
||||
|
||||
{:ok, admin} =
|
||||
ChoreTracker.Accounts.register_user(%{
|
||||
email: "admin@jednota.party",
|
||||
ChoreTracker.Accounts.register_user(
|
||||
%{
|
||||
email: "ondrej@jednota.party",
|
||||
password: admin_password,
|
||||
display_name: "Admin"
|
||||
})
|
||||
display_name: "Ondřej"
|
||||
},
|
||||
disable_password_validation: true
|
||||
)
|
||||
|
||||
ChoreTracker.Accounts.register_user(%{
|
||||
ChoreTracker.Accounts.register_user(
|
||||
%{
|
||||
email: "matej@jednota.party",
|
||||
password: Helpers.random_string(16),
|
||||
password: "secret",
|
||||
display_name: "Matěj"
|
||||
})
|
||||
},
|
||||
disable_password_validation: true
|
||||
)
|
||||
|
||||
ChoreTracker.Accounts.register_user(%{
|
||||
ChoreTracker.Accounts.register_user(
|
||||
%{
|
||||
email: "valentyna@jednota.party",
|
||||
password: Helpers.random_string(16),
|
||||
password: "secret",
|
||||
display_name: "Valentýna"
|
||||
})
|
||||
},
|
||||
disable_password_validation: true
|
||||
)
|
||||
|
||||
ChoreTracker.Chores.create_chore(%{
|
||||
name: "Uklidit kuchyň",
|
||||
|
|
Loading…
Reference in a new issue