Added fields to these Ecto changeset schemas based on latest migrations
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
defmodule Sukaato.User do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Sukaato.Vschemas
|
||||
# import Sukaato.Vschemas
|
||||
import Sukaato.CustomValidators
|
||||
|
||||
schema "users" do
|
||||
@@ -17,6 +17,15 @@ defmodule Sukaato.User do
|
||||
field :perms, {:array, :integer}
|
||||
field :user_token, :string
|
||||
field :pub_keys, :map
|
||||
field :totp_enabled, :boolean, default: false
|
||||
field :totp_active, :boolean, default: true
|
||||
field :totp_secret, :string
|
||||
field :ltotp, :utc_datetime
|
||||
field :fido_enabled, :boolean, default: false
|
||||
field :fido_active, :boolean, default: false
|
||||
field :fido_priority, :integer
|
||||
field :fido_creds, {:array, :string}
|
||||
field :fido_keys, {:array, :map}
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
@@ -24,13 +33,36 @@ defmodule Sukaato.User do
|
||||
@doc false
|
||||
def changeset(user, attrs) do
|
||||
user
|
||||
|> cast(attrs, [:name, :username, :password, :email, :dob, :gender_type, :gender_id, :bio, :affil, :perms, :user_token, :pub_keys])
|
||||
|> validate_required([:username, :password, :email, :dob, :perms, :user_token])
|
||||
|> cast(attrs, [
|
||||
:name,
|
||||
:username,
|
||||
:password,
|
||||
:email,
|
||||
:dob,
|
||||
:gender_type,
|
||||
:gender_id,
|
||||
:bio,
|
||||
:affil,
|
||||
:perms,
|
||||
:user_token,
|
||||
:pub_keys,
|
||||
:totp_enabled,
|
||||
:totp_active,
|
||||
:totp_secret,
|
||||
:ltotp,
|
||||
:fido_enabled,
|
||||
:fido_active,
|
||||
:fido_priority,
|
||||
:fido_creds,
|
||||
:fido_keys
|
||||
])
|
||||
|> validate_required([:username, :password, :email, :perms])
|
||||
|> validate_length(:perms, is: 6)
|
||||
|> validate_format(:email, ~r/@/)
|
||||
|> validate_map_format(:perms, @perms_vschema)
|
||||
|> validate_map_format(:affil, @affil_vschema)
|
||||
|> validate_map_format(:pub_keys, @pubkeys_vschema)
|
||||
|> validate_map_format(:perms, Sukaato.Vschemas.perms)
|
||||
|> validate_map_format(:affil, Sukaato.Vschemas.affil)
|
||||
|> validate_map_format(:pub_keys, Sukaato.Vschemas.pub_keys)
|
||||
|> encrypt_password(:password)
|
||||
|> unique_constraint(:username)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user