Added fields to these Ecto changeset schemas based on latest migrations
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
defmodule Sukaato.Folio do
 | 
			
		||||
  use Ecto.Schema
 | 
			
		||||
  import Ecto.Changeset
 | 
			
		||||
  import Sukaato.Vschemas
 | 
			
		||||
  # import Sukaato.Vschemas
 | 
			
		||||
  import Sukaato.CustomValidators
 | 
			
		||||
 | 
			
		||||
  schema "folios" do
 | 
			
		||||
@@ -18,7 +18,7 @@ defmodule Sukaato.Folio do
 | 
			
		||||
    folio
 | 
			
		||||
    |> cast(attrs, [:resume, :showcase, :theme_uri])
 | 
			
		||||
    |> validate_required([:user_id, :showcase])
 | 
			
		||||
    |> validate_map_format(:resume, @resume_vschema)
 | 
			
		||||
    |> validate_map_format(:showcase, @showcase_vschema)
 | 
			
		||||
    |> validate_map_format(:resume, Sukaato.Vschemas.resume)
 | 
			
		||||
    |> validate_map_format(:showcase, Sukaato.Vschemas.showcase)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -21,8 +21,15 @@ defmodule Sukaato.Post do
 | 
			
		||||
  def changeset(post, attrs) do
 | 
			
		||||
    post
 | 
			
		||||
    |> cast(attrs, [:title, :abst, :slug, :content, :tags, :cat, :ledit])
 | 
			
		||||
    |> validate_required([:title, :slug, :content, :cat, :ledit])
 | 
			
		||||
    |> validate_required([:title, :content, :cat, :ledit])
 | 
			
		||||
    |> validate_format(:cat, ~r/^(\.(\w)+)+/)
 | 
			
		||||
    |> unique_constraint(:title)
 | 
			
		||||
    |> gen_slug()
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp gen_slug(changeset) do
 | 
			
		||||
    slug = changeset.changes.title |> String.downcase() |> String.replace(" ", "-")
 | 
			
		||||
 | 
			
		||||
    put_change(changeset, :slug, slug)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -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