summaryrefslogtreecommitdiff
path: root/lib/aggiedit/rooms
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-06 12:13:54 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-06 12:13:54 -0600
commit2055742911201258e6f755b3eb4031a1b09407f1 (patch)
treea8e0471cab55329e2e00b5d3e2011d37bb67fdb6 /lib/aggiedit/rooms
downloadaggiedit-2055742911201258e6f755b3eb4031a1b09407f1.tar.gz
aggiedit-2055742911201258e6f755b3eb4031a1b09407f1.zip
Initial commit; generate auth code with phx.gen.auth; added room model and association; generate room model on domain of user emails; allow users to change their email
Diffstat (limited to 'lib/aggiedit/rooms')
-rw-r--r--lib/aggiedit/rooms/room.ex22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/aggiedit/rooms/room.ex b/lib/aggiedit/rooms/room.ex
new file mode 100644
index 0000000..24f1b8a
--- /dev/null
+++ b/lib/aggiedit/rooms/room.ex
@@ -0,0 +1,22 @@
+defmodule Aggiedit.Rooms.Room do
+ use Ecto.Schema
+ import Ecto.Changeset
+
+ schema "rooms" do
+ field :domain, :string
+
+ has_many :users, Aggiedit.Accounts.User
+
+ timestamps()
+ end
+
+ @doc false
+ def changeset(room, attrs) do
+ room
+ |> cast(attrs, [:domain])
+ |> validate_required([:domain])
+ |> validate_length(:domain, max: 160)
+ |> validate_format(:domain, ~r/^[^\s\.]+\.[^\.\s]+$/, message: "Domain cannot be a subdomain, and cannot have spaces")
+ |> unique_constraint(:domain)
+ end
+end