diff --git a/backend/src/models/ChangePasswordReq.ts b/backend/src/models/ChangePasswordReq.ts index 6cefb352..3245bc51 100644 --- a/backend/src/models/ChangePasswordReq.ts +++ b/backend/src/models/ChangePasswordReq.ts @@ -1,5 +1,5 @@ -export interface ChangePasswordReq{ - old_password: string, - new_password: string, - repeat_password: string -} \ No newline at end of file +export interface ChangePasswordReq { + old_password: string; + new_password: string; + repeat_password: string; +} diff --git a/backend/src/routes/usersRoute.ts b/backend/src/routes/usersRoute.ts index e74aa52d..2dd00509 100644 --- a/backend/src/routes/usersRoute.ts +++ b/backend/src/routes/usersRoute.ts @@ -306,49 +306,58 @@ usersRouter.put("/:userId", async (req: Request, res: OkErrorResponse) => { } }); -usersRouter.post("/:userId/change-password", async (req: Request, res: OkErrorResponse) => { - try { - const userId = req.params.userId; - const passwords: ChangePasswordReq = req.body; - - const {old_password, new_password, repeat_password} = passwords +usersRouter.post( + "/:userId/change-password", + async (req: Request, res: OkErrorResponse) => { + try { + const userId = req.params.userId; + const passwords: ChangePasswordReq = req.body; - const session = driver.session(); - const user = await userExists(session, { id: userId }); + const { old_password, new_password, repeat_password } = passwords; - if (!user) { - return userNotFoundRes(res); - } + const session = driver.session(); + const user = await userExists(session, { id: userId }); - // check validation of the old password + if (!user) { + return userNotFoundRes(res); + } - const match: boolean = await bcrypt.compare(old_password, user.password); + // check validation of the old password - if(!match) { - return res.status(400).json({ status: "error", errors: {"error":""} }); - } + const match: boolean = await bcrypt.compare(old_password, user.password); - // check if there are two same password - if(new_password !== repeat_password){ - return res.status(400).json({ status: "error", errors: {"error":"Passwords don't match"} }); + if (!match) { + return res + .status(400) + .json({ status: "error", errors: { "error": "" } }); } - const passwordHashed = await bcrypt.hash(new_password, 10); + // check if there are two same password + if (new_password !== repeat_password) { + return res + .status(400) + .json({ + status: "error", + errors: { "error": "Passwords don't match" }, + }); + } + const passwordHashed = await bcrypt.hash(new_password, 10); - const updatedUser = { ...user, password: passwordHashed }; - await session.run(`MATCH (u:User {id: $userId}) SET u=$user`, { - userId, - user: updatedUser, - }); - await session.close(); + const updatedUser = { ...user, password: passwordHashed }; + await session.run(`MATCH (u:User {id: $userId}) SET u=$user`, { + userId, + user: updatedUser, + }); + await session.close(); - return res.json({ status: "ok" }); - } catch (err) { - console.log("Error:", err); - return res.status(404).json({ status: "error", errors: err as object }); - } -}); + return res.json({ status: "ok" }); + } catch (err) { + console.log("Error:", err); + return res.status(404).json({ status: "error", errors: err as object }); + } + }, +); usersRouter.delete("/:userId", async (req: Request, res: OkErrorResponse) => { try { diff --git a/frontend/src/assets/countries.json b/frontend/src/assets/countries.json index 64015f4f..1ceed16c 100644 --- a/frontend/src/assets/countries.json +++ b/frontend/src/assets/countries.json @@ -1,197 +1,196 @@ [ - {"Country": "Afghanistan", "Code": "AF"}, - {"Country": "Albania", "Code": "AL"}, - {"Country": "Algeria", "Code": "DZ"}, - {"Country": "Andorra", "Code": "AD"}, - {"Country": "Angola", "Code": "AO"}, - {"Country": "Antigua and Barbuda", "Code": "AG"}, - {"Country": "Argentina", "Code": "AR"}, - {"Country": "Armenia", "Code": "AM"}, - {"Country": "Australia", "Code": "AU"}, - {"Country": "Austria", "Code": "AT"}, - {"Country": "Azerbaijan", "Code": "AZ"}, - {"Country": "Bahamas", "Code": "BS"}, - {"Country": "Bahrain", "Code": "BH"}, - {"Country": "Bangladesh", "Code": "BD"}, - {"Country": "Barbados", "Code": "BB"}, - {"Country": "Belarus", "Code": "BY"}, - {"Country": "Belgium", "Code": "BE"}, - {"Country": "Belize", "Code": "BZ"}, - {"Country": "Benin", "Code": "BJ"}, - {"Country": "Bhutan", "Code": "BT"}, - {"Country": "Bolivia", "Code": "BO"}, - {"Country": "Bosnia and Herzegovina", "Code": "BA"}, - {"Country": "Botswana", "Code": "BW"}, - {"Country": "Brazil", "Code": "BR"}, - {"Country": "Brunei", "Code": "BN"}, - {"Country": "Bulgaria", "Code": "BG"}, - {"Country": "Burkina Faso", "Code": "BF"}, - {"Country": "Burundi", "Code": "BI"}, - {"Country": "Cabo Verde", "Code": "CV"}, - {"Country": "Cambodia", "Code": "KH"}, - {"Country": "Cameroon", "Code": "CM"}, - {"Country": "Canada", "Code": "CA"}, - {"Country": "Central African Republic", "Code": "CF"}, - {"Country": "Chad", "Code": "TD"}, - {"Country": "Chile", "Code": "CL"}, - {"Country": "China", "Code": "CN"}, - {"Country": "Colombia", "Code": "CO"}, - {"Country": "Comoros", "Code": "KM"}, - {"Country": "Congo (Congo-Brazzaville)", "Code": "CG"}, - {"Country": "Costa Rica", "Code": "CR"}, - {"Country": "Croatia", "Code": "HR"}, - {"Country": "Cuba", "Code": "CU"}, - {"Country": "Cyprus", "Code": "CY"}, - {"Country": "Czechia (Czech Republic)", "Code": "CZ"}, - {"Country": "Democratic Republic of the Congo", "Code": "CD"}, - {"Country": "Denmark", "Code": "DK"}, - {"Country": "Djibouti", "Code": "DJ"}, - {"Country": "Dominica", "Code": "DM"}, - {"Country": "Dominican Republic", "Code": "DO"}, - {"Country": "Ecuador", "Code": "EC"}, - {"Country": "Egypt", "Code": "EG"}, - {"Country": "El Salvador", "Code": "SV"}, - {"Country": "Equatorial Guinea", "Code": "GQ"}, - {"Country": "Eritrea", "Code": "ER"}, - {"Country": "Estonia", "Code": "EE"}, - {"Country": "Eswatini (fmr. Swaziland)", "Code": "SZ"}, - {"Country": "Ethiopia", "Code": "ET"}, - {"Country": "Fiji", "Code": "FJ"}, - {"Country": "Finland", "Code": "FI"}, - {"Country": "France", "Code": "FR"}, - {"Country": "Gabon", "Code": "GA"}, - {"Country": "Gambia", "Code": "GM"}, - {"Country": "Georgia", "Code": "GE"}, - {"Country": "Germany", "Code": "DE"}, - {"Country": "Ghana", "Code": "GH"}, - {"Country": "Greece", "Code": "GR"}, - {"Country": "Grenada", "Code": "GD"}, - {"Country": "Guatemala", "Code": "GT"}, - {"Country": "Guinea", "Code": "GN"}, - {"Country": "Guinea-Bissau", "Code": "GW"}, - {"Country": "Guyana", "Code": "GY"}, - {"Country": "Haiti", "Code": "HT"}, - {"Country": "Holy See", "Code": "VA"}, - {"Country": "Honduras", "Code": "HN"}, - {"Country": "Hungary", "Code": "HU"}, - {"Country": "Iceland", "Code": "IS"}, - {"Country": "India", "Code": "IN"}, - {"Country": "Indonesia", "Code": "ID"}, - {"Country": "Iran", "Code": "IR"}, - {"Country": "Iraq", "Code": "IQ"}, - {"Country": "Ireland", "Code": "IE"}, - {"Country": "Israel", "Code": "IL"}, - {"Country": "Italy", "Code": "IT"}, - {"Country": "Jamaica", "Code": "JM"}, - {"Country": "Japan", "Code": "JP"}, - {"Country": "Jordan", "Code": "JO"}, - {"Country": "Kazakhstan", "Code": "KZ"}, - {"Country": "Kenya", "Code": "KE"}, - {"Country": "Kiribati", "Code": "KI"}, - {"Country": "Kuwait", "Code": "KW"}, - {"Country": "Kyrgyzstan", "Code": "KG"}, - {"Country": "Laos", "Code": "LA"}, - {"Country": "Latvia", "Code": "LV"}, - {"Country": "Lebanon", "Code": "LB"}, - {"Country": "Lesotho", "Code": "LS"}, - {"Country": "Liberia", "Code": "LR"}, - {"Country": "Libya", "Code": "LY"}, - {"Country": "Liechtenstein", "Code": "LI"}, - {"Country": "Lithuania", "Code": "LT"}, - {"Country": "Luxembourg", "Code": "LU"}, - {"Country": "Madagascar", "Code": "MG"}, - {"Country": "Malawi", "Code": "MW"}, - {"Country": "Malaysia", "Code": "MY"}, - {"Country": "Maldives", "Code": "MV"}, - {"Country": "Mali", "Code": "ML"}, - {"Country": "Malta", "Code": "MT"}, - {"Country": "Marshall Islands", "Code": "MH"}, - {"Country": "Mauritania", "Code": "MR"}, - {"Country": "Mauritius", "Code": "MU"}, - {"Country": "Mexico", "Code": "MX"}, - {"Country": "Micronesia", "Code": "FM"}, - {"Country": "Moldova", "Code": "MD"}, - {"Country": "Monaco", "Code": "MC"}, - {"Country": "Mongolia", "Code": "MN"}, - {"Country": "Montenegro", "Code": "ME"}, - {"Country": "Morocco", "Code": "MA"}, - {"Country": "Mozambique", "Code": "MZ"}, - {"Country": "Myanmar (formerly Burma)", "Code": "MM"}, - {"Country": "Namibia", "Code": "NA"}, - {"Country": "Nauru", "Code": "NR"}, - {"Country": "Nepal", "Code": "NP"}, - {"Country": "Netherlands", "Code": "NL"}, - {"Country": "New Zealand", "Code": "NZ"}, - {"Country": "Nicaragua", "Code": "NI"}, - {"Country": "Niger", "Code": "NE"}, - {"Country": "Nigeria", "Code": "NG"}, - {"Country": "North Korea", "Code": "KP"}, - {"Country": "North Macedonia", "Code": "MK"}, - {"Country": "Norway", "Code": "NO"}, - {"Country": "Oman", "Code": "OM"}, - {"Country": "Pakistan", "Code": "PK"}, - {"Country": "Palau", "Code": "PW"}, - {"Country": "Palestine State", "Code": "PS"}, - {"Country": "Panama", "Code": "PA"}, - {"Country": "Papua New Guinea", "Code": "PG"}, - {"Country": "Paraguay", "Code": "PY"}, - {"Country": "Peru", "Code": "PE"}, - {"Country": "Philippines", "Code": "PH"}, - {"Country": "Poland", "Code": "PL"}, - {"Country": "Portugal", "Code": "PT"}, - {"Country": "Qatar", "Code": "QA"}, - {"Country": "Romania", "Code": "RO"}, - {"Country": "Russia", "Code": "RU"}, - {"Country": "Rwanda", "Code": "RW"}, - {"Country": "Saint Kitts and Nevis", "Code": "KN"}, - {"Country": "Saint Lucia", "Code": "LC"}, - {"Country": "Saint Vincent and the Grenadines", "Code": "VC"}, - {"Country": "Samoa", "Code": "WS"}, - {"Country": "San Marino", "Code": "SM"}, - {"Country": "Sao Tome and Principe", "Code": "ST"}, - {"Country": "Saudi Arabia", "Code": "SA"}, - {"Country": "Senegal", "Code": "SN"}, - {"Country": "Serbia", "Code": "RS"}, - {"Country": "Seychelles", "Code": "SC"}, - {"Country": "Sierra Leone", "Code": "SL"}, - {"Country": "Singapore", "Code": "SG"}, - {"Country": "Slovakia", "Code": "SK"}, - {"Country": "Slovenia", "Code": "SI"}, - {"Country": "Solomon Islands", "Code": "SB"}, - {"Country": "Somalia", "Code": "SO"}, - {"Country": "South Africa", "Code": "ZA"}, - {"Country": "South Korea", "Code": "KR"}, - {"Country": "South Sudan", "Code": "SS"}, - {"Country": "Spain", "Code": "ES"}, - {"Country": "Sri Lanka", "Code": "LK"}, - {"Country": "Sudan", "Code": "SD"}, - {"Country": "Suriname", "Code": "SR"}, - {"Country": "Sweden", "Code": "SE"}, - {"Country": "Switzerland", "Code": "CH"}, - {"Country": "Syria", "Code": "SY"}, - {"Country": "Tajikistan", "Code": "TJ"}, - {"Country": "Tanzania", "Code": "TZ"}, - {"Country": "Thailand", "Code": "TH"}, - {"Country": "Timor-Leste", "Code": "TL"}, - {"Country": "Togo", "Code": "TG"}, - {"Country": "Tonga", "Code": "TO"}, - {"Country": "Trinidad and Tobago", "Code": "TT"}, - {"Country": "Tunisia", "Code": "TN"}, - {"Country": "Turkey", "Code": "TR"}, - {"Country": "Turkmenistan", "Code": "TM"}, - {"Country": "Tuvalu", "Code": "TV"}, - {"Country": "Uganda", "Code": "UG"}, - {"Country": "Ukraine", "Code": "UA"}, - {"Country": "United Arab Emirates", "Code": "AE"}, - {"Country": "United Kingdom", "Code": "GB"}, - {"Country": "United States of America", "Code": "US"}, - {"Country": "Uruguay", "Code": "UY"}, - {"Country": "Uzbekistan", "Code": "UZ"}, - {"Country": "Vanuatu", "Code": "VU"}, - {"Country": "Venezuela", "Code": "VE"}, - {"Country": "Vietnam", "Code": "VN"}, - {"Country": "Yemen", "Code": "YE"}, - {"Country": "Zambia", "Code": "ZM"}, - {"Country": "Zimbabwe", "Code": "ZW"} + { "Country": "Afghanistan", "Code": "AF" }, + { "Country": "Albania", "Code": "AL" }, + { "Country": "Algeria", "Code": "DZ" }, + { "Country": "Andorra", "Code": "AD" }, + { "Country": "Angola", "Code": "AO" }, + { "Country": "Antigua and Barbuda", "Code": "AG" }, + { "Country": "Argentina", "Code": "AR" }, + { "Country": "Armenia", "Code": "AM" }, + { "Country": "Australia", "Code": "AU" }, + { "Country": "Austria", "Code": "AT" }, + { "Country": "Azerbaijan", "Code": "AZ" }, + { "Country": "Bahamas", "Code": "BS" }, + { "Country": "Bahrain", "Code": "BH" }, + { "Country": "Bangladesh", "Code": "BD" }, + { "Country": "Barbados", "Code": "BB" }, + { "Country": "Belarus", "Code": "BY" }, + { "Country": "Belgium", "Code": "BE" }, + { "Country": "Belize", "Code": "BZ" }, + { "Country": "Benin", "Code": "BJ" }, + { "Country": "Bhutan", "Code": "BT" }, + { "Country": "Bolivia", "Code": "BO" }, + { "Country": "Bosnia and Herzegovina", "Code": "BA" }, + { "Country": "Botswana", "Code": "BW" }, + { "Country": "Brazil", "Code": "BR" }, + { "Country": "Brunei", "Code": "BN" }, + { "Country": "Bulgaria", "Code": "BG" }, + { "Country": "Burkina Faso", "Code": "BF" }, + { "Country": "Burundi", "Code": "BI" }, + { "Country": "Cabo Verde", "Code": "CV" }, + { "Country": "Cambodia", "Code": "KH" }, + { "Country": "Cameroon", "Code": "CM" }, + { "Country": "Canada", "Code": "CA" }, + { "Country": "Central African Republic", "Code": "CF" }, + { "Country": "Chad", "Code": "TD" }, + { "Country": "Chile", "Code": "CL" }, + { "Country": "China", "Code": "CN" }, + { "Country": "Colombia", "Code": "CO" }, + { "Country": "Comoros", "Code": "KM" }, + { "Country": "Congo (Congo-Brazzaville)", "Code": "CG" }, + { "Country": "Costa Rica", "Code": "CR" }, + { "Country": "Croatia", "Code": "HR" }, + { "Country": "Cuba", "Code": "CU" }, + { "Country": "Cyprus", "Code": "CY" }, + { "Country": "Czechia (Czech Republic)", "Code": "CZ" }, + { "Country": "Democratic Republic of the Congo", "Code": "CD" }, + { "Country": "Denmark", "Code": "DK" }, + { "Country": "Djibouti", "Code": "DJ" }, + { "Country": "Dominica", "Code": "DM" }, + { "Country": "Dominican Republic", "Code": "DO" }, + { "Country": "Ecuador", "Code": "EC" }, + { "Country": "Egypt", "Code": "EG" }, + { "Country": "El Salvador", "Code": "SV" }, + { "Country": "Equatorial Guinea", "Code": "GQ" }, + { "Country": "Eritrea", "Code": "ER" }, + { "Country": "Estonia", "Code": "EE" }, + { "Country": "Eswatini (fmr. Swaziland)", "Code": "SZ" }, + { "Country": "Ethiopia", "Code": "ET" }, + { "Country": "Fiji", "Code": "FJ" }, + { "Country": "Finland", "Code": "FI" }, + { "Country": "France", "Code": "FR" }, + { "Country": "Gabon", "Code": "GA" }, + { "Country": "Gambia", "Code": "GM" }, + { "Country": "Georgia", "Code": "GE" }, + { "Country": "Germany", "Code": "DE" }, + { "Country": "Ghana", "Code": "GH" }, + { "Country": "Greece", "Code": "GR" }, + { "Country": "Grenada", "Code": "GD" }, + { "Country": "Guatemala", "Code": "GT" }, + { "Country": "Guinea", "Code": "GN" }, + { "Country": "Guinea-Bissau", "Code": "GW" }, + { "Country": "Guyana", "Code": "GY" }, + { "Country": "Haiti", "Code": "HT" }, + { "Country": "Holy See", "Code": "VA" }, + { "Country": "Honduras", "Code": "HN" }, + { "Country": "Hungary", "Code": "HU" }, + { "Country": "Iceland", "Code": "IS" }, + { "Country": "India", "Code": "IN" }, + { "Country": "Indonesia", "Code": "ID" }, + { "Country": "Iran", "Code": "IR" }, + { "Country": "Iraq", "Code": "IQ" }, + { "Country": "Ireland", "Code": "IE" }, + { "Country": "Israel", "Code": "IL" }, + { "Country": "Italy", "Code": "IT" }, + { "Country": "Jamaica", "Code": "JM" }, + { "Country": "Japan", "Code": "JP" }, + { "Country": "Jordan", "Code": "JO" }, + { "Country": "Kazakhstan", "Code": "KZ" }, + { "Country": "Kenya", "Code": "KE" }, + { "Country": "Kiribati", "Code": "KI" }, + { "Country": "Kuwait", "Code": "KW" }, + { "Country": "Kyrgyzstan", "Code": "KG" }, + { "Country": "Laos", "Code": "LA" }, + { "Country": "Latvia", "Code": "LV" }, + { "Country": "Lebanon", "Code": "LB" }, + { "Country": "Lesotho", "Code": "LS" }, + { "Country": "Liberia", "Code": "LR" }, + { "Country": "Libya", "Code": "LY" }, + { "Country": "Liechtenstein", "Code": "LI" }, + { "Country": "Lithuania", "Code": "LT" }, + { "Country": "Luxembourg", "Code": "LU" }, + { "Country": "Madagascar", "Code": "MG" }, + { "Country": "Malawi", "Code": "MW" }, + { "Country": "Malaysia", "Code": "MY" }, + { "Country": "Maldives", "Code": "MV" }, + { "Country": "Mali", "Code": "ML" }, + { "Country": "Malta", "Code": "MT" }, + { "Country": "Marshall Islands", "Code": "MH" }, + { "Country": "Mauritania", "Code": "MR" }, + { "Country": "Mauritius", "Code": "MU" }, + { "Country": "Mexico", "Code": "MX" }, + { "Country": "Micronesia", "Code": "FM" }, + { "Country": "Moldova", "Code": "MD" }, + { "Country": "Monaco", "Code": "MC" }, + { "Country": "Mongolia", "Code": "MN" }, + { "Country": "Montenegro", "Code": "ME" }, + { "Country": "Morocco", "Code": "MA" }, + { "Country": "Mozambique", "Code": "MZ" }, + { "Country": "Myanmar (formerly Burma)", "Code": "MM" }, + { "Country": "Namibia", "Code": "NA" }, + { "Country": "Nauru", "Code": "NR" }, + { "Country": "Nepal", "Code": "NP" }, + { "Country": "Netherlands", "Code": "NL" }, + { "Country": "New Zealand", "Code": "NZ" }, + { "Country": "Nicaragua", "Code": "NI" }, + { "Country": "Niger", "Code": "NE" }, + { "Country": "Nigeria", "Code": "NG" }, + { "Country": "North Korea", "Code": "KP" }, + { "Country": "North Macedonia", "Code": "MK" }, + { "Country": "Norway", "Code": "NO" }, + { "Country": "Oman", "Code": "OM" }, + { "Country": "Pakistan", "Code": "PK" }, + { "Country": "Palau", "Code": "PW" }, + { "Country": "Palestine State", "Code": "PS" }, + { "Country": "Panama", "Code": "PA" }, + { "Country": "Papua New Guinea", "Code": "PG" }, + { "Country": "Paraguay", "Code": "PY" }, + { "Country": "Peru", "Code": "PE" }, + { "Country": "Philippines", "Code": "PH" }, + { "Country": "Poland", "Code": "PL" }, + { "Country": "Portugal", "Code": "PT" }, + { "Country": "Qatar", "Code": "QA" }, + { "Country": "Romania", "Code": "RO" }, + { "Country": "Russia", "Code": "RU" }, + { "Country": "Rwanda", "Code": "RW" }, + { "Country": "Saint Kitts and Nevis", "Code": "KN" }, + { "Country": "Saint Lucia", "Code": "LC" }, + { "Country": "Saint Vincent and the Grenadines", "Code": "VC" }, + { "Country": "Samoa", "Code": "WS" }, + { "Country": "San Marino", "Code": "SM" }, + { "Country": "Sao Tome and Principe", "Code": "ST" }, + { "Country": "Saudi Arabia", "Code": "SA" }, + { "Country": "Senegal", "Code": "SN" }, + { "Country": "Serbia", "Code": "RS" }, + { "Country": "Seychelles", "Code": "SC" }, + { "Country": "Sierra Leone", "Code": "SL" }, + { "Country": "Singapore", "Code": "SG" }, + { "Country": "Slovakia", "Code": "SK" }, + { "Country": "Slovenia", "Code": "SI" }, + { "Country": "Solomon Islands", "Code": "SB" }, + { "Country": "Somalia", "Code": "SO" }, + { "Country": "South Africa", "Code": "ZA" }, + { "Country": "South Korea", "Code": "KR" }, + { "Country": "South Sudan", "Code": "SS" }, + { "Country": "Spain", "Code": "ES" }, + { "Country": "Sri Lanka", "Code": "LK" }, + { "Country": "Sudan", "Code": "SD" }, + { "Country": "Suriname", "Code": "SR" }, + { "Country": "Sweden", "Code": "SE" }, + { "Country": "Switzerland", "Code": "CH" }, + { "Country": "Syria", "Code": "SY" }, + { "Country": "Tajikistan", "Code": "TJ" }, + { "Country": "Tanzania", "Code": "TZ" }, + { "Country": "Thailand", "Code": "TH" }, + { "Country": "Timor-Leste", "Code": "TL" }, + { "Country": "Togo", "Code": "TG" }, + { "Country": "Tonga", "Code": "TO" }, + { "Country": "Trinidad and Tobago", "Code": "TT" }, + { "Country": "Tunisia", "Code": "TN" }, + { "Country": "Turkey", "Code": "TR" }, + { "Country": "Turkmenistan", "Code": "TM" }, + { "Country": "Tuvalu", "Code": "TV" }, + { "Country": "Uganda", "Code": "UG" }, + { "Country": "Ukraine", "Code": "UA" }, + { "Country": "United Arab Emirates", "Code": "AE" }, + { "Country": "United Kingdom", "Code": "GB" }, + { "Country": "United States of America", "Code": "US" }, + { "Country": "Uruguay", "Code": "UY" }, + { "Country": "Uzbekistan", "Code": "UZ" }, + { "Country": "Vanuatu", "Code": "VU" }, + { "Country": "Venezuela", "Code": "VE" }, + { "Country": "Vietnam", "Code": "VN" }, + { "Country": "Yemen", "Code": "YE" }, + { "Country": "Zambia", "Code": "ZM" }, + { "Country": "Zimbabwe", "Code": "ZW" } ] - \ No newline at end of file diff --git a/frontend/src/components/EditDetails.tsx b/frontend/src/components/EditDetails.tsx index 0e5f4332..e995acb4 100644 --- a/frontend/src/components/EditDetails.tsx +++ b/frontend/src/components/EditDetails.tsx @@ -4,171 +4,171 @@ import User, { FrontendUser } from "../models/User"; import { zodResolver } from "@hookform/resolvers/zod"; import { userEditDetails } from "../models/RegisterUserSchema"; import { ChangeEvent, Dispatch, SetStateAction, useState } from "react"; -import countriesData from '../assets/countries.json'; -import Select from 'react-select'; +import countriesData from "../assets/countries.json"; +import Select from "react-select"; export interface EditDetails { - user: User; - updateUser: () => Promise, - setUser: Dispatch> - } + user: User; + updateUser: () => Promise; + setUser: Dispatch>; +} function EditDetails(props: EditDetails) { - const user: User = props.user; - const updateUser = props.updateUser; - const setUser = props.setUser; - const navigate = useNavigate(); - - const { - register, - handleSubmit, - formState: { errors, isSubmitting }, - } = useForm({ - resolver: zodResolver(userEditDetails), - }); - - const [submitError, setSubmitError] = useState(""); - const [country, setCountry] = useState(user.country) - const [formData, setFormData] = useState({ - first_name: user.first_name, - last_name: user.last_name, - mail: user.mail, - country: country, - }) + const user: User = props.user; + const updateUser = props.updateUser; + const setUser = props.setUser; + const navigate = useNavigate(); + + const { + register, + handleSubmit, + formState: { errors, isSubmitting }, + } = useForm({ + resolver: zodResolver(userEditDetails), + }); + const [submitError, setSubmitError] = useState(""); + const [country, setCountry] = useState(user.country); + const [formData, setFormData] = useState({ + first_name: user.first_name, + last_name: user.last_name, + mail: user.mail, + country: country, + }); // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleCountryChange = (selection: any) => { - const selectedCountry = selection ? selection.value : ''; - - setCountry(selectedCountry); - setFormData(prevState => { - return { ...prevState, country: selectedCountry }; - }); - - }; + const selectedCountry = selection ? selection.value : ""; - const handleChange = (e: ChangeEvent) => { - console.log(e); - - const { name, value } = e.target; - setFormData(prevData => ({ - ...prevData, - [name]: value, - })); - }; - - const errorProps = { - className: "pb-4 text-[#f88]", - }; - - const inputProps = { - className: "text-my-dark form-input", - }; - - const countryOptions = countriesData.map((country) => ({ - value: country.Country, - label: country.Country, + setCountry(selectedCountry); + setFormData((prevState) => { + return { ...prevState, country: selectedCountry }; + }); + }; + + const handleChange = (e: ChangeEvent) => { + console.log(e); + + const { name, value } = e.target; + setFormData((prevData) => ({ + ...prevData, + [name]: value, })); - - const editUser = async (newUser: FrontendUser): Promise => { - const userToSave: User = { - ...user, - first_name: newUser.first_name, - last_name: newUser.last_name, - country: country, - mail: newUser.mail - } - setUser(userToSave) - - updateUser().then((updated) => { - if (updated) console.log("Updated"); - else throw new Error("Error while updating user"); - }); - + }; + + const errorProps = { + className: "pb-4 text-[#f88]", + }; + + const inputProps = { + className: "text-my-dark form-input", + }; + + const countryOptions = countriesData.map((country) => ({ + value: country.Country, + label: country.Country, + })); + + const editUser = async (newUser: FrontendUser): Promise => { + const userToSave: User = { + ...user, + first_name: newUser.first_name, + last_name: newUser.last_name, + country: country, + mail: newUser.mail, }; - - - const submit = async (user: FrontendUser) => { - try { - - await editUser(user); - - navigate("/profile"); - } catch (e) { - if (e instanceof Error) { - setSubmitError("Can't connect to the server"); - throw e; - } - - if ((e as Response).status == 400) { - setSubmitError("User already exists"); - } else { - setSubmitError("Unknown error"); - } + setUser(userToSave); + + updateUser().then((updated) => { + if (updated) console.log("Updated"); + else throw new Error("Error while updating user"); + }); + }; + + const submit = async (user: FrontendUser) => { + try { + await editUser(user); + + navigate("/profile"); + } catch (e) { + if (e instanceof Error) { + setSubmitError("Can't connect to the server"); + throw e; } - }; + if ((e as Response).status == 400) { + setSubmitError("User already exists"); + } else { + setSubmitError("Unknown error"); + } + } + }; return ( -
-

Edit Details

-
-
-
First name
- -
{errors.first_name?.message}
-
Last Name
- -
{errors.last_name?.message}
-
-
-
Country
- +
{errors.first_name?.message}
+
Last Name
+ +
{errors.last_name?.message}
+
+
+
Country
+ -
{errors.mail?.message}
+
+
E-mail
+ +
{errors.mail?.message}
-
{errors.password?.message}
-
- -
{submitError}
+
{errors.password?.message}
+
- +
{submitError}
- + +
); } diff --git a/frontend/src/components/EditPassword.tsx b/frontend/src/components/EditPassword.tsx index 8bced1cf..5c23a672 100644 --- a/frontend/src/components/EditPassword.tsx +++ b/frontend/src/components/EditPassword.tsx @@ -7,153 +7,145 @@ import { useForm } from "react-hook-form"; import { PasswordForm } from "../models/PasswordForm"; export interface EditDetails { - user: User; - logout: () => Promise - } - + user: User; + logout: () => Promise; +} function EditPassword(props: EditDetails) { + const { user, logout } = props; + const navigate = useNavigate(); + + const { + register, + handleSubmit, + formState: { errors, isSubmitting }, + } = useForm({ + resolver: zodResolver(changePasswordSchema), + }); + + const [submitError, setSubmitError] = useState(""); + const [formData, setFormData] = useState({ + old_password: "", + new_password: "", + repeat_password: "", + }); + + const handleChange = (e: ChangeEvent) => { + const { name, value } = e.target; + setFormData((prevData) => ({ + ...prevData, + [name]: value, + })); + }; - const {user, logout} = props - const navigate = useNavigate(); - - const { - register, - handleSubmit, - formState: { errors, isSubmitting }, - } = useForm({ - resolver: zodResolver(changePasswordSchema), - }); - - const [submitError, setSubmitError] = useState(""); - const [formData, setFormData] = useState({ - old_password: '', - new_password: '', - repeat_password: '' - - }) - - const handleChange = (e: ChangeEvent) => { - const { name, value } = e.target; - setFormData(prevData => ({ - ...prevData, - [name]: value, - })); - }; - - const handleLogout = async () => { - const logged_out = await logout(); - if (logged_out) { - navigate("/"); - } else { - throw new Error("Couldn't log out"); - } - }; - const errorProps = { - className: "pb-4 text-[#f88]", - }; - - const inputProps = { - className: "text-my-dark form-input", - }; - - - const editPassword = async (passwords: PasswordForm): Promise => { - if (user) { - const response = await fetch(`http://localhost:5000/users/${user.id}/change-password`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(passwords), - }); - - if (response.ok){ - return - } - throw response; + const handleLogout = async () => { + const logged_out = await logout(); + if (logged_out) { + navigate("/"); + } else { + throw new Error("Couldn't log out"); + } + }; + const errorProps = { + className: "pb-4 text-[#f88]", + }; + + const inputProps = { + className: "text-my-dark form-input", + }; + + const editPassword = async (passwords: PasswordForm): Promise => { + if (user) { + const response = await fetch( + `http://localhost:5000/users/${user.id}/change-password`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(passwords), + }, + ); + + if (response.ok) { + return; } - }; - - - const submit = async (passwords: PasswordForm) => { - - try { - await editPassword(passwords); - - handleLogout() - navigate("/login") - - - } catch (e) { - if (e instanceof Error) { - setSubmitError("Can't connect to the server"); - throw e; - } - - if ((e as Response).status == 400) { - setSubmitError("Invalid Password"); - } else { - setSubmitError("Unknown error"); - } + throw response; + } + }; + + const submit = async (passwords: PasswordForm) => { + try { + await editPassword(passwords); + + handleLogout(); + navigate("/login"); + } catch (e) { + if (e instanceof Error) { + setSubmitError("Can't connect to the server"); + throw e; + } + + if ((e as Response).status == 400) { + setSubmitError("Invalid Password"); + } else { + setSubmitError("Unknown error"); } - }; - - - return( -
-

Change Password

-
-
-
Current password
- -
{errors.old_password?.message}
- -
New password
- -
{errors.new_password?.message}
- -
Repeat new password
- -
{errors.repeat_password?.message}
- - -
{submitError}
- - -

WARNING: You will be logged out!

- -
-
- ) + } + }; + + return ( +
+

Change Password

+
+
+
Current password
+ +
{errors.old_password?.message}
+ +
New password
+ +
{errors.new_password?.message}
+ +
Repeat new password
+ +
{errors.repeat_password?.message}
+ +
{submitError}
+ + +

WARNING: You will be logged out!

+
+
+ ); } -export default EditPassword \ No newline at end of file +export default EditPassword; diff --git a/frontend/src/components/EditPhoto.tsx b/frontend/src/components/EditPhoto.tsx index bac64b32..e65738ea 100644 --- a/frontend/src/components/EditPhoto.tsx +++ b/frontend/src/components/EditPhoto.tsx @@ -3,119 +3,119 @@ import User from "../models/User"; import { Dispatch, SetStateAction, useState } from "react"; export interface EditDetails { - user: User; - updateUser: () => Promise, - setUser: Dispatch> - } + user: User; + updateUser: () => Promise; + setUser: Dispatch>; +} function EditPhoto(props: EditDetails) { - const user: User = props.user; - const updateUser = props.updateUser; - const setUser = props.setUser; - - const navigate = useNavigate(); - - const [profilePictureBase64, setProfilePictureBase64] = useState(user.profile_picture); - const [submitError, setSubmitError] = useState(""); - - const encodePicture = async (file: File): Promise => { - return new Promise((resolve) => { - const reader = new FileReader(); - reader.onloadend = () => { - const base64 = reader.result as string; - // console.log(base64.slice(0,40)); - - setProfilePictureBase64(base64); - resolve(base64); - }; - reader.readAsDataURL(file); - }); - }; - - const handleFileChange = (e: React.ChangeEvent) => { - const file = e.target.files?.[0]; - if (file) { - encodePicture(file); - } + const user: User = props.user; + const updateUser = props.updateUser; + const setUser = props.setUser; + + const navigate = useNavigate(); + + const [profilePictureBase64, setProfilePictureBase64] = useState( + user.profile_picture, + ); + const [submitError, setSubmitError] = useState(""); + + const encodePicture = async (file: File): Promise => { + return new Promise((resolve) => { + const reader = new FileReader(); + reader.onloadend = () => { + const base64 = reader.result as string; + // console.log(base64.slice(0,40)); + + setProfilePictureBase64(base64); + resolve(base64); }; + reader.readAsDataURL(file); + }); + }; + + const handleFileChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + encodePicture(file); + } + }; - const inputProps = { - className: "text-my-dark form-input", - }; - - const editPhoto = async (): Promise => { - user.profile_picture = profilePictureBase64 - // console.log(user); - setUser(user) - - updateUser().then((updated) => { - if (updated) console.log("Updated"); - else throw new Error("Error while updating user"); - }); - - }; - - - const submit = async () => { - try { - const changedUser = await editPhoto(); - - console.log(changedUser); - navigate("/profile"); - } catch (e) { - if (e instanceof Error) { - setSubmitError("Can't connect to the server"); - throw e; - } - - if ((e as Response).status == 400) { - setSubmitError("User already exists"); - } else { - setSubmitError("Unknown error"); - } + const inputProps = { + className: "text-my-dark form-input", + }; + + const editPhoto = async (): Promise => { + user.profile_picture = profilePictureBase64; + // console.log(user); + setUser(user); + + updateUser().then((updated) => { + if (updated) console.log("Updated"); + else throw new Error("Error while updating user"); + }); + }; + + const submit = async () => { + try { + const changedUser = await editPhoto(); + + console.log(changedUser); + navigate("/profile"); + } catch (e) { + if (e instanceof Error) { + setSubmitError("Can't connect to the server"); + throw e; } - }; + if ((e as Response).status == 400) { + setSubmitError("User already exists"); + } else { + setSubmitError("Unknown error"); + } + } + }; return ( -
-

Change Photo

-
-
+

Change Photo

+
+
+
+ - -
- - - {profilePictureBase64 && ( - Profile - )} -
- -
{submitError}
+ {profilePictureBase64 && ( + Profile + )} +
+ +
{submitError}
-
); } diff --git a/frontend/src/components/Profile.tsx b/frontend/src/components/Profile.tsx index 977bd6bb..415dc662 100644 --- a/frontend/src/components/Profile.tsx +++ b/frontend/src/components/Profile.tsx @@ -11,11 +11,7 @@ export interface ProfilePageFormProps { function Profile(props: ProfilePageFormProps) { const [showDeleteModal, setShowDeleteModal] = useState(false); - const { - user, - handleEditClick, - deleteUser, - } = props; + const { user, handleEditClick, deleteUser } = props; return (
@@ -33,19 +29,14 @@ function Profile(props: ProfilePageFormProps) {

Name: {user.first_name || ""} {user.last_name || ""}

-

- Country: {user.country || ""} -

-

- E-mail: {user.mail || ""} -

+

Country: {user.country || ""}

+

E-mail: {user.mail || ""}

- - - + +
{errors.country?.message}
diff --git a/frontend/src/components/Transition.tsx b/frontend/src/components/Transition.tsx index 1507f123..500e0540 100644 --- a/frontend/src/components/Transition.tsx +++ b/frontend/src/components/Transition.tsx @@ -9,7 +9,6 @@ const Transition: React.FC = ({ startAnimation }) => { const controls = useAnimation(); const animateSquare = async () => { - await controls.start({ y: 0, opacity: 1 }); await new Promise((resolve) => setTimeout(resolve, 1)); @@ -20,7 +19,6 @@ const Transition: React.FC = ({ startAnimation }) => { }; useEffect(() => { - if (startAnimation) { animateSquare(); } diff --git a/frontend/src/models/PasswordForm.ts b/frontend/src/models/PasswordForm.ts index 943da264..125808be 100644 --- a/frontend/src/models/PasswordForm.ts +++ b/frontend/src/models/PasswordForm.ts @@ -1,5 +1,5 @@ -export interface PasswordForm{ - old_password: string, - new_password: string, - repeat_password: string -} \ No newline at end of file +export interface PasswordForm { + old_password: string; + new_password: string; + repeat_password: string; +} diff --git a/frontend/src/models/RegisterUserSchema.ts b/frontend/src/models/RegisterUserSchema.ts index 6e3c9d21..bc523890 100644 --- a/frontend/src/models/RegisterUserSchema.ts +++ b/frontend/src/models/RegisterUserSchema.ts @@ -28,20 +28,20 @@ export const userEditDetails: z.ZodType> = z.object({ .min(2, "Last name should be at least two characters long"), // country: z // .string().min(1), - mail: z.string().email() -}) - -export const changePasswordSchema: z.ZodType = z.object({ - old_password: z - .string() - .min(8, "Password should be at least eight characters long"), - new_password: z - .string() - .min(8, "Password should be at least eight characters long"), - repeat_password: z - .string() -}).refine((data) => data.new_password === data.repeat_password, { - message: "Passwords must match!", - path: ["repeat_password"], -}) + mail: z.string().email(), +}); +export const changePasswordSchema: z.ZodType = z + .object({ + old_password: z + .string() + .min(8, "Password should be at least eight characters long"), + new_password: z + .string() + .min(8, "Password should be at least eight characters long"), + repeat_password: z.string(), + }) + .refine((data) => data.new_password === data.repeat_password, { + message: "Passwords must match!", + path: ["repeat_password"], + }); diff --git a/frontend/src/pages/EditDataPage.tsx b/frontend/src/pages/EditDataPage.tsx index 640f89cb..42755ed7 100644 --- a/frontend/src/pages/EditDataPage.tsx +++ b/frontend/src/pages/EditDataPage.tsx @@ -8,37 +8,42 @@ import EditPhoto from "../components/EditPhoto"; import EditPassword from "../components/EditPassword"; function EditDataPage() { - const {user, updateUser, setUser, logout} = useUser(); - const [showAnimation, setShowAnim] = useState(false); - const [showContent, setShowContent] = useState(false); + const { user, updateUser, setUser, logout } = useUser(); + const [showAnimation, setShowAnim] = useState(false); + const [showContent, setShowContent] = useState(false); - useEffect(() => { - setShowAnim(true); - setTimeout(() => { - setShowContent(true); - }, 100); - }, []); + useEffect(() => { + setShowAnim(true); + setTimeout(() => { + setShowContent(true); + }, 100); + }, []); return ( <> - - {showAnimation && } - {user && showContent ? ( - <> -
- - - -
- + + {showAnimation && } + {user && showContent ? ( + <> +
+ + + +
- ) : ( -
Loading...
- )} - {showContent &&