From 462ec66a26ab87e068159f8f66a29510932f9261 Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Sun, 9 Feb 2025 14:04:38 +0800 Subject: [PATCH] auto login after signup --- .../src/components/SignupView.tsx | 26 +++++++++++++++---- AceJobAgency.client/src/pages/MemberPage.tsx | 4 ++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/AceJobAgency.client/src/components/SignupView.tsx b/AceJobAgency.client/src/components/SignupView.tsx index 57552e1..0ef944f 100644 --- a/AceJobAgency.client/src/components/SignupView.tsx +++ b/AceJobAgency.client/src/components/SignupView.tsx @@ -2,7 +2,7 @@ import { Input, Button, Link, Select, SelectItem } from "@heroui/react"; import { IconMail, IconLock } from "@tabler/icons-react"; import { useState } from "react"; import { toast } from "react-toastify"; -import http from "../http"; +import http, { login } from "../http"; export default function SignupView({ onLogin, @@ -19,10 +19,11 @@ export default function SignupView({ const [dateOfBirth, setDateOfBirth] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); + const [signupEnabled, setSignupEnabled] = useState(true); const validatePassword = (password: string): boolean => { const passwordComplexityRegex = - /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$/; + /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d])[A-Za-z\d@$!%*?&\\]{12,}$/; return passwordComplexityRegex.test(password); }; @@ -74,9 +75,19 @@ export default function SignupView({ if (response.status !== 200) { throw new Error("Failed to sign up"); } - + setSignupEnabled(false); toast.success("Welcome to Ace Job, " + firstName + "!", { - onClose: onLogin, + onClose: () => { + http + .post("/User/login", { email: emailValue, password: password }) + .then((response) => { + if (response.status === 200) { + login(response.data.token); + } else { + toast.error("Failed to login"); + } + }); + }, }); } catch (error) { toast.error((error as any).response?.data || "Error during signup"); @@ -144,7 +155,12 @@ export default function SignupView({ />
-
diff --git a/AceJobAgency.client/src/pages/MemberPage.tsx b/AceJobAgency.client/src/pages/MemberPage.tsx index a991b5d..0eef687 100644 --- a/AceJobAgency.client/src/pages/MemberPage.tsx +++ b/AceJobAgency.client/src/pages/MemberPage.tsx @@ -147,7 +147,9 @@ export default function MemberPage() { {userProfile.whoAmI} ) : ( - "You have not wrote anything about yourself." +

+ You have not wrote anything about yourself. +

)}