Verified Commit de3a9395 authored by Nicolas's avatar Nicolas

Remove useless files

parent 30bd9fa3
defmodule PlasmaRepo.Users.Commands do
defmodule RegisterUser do
@enforce_keys [:username, :device_id, :access_token]
defstruct [:username, :password_hash, :device_id, :access_token, :initial_display_name]
end
defmodule AddDevice do
@enforce_keys [:device_id, :access_token]
defstruct [:device_id, :access_token, :initial_display_name]
end
defmodule RemoveDevice do
@enforce_keys [:device_id]
defstruct [:device_id]
end
defmodule RemoveAllDevices do
defstruct []
end
end
defmodule PlasmaRepo.Users.RegistrationRequest do
require Logger
use Ecto.Schema
embedded_schema do
field :bind_email, :boolean
field :user_id, :string
field :password, :string
field :password_hash, :string
field :device_id, :string
field :initial_device_display_name, :string
field :inhibit_login, :string
field :kind, :string
field :access_token, :string
end
def cast(request, params \\ %{}) do
request
|> Ecto.Changeset.cast(params, [
:bind_email,
:user_id,
:password,
:device_id,
:initial_device_display_name,
:inhibit_login,
:kind,
:access_token
])
end
# Validate registration username
# - if no username is provided, generate a new random one
# - if a localpart is given, build full username and check availability
def validate_username(changeset) do
case changeset do
%Ecto.Changeset{valid?: true} ->
case changeset.data.username do
nil ->
Ecto.Changeset.put_change(
changeset,
:username,
to_string(PlasmaRepo.Channels.Identifier.generate(:user))
)
username ->
if PlasmaRepo.Channels.Identifier.valid?(username) do
Logger.debug("Requested username: #{username}")
case PlasmaRepo.Channels.get_channel(username) do
nil ->
Ecto.Changeset.put_change(changeset, :username, username)
_ ->
Ecto.Changeset.add_error(changeset, :username, "user_in_use")
end
else
Ecto.Changeset.add_error(changeset, :username, "invalid_username")
end
end
_ ->
changeset
end
end
def validate_password(changeset) do
case changeset do
%Ecto.Changeset{valid?: true} ->
case changeset.data.password do
nil ->
changeset
password ->
Ecto.Changeset.put_change(changeset, :password_hash, Argon2.hash_pwd_salt(password))
end
_ ->
changeset
end
end
end
defmodule PlasmaRepo.Users.RegistrationResponse do
defstruct [:username, :devices]
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment