ENCOA-279

This commit is contained in:
Tiago Ribeiro
2024-12-12 15:06:00 +00:00
parent 3e74827c47
commit 240e36f15a
11 changed files with 71 additions and 73 deletions

View File

@@ -64,7 +64,7 @@ export default function Reset({code, mode, continueUrl}: {code: string; mode: st
}); });
setTimeout(() => { setTimeout(() => {
router.push("/"); router.push("/");
}, 1000); }, 500);
return; return;
} }

View File

@@ -73,9 +73,8 @@ async function registerIndividual(req: NextApiRequest, res: NextApiResponse) {
...(passport_id ? { demographicInformation: { passport_id } } : {}), ...(passport_id ? { demographicInformation: { passport_id } } : {}),
registrationDate: new Date().toISOString(), registrationDate: new Date().toISOString(),
status: code ? "active" : "paymentDue", status: code ? "active" : "paymentDue",
// apparently there's an issue with the verification email system entities: [],
// therefore we will skip this requirement for now isVerified: !!codeDoc,
isVerified: true,
}; };
await db.collection("users").insertOne(user); await db.collection("users").insertOne(user);

View File

@@ -47,7 +47,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer"])) return redirect("/") if (!checkAccess(user, ["admin", "developer"])) return redirect("/")

View File

@@ -46,7 +46,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "corporate"])) return redirect("/") if (!checkAccess(user, ["admin", "developer", "corporate"])) return redirect("/")

View File

@@ -47,7 +47,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer"])) return redirect("/") if (!checkAccess(user, ["admin", "developer"])) return redirect("/")

View File

@@ -6,7 +6,7 @@ import {withIronSessionSsr} from "iron-session/next";
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
return redirect(`/dashboard/${user.type}`) return redirect(`/dashboard/${user.type}`)
}, sessionOptions); }, sessionOptions);

View File

@@ -52,7 +52,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "mastercorporate"])) if (!checkAccess(user, ["admin", "developer", "mastercorporate"]))
return redirect("/") return redirect("/")

View File

@@ -51,7 +51,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "student"])) if (!checkAccess(user, ["admin", "developer", "student"]))
return redirect("/") return redirect("/")
@@ -90,11 +90,13 @@ export default function Dashboard({user, entities, assignments, stats, invites,
}) })
if (assignmentExams.every((x) => !!x)) { if (assignmentExams.every((x) => !!x)) {
dispatch({type: "INIT_EXAM", payload: { dispatch({
type: "INIT_EXAM", payload: {
exams: assignmentExams.sort(sortByModule), exams: assignmentExams.sort(sortByModule),
modules: mapBy(assignmentExams.sort(sortByModule), 'module'), modules: mapBy(assignmentExams.sort(sortByModule), 'module'),
assignment assignment
}}) }
})
router.push("/exam"); router.push("/exam");
} }

View File

@@ -39,7 +39,7 @@ interface Props {
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
if (!checkAccess(user, ["admin", "developer", "teacher"])) if (!checkAccess(user, ["admin", "developer", "teacher"]))
return redirect("/") return redirect("/")

View File

@@ -6,7 +6,7 @@ import {withIronSessionSsr} from "iron-session/next";
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (!user) return redirect("/login") if (!user || !user.isVerified) return redirect("/login")
return redirect(`/dashboard/${user.type}`) return redirect(`/dashboard/${user.type}`)
}, sessionOptions); }, sessionOptions);

View File

@@ -23,7 +23,7 @@ const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => { export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString() const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString()
const user = await requestUser(req, res) const user = await requestUser(req, res)
if (user) return redirect(destination) if (user && user.isVerified) return redirect(destination)
return { return {
props: { user: null, destination }, props: { user: null, destination },
@@ -39,13 +39,10 @@ export default function Login({ destination = "/" }: { destination?: string }) {
const router = useRouter(); const router = useRouter();
const isOfficialExamLogin = useMemo(() => destination.startsWith("/official-exam"), [destination]) const isOfficialExamLogin = useMemo(() => destination.startsWith("/official-exam"), [destination])
const { user, mutateUser } = useUser({ const { user, mutateUser } = useUser();
redirectTo: destination,
redirectIfFound: true,
});
useEffect(() => { useEffect(() => {
if (user) router.push(destination); if (user && user.isVerified) router.push(destination);
}, [router, user, destination]); }, [router, user, destination]);
const forgotPassword = () => { const forgotPassword = () => {
@@ -173,7 +170,7 @@ export default function Login({ destination = "/" }: { destination?: string }) {
</span> </span>
</> </>
)} )}
{/* {user && !user.isVerified && <EmailVerification user={user} isLoading={isLoading} setIsLoading={setIsLoading} />} */} {user && !user.isVerified && <EmailVerification user={user} isLoading={isLoading} setIsLoading={setIsLoading} />}
</section> </section>
</main> </main>
</> </>