Skip to content

Commit 9e16b05

Browse files
committed
Updated birthdate format for profile edit
1 parent 20fb35e commit 9e16b05

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

PyMatcha.postman_collection.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@
17431743
"header": [],
17441744
"body": {
17451745
"mode": "raw",
1746-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1746+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"{{user_birthdate}}\"\n}",
17471747
"options": {
17481748
"raw": {
17491749
"language": "json"
@@ -1810,7 +1810,7 @@
18101810
"header": [],
18111811
"body": {
18121812
"mode": "raw",
1813-
"raw": "{\n\t\"orientation\": \"homosexual\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"male\",\n\t\"birthdate\": {{user_birthdate}},\n\t\"first_name\": \"Foo\",\n\t\"last_name\": \"Bar\",\n\t\"username\": \"FooBar\"\n}",
1813+
"raw": "{\n\t\"orientation\": \"homosexual\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"male\",\n\t\"birthdate\": \"{{user_birthdate}}\",\n\t\"first_name\": \"Foo\",\n\t\"last_name\": \"Bar\",\n\t\"username\": \"FooBar\"\n}",
18141814
"options": {
18151815
"raw": {
18161816
"language": "json"
@@ -3846,109 +3846,109 @@
38463846
],
38473847
"variable": [
38483848
{
3849-
"id": "6099b8b2-2e73-44f4-9f74-78e9089dfdff",
3849+
"id": "67d932fb-073d-43ef-9460-1262b4d04584",
38503850
"key": "host",
38513851
"value": "http://127.0.0.1:5000",
38523852
"type": "string"
38533853
},
38543854
{
3855-
"id": "714206c8-2107-4eff-8ae8-ebf5e2015f94",
3855+
"id": "6217dac6-98f4-4fb0-8020-98120a3f95d2",
38563856
"key": "user_id",
38573857
"value": "",
38583858
"type": "string"
38593859
},
38603860
{
3861-
"id": "4e75b103-8383-47ee-bef0-4425f7ff99c5",
3861+
"id": "b51b39a2-02a2-4b77-94ab-a277dceda470",
38623862
"key": "user_email",
38633863
"value": "foo@example.org",
38643864
"type": "string"
38653865
},
38663866
{
3867-
"id": "665e0304-daa9-4c01-b859-780889d2ff5f",
3867+
"id": "5ee1508b-8f92-4f47-b2d5-31ae9f7e5ed1",
38683868
"key": "user_username",
38693869
"value": "foo",
38703870
"type": "string"
38713871
},
38723872
{
3873-
"id": "cf9665a1-0e7e-430d-8011-a3b352043b6e",
3873+
"id": "b4c170f3-b982-4296-a5d8-faba84e73b80",
38743874
"key": "user_password",
38753875
"value": "admin",
38763876
"type": "string"
38773877
},
38783878
{
3879-
"id": "93c59f99-458f-4e39-a7e7-87a6e1f6f377",
3879+
"id": "96c93b0a-de2e-4726-b53a-43b8e7879474",
38803880
"key": "user_firstname",
38813881
"value": "Foo",
38823882
"type": "string"
38833883
},
38843884
{
3885-
"id": "f2ae4172-b5ec-4640-b4af-f8be4853ec49",
3885+
"id": "4aa9fcef-e2de-4d49-a286-998b84fe4b44",
38863886
"key": "user_lastname",
38873887
"value": "Bar",
38883888
"type": "string"
38893889
},
38903890
{
3891-
"id": "d936adc6-51e9-48ca-b5d7-8a3a54a73650",
3891+
"id": "609d2b71-5892-4763-8433-516f3e33c224",
38923892
"key": "debug_token",
38933893
"value": "xX69jules69Xx",
38943894
"type": "string"
38953895
},
38963896
{
3897-
"id": "186a863a-cc6e-4187-b636-ff1b7df31d14",
3897+
"id": "66fd42f3-d56f-4b50-b7d2-b376b49edb55",
38983898
"key": "user_access_token",
38993899
"value": "",
39003900
"type": "string"
39013901
},
39023902
{
3903-
"id": "f3e535fc-76c9-49eb-92c1-a4c5ff3c5307",
3903+
"id": "ec955af3-dcc6-4bad-855c-842f395741b1",
39043904
"key": "user_refresh_token",
39053905
"value": "",
39063906
"type": "string"
39073907
},
39083908
{
3909-
"id": "70529b93-f36f-4a24-88de-b1842f0b61e9",
3909+
"id": "c219813e-7377-4b09-b608-ff0cee573747",
39103910
"key": "expired_token",
39113911
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU",
39123912
"type": "string"
39133913
},
39143914
{
3915-
"id": "9c08e3a8-2605-45cd-b367-da94e7b1befc",
3915+
"id": "a77dccc5-c086-4888-9014-ac304e1ea8d9",
39163916
"key": "user_orientation",
39173917
"value": "heterosexual",
39183918
"type": "string"
39193919
},
39203920
{
3921-
"id": "e495090b-8ca2-4fe3-97fc-2e6ac3ab1a7b",
3921+
"id": "b877aa0c-babd-4255-968a-3b1c07e4b1af",
39223922
"key": "user_bio",
39233923
"value": "Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites. Lorem Ipsum best not make any more threats to your website. It will be met with fire and fury like the world has never seen. Does everybody know that pig named Lorem Ipsum? An ‘extremely credible source’ has called my office and told me that Barack Obama’s placeholder text is a fraud.",
39243924
"type": "string"
39253925
},
39263926
{
3927-
"id": "6e78fb84-ee65-416d-96bf-82141d494e19",
3927+
"id": "55719b16-b04a-4533-b3e5-458663a60569",
39283928
"key": "user_gender",
39293929
"value": "male",
39303930
"type": "string"
39313931
},
39323932
{
3933-
"id": "ae88bd6a-68ef-43ec-9cfa-04aba929cfcc",
3933+
"id": "ade7c16f-9ea0-436a-9cc4-c7e691efdacd",
39343934
"key": "user_birthdate",
39353935
"value": "06/04/1998",
39363936
"type": "string"
39373937
},
39383938
{
3939-
"id": "083094e4-16bf-4eb9-bf9e-ecb37ebf747f",
3939+
"id": "6b00f154-1f8a-493c-ad4f-bc1f0cf5bb24",
39403940
"key": "user_lat",
39413941
"value": "44.8404",
39423942
"type": "string"
39433943
},
39443944
{
3945-
"id": "ae94618b-31bb-4c07-9c87-f7d81bc32eef",
3945+
"id": "0e519257-8fe5-4431-be54-8710b97fee58",
39463946
"key": "user_lng",
39473947
"value": "-0.5805",
39483948
"type": "string"
39493949
},
39503950
{
3951-
"id": "89b0ed54-50e0-4924-b6cc-ac61756173ec",
3951+
"id": "1f84e450-4185-4966-b767-aec7aae6e19f",
39523952
"key": "user_ip",
39533953
"value": "77.205.46.181",
39543954
"type": "string"

backend/PyMatcha/routes/api/profile.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ def edit_profile():
118118
orientation = data["orientation"]
119119
birthdate = data["birthdate"]
120120

121+
try:
122+
birthdate = datetime.datetime.strptime(birthdate, "%d/%m/%Y").date()
123+
except ValueError:
124+
raise BadRequestError("Birthdate format must be %d/%m/%Y (day/month/year)", "Try again")
125+
126+
today = datetime.datetime.utcnow()
127+
128+
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
129+
if age < 18:
130+
raise BadRequestError("You must be 18 years old or older", "Try again later")
131+
121132
try:
122133
get_user(username)
123134
except NotFoundError:
@@ -131,8 +142,6 @@ def edit_profile():
131142
if gender not in ["male", "female", "other"]:
132143
raise BadRequestError("Gender must be male, female or other", "Try again")
133144

134-
birthdate = datetime.date.fromtimestamp(birthdate)
135-
136145
current_user.first_name = first_name
137146
current_user.last_name = last_name
138147
current_user.username = username

0 commit comments

Comments
 (0)