File tree 2 files changed +44
-0
lines changed 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ defmodule PollerDal.Users.User do
2
+ use Ecto.Schema
3
+ import Ecto.Changeset
4
+
5
+ schema "users" do
6
+ field ( :email , :string )
7
+ field ( :password_hash , :string )
8
+ field ( :password , :string , virtual: true )
9
+ field ( :admin , :boolean , default: false )
10
+
11
+ timestamps ( )
12
+ end
13
+
14
+ def registration_changeset ( user , attrs ) do
15
+ user
16
+ |> cast ( attrs , [ :email , :password ] )
17
+ |> validate_required ( [ :email , :password ] )
18
+ |> validate_length ( :password , min: 6 )
19
+ |> down_case_email ( )
20
+ |> unique_constraint ( :email )
21
+ end
22
+
23
+ defp down_case_email ( changeset ) do
24
+ case get_field ( changeset , :email ) do
25
+ nil -> changeset
26
+ email -> put_change ( changeset , :email , String . downcase ( email ) )
27
+ end
28
+ end
29
+ end
Original file line number Diff line number Diff line change
1
+ defmodule PollerDal.Repo.Migrations.CreateUsers do
2
+ use Ecto.Migration
3
+
4
+ def change do
5
+ create table ( :users ) do
6
+ add ( :email , :string )
7
+ add ( :password_hash , :string )
8
+ add ( :admin , :boolean )
9
+
10
+ timestamps ( )
11
+ end
12
+
13
+ create ( unique_index ( :users , [ :email ] ) )
14
+ end
15
+ end
You can’t perform that action at this time.
0 commit comments