@@ -9,6 +9,13 @@ defmodule MastaniServer.Accounts.User do
9
9
field ( :avatar , :string )
10
10
field ( :sex , :string )
11
11
field ( :bio , :string )
12
+ field ( :email , :string )
13
+ field ( :location , :string )
14
+ field ( :education , :string )
15
+ field ( :company , :string )
16
+ field ( :qq , :string )
17
+ field ( :weibo , :string )
18
+ field ( :weichat , :string )
12
19
field ( :from_github , :boolean )
13
20
has_one ( :github_profile , GithubUser )
14
21
@@ -22,8 +29,8 @@ defmodule MastaniServer.Accounts.User do
22
29
timestamps ( type: :utc_datetime )
23
30
end
24
31
25
- @ optional_fields ~w( nickname bio avatar sex) a
26
32
@ required_fields ~w( nickname avatar) a
33
+ @ optional_fields ~w( nickname bio avatar sex location email company education qq weichat weibo) a
27
34
28
35
@ doc false
29
36
def changeset ( % User { } = user , attrs ) do
@@ -33,7 +40,15 @@ defmodule MastaniServer.Accounts.User do
33
40
user
34
41
|> cast ( attrs , @ optional_fields ++ @ required_fields )
35
42
|> validate_required ( @ required_fields )
36
- |> validate_length ( :nickname , max: 30 )
43
+ |> validate_length ( :nickname , min: 3 , max: 30 )
44
+ |> validate_length ( :bio , min: 3 , max: 100 )
45
+ |> validate_inclusion ( :sex , [ "dude" , "girl" ] )
46
+ |> validate_format ( :email , ~r/ @/ )
47
+ |> validate_length ( :location , min: 2 , max: 30 )
48
+ |> validate_length ( :company , min: 3 , max: 30 )
49
+ |> validate_length ( :qq , min: 8 , max: 15 )
50
+ |> validate_length ( :weichat , min: 3 , max: 30 )
51
+ |> validate_length ( :weibo , min: 3 , max: 30 )
37
52
38
53
# |> unique_constraint(:username)
39
54
end