|
25 | 25 | from flask import request |
26 | 26 | from flask_jwt_extended import current_user |
27 | 27 | from flask_jwt_extended import jwt_required |
28 | | -from PyMatcha.models.user import get_user |
29 | 28 | from PyMatcha.utils import hash_password |
30 | 29 | from PyMatcha.utils.confirm_token import generate_confirmation_token |
31 | 30 | from PyMatcha.utils.decorators import validate_params |
32 | 31 | from PyMatcha.utils.errors import BadRequestError |
33 | | -from PyMatcha.utils.errors import NotFoundError |
34 | 32 | from PyMatcha.utils.errors import UnauthorizedError |
35 | 33 | from PyMatcha.utils.mail import send_mail_html |
36 | 34 | from PyMatcha.utils.mail import send_mail_text |
37 | 35 | from PyMatcha.utils.password import check_password |
38 | 36 | from PyMatcha.utils.static import FRONTEND_EMAIL_CONFIRMATION_URL |
39 | 37 | from PyMatcha.utils.success import Success |
40 | 38 |
|
| 39 | +# from PyMatcha.models.user import get_user |
| 40 | +# from PyMatcha.utils.errors import NotFoundError |
| 41 | + |
41 | 42 | profile_edit_bp = Blueprint("profile_edit", __name__) |
42 | 43 |
|
43 | 44 | REQUIRED_PARAMS_EDIT_PROFILE = { |
|
52 | 53 | } |
53 | 54 |
|
54 | 55 |
|
55 | | -@profile_edit_bp.route("/profile/edit", methods=["PUT"]) |
56 | | -@validate_params(REQUIRED_PARAMS_EDIT_PROFILE) |
| 56 | +@profile_edit_bp.route("/profile/edit/first_name", methods=["PATCH"]) |
| 57 | +@validate_params({"first_name": str}) |
57 | 58 | @jwt_required |
58 | | -def edit_profile(): |
| 59 | +def edit_profile_first_name(): |
59 | 60 | if not current_user.is_profile_completed: |
60 | 61 | raise BadRequestError("The user has not completed his profile.", "Complete your profile and try again.") |
61 | 62 | data = request.get_json() |
62 | 63 | first_name = data["first_name"] |
63 | | - last_name = data["last_name"] |
64 | | - username = data["username"] |
65 | | - bio = data["bio"] |
66 | | - gender = data["gender"] |
67 | | - orientation = data["orientation"] |
68 | | - birthdate = data["birthdate"] |
69 | | - |
70 | | - try: |
71 | | - birthdate = datetime.datetime.strptime(birthdate, "%d/%m/%Y").date() |
72 | | - except ValueError: |
73 | | - raise BadRequestError("Birthdate format must be %d/%m/%Y (day/month/year).") |
74 | | - |
75 | | - today = datetime.datetime.utcnow() |
76 | | - |
77 | | - age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) |
78 | | - if age < 18: |
79 | | - raise BadRequestError("You must be 18 years old or older.") |
80 | | - |
81 | | - try: |
82 | | - get_user(username) |
83 | | - except NotFoundError: |
84 | | - pass |
85 | | - else: |
86 | | - raise BadRequestError("Username taken.") |
87 | | - |
88 | | - if orientation not in ["heterosexual", "homosexual", "bisexual", "other"]: |
89 | | - raise BadRequestError("Orientation must be heterosexual, homosexual, bisexual or other.") |
| 64 | + current_user.first_name = first_name |
| 65 | + current_user.save() |
| 66 | + return Success("First name successfully modified!") |
90 | 67 |
|
91 | | - if gender not in ["male", "female", "other"]: |
92 | | - raise BadRequestError("Gender must be male, female or other.") |
93 | 68 |
|
| 69 | +@profile_edit_bp.route("/profile/edit/first_name", methods=["PATCH"]) |
| 70 | +@validate_params({"first_name": str}) |
| 71 | +@jwt_required |
| 72 | +def edit_profile_last_name(): |
| 73 | + if not current_user.is_profile_completed: |
| 74 | + raise BadRequestError("The user has not completed his profile.", "Complete your profile and try again.") |
| 75 | + data = request.get_json() |
| 76 | + first_name = data["first_name"] |
94 | 77 | current_user.first_name = first_name |
95 | | - current_user.last_name = last_name |
96 | | - current_user.username = username |
97 | | - current_user.bio = bio |
98 | | - current_user.gender = gender |
99 | | - current_user.orientation = orientation |
100 | | - current_user.birthdate = birthdate |
101 | 78 | current_user.save() |
102 | | - return Success("User successfully modified !") |
| 79 | + return Success("First name successfully modified!") |
| 80 | + |
| 81 | + |
| 82 | +# @profile_edit_bp.route("/profile/edit", methods=["PUT"]) |
| 83 | +# @validate_params(REQUIRED_PARAMS_EDIT_PROFILE) |
| 84 | +# @jwt_required |
| 85 | +# def edit_profile(): |
| 86 | +# if not current_user.is_profile_completed: |
| 87 | +# raise BadRequestError("The user has not completed his profile.", "Complete your profile and try again.") |
| 88 | +# data = request.get_json() |
| 89 | +# first_name = data["first_name"] |
| 90 | +# last_name = data["last_name"] |
| 91 | +# username = data["username"] |
| 92 | +# bio = data["bio"] |
| 93 | +# gender = data["gender"] |
| 94 | +# orientation = data["orientation"] |
| 95 | +# birthdate = data["birthdate"] |
| 96 | +# |
| 97 | +# try: |
| 98 | +# birthdate = datetime.datetime.strptime(birthdate, "%d/%m/%Y").date() |
| 99 | +# except ValueError: |
| 100 | +# raise BadRequestError("Birthdate format must be %d/%m/%Y (day/month/year).") |
| 101 | +# |
| 102 | +# today = datetime.datetime.utcnow() |
| 103 | +# |
| 104 | +# age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) |
| 105 | +# if age < 18: |
| 106 | +# raise BadRequestError("You must be 18 years old or older.") |
| 107 | +# |
| 108 | +# try: |
| 109 | +# get_user(username) |
| 110 | +# except NotFoundError: |
| 111 | +# pass |
| 112 | +# else: |
| 113 | +# raise BadRequestError("Username taken.") |
| 114 | +# |
| 115 | +# if orientation not in ["heterosexual", "homosexual", "bisexual", "other"]: |
| 116 | +# raise BadRequestError("Orientation must be heterosexual, homosexual, bisexual or other.") |
| 117 | +# |
| 118 | +# if gender not in ["male", "female", "other"]: |
| 119 | +# raise BadRequestError("Gender must be male, female or other.") |
| 120 | +# |
| 121 | +# current_user.first_name = first_name |
| 122 | +# current_user.last_name = last_name |
| 123 | +# current_user.username = username |
| 124 | +# current_user.bio = bio |
| 125 | +# current_user.gender = gender |
| 126 | +# current_user.orientation = orientation |
| 127 | +# current_user.birthdate = birthdate |
| 128 | +# current_user.save() |
| 129 | +# return Success("User successfully modified !") |
103 | 130 |
|
104 | 131 |
|
105 | 132 | @profile_edit_bp.route("/profile/edit/email", methods=["PUT"]) |
|
0 commit comments