mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2024-11-16 22:29:24 +08:00
Added email validation to see if email exists on register page
This commit is contained in:
parent
8fdb589e67
commit
9b29f050b6
2 changed files with 30 additions and 8 deletions
|
@ -206,3 +206,19 @@ export async function CheckSavedSession() {
|
||||||
console.log("No previous session found");
|
console.log("No previous session found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function VerifyEmail(email: string) {
|
||||||
|
return axios
|
||||||
|
.get(
|
||||||
|
"https://emailvalidation.abstractapi.com/v1/?api_key=d7abfb5f41b7476faaebe37ceba8ae37&email=" +
|
||||||
|
email
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
console.log("Email valid?" + response.data);
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Email valid?" + error);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Button } from "@mui/material";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { UserRegister } from "../../Components/Api/Api";
|
import { UserRegister, VerifyEmail } from "../../Components/Api/Api";
|
||||||
export default function Register() {
|
export default function Register() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
@ -65,18 +65,24 @@ export default function Register() {
|
||||||
style={styles.login_button}
|
style={styles.login_button}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
console.log("Email valid?" + (await VerifyEmail(user.email)));
|
||||||
|
if (await VerifyEmail(user.email)) {
|
||||||
|
if (await UserRegister(user)) {
|
||||||
|
setFeedback(
|
||||||
|
"Registration success. Please check your email address for activation"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setFeedback("Invalid credentials specified");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setFeedback("Email does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
setUser({
|
setUser({
|
||||||
email: "",
|
email: "",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
});
|
});
|
||||||
if (await UserRegister(user)) {
|
|
||||||
setFeedback(
|
|
||||||
"Registration success. Please check your email address for activation"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setFeedback("Invalid credentials specified");
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Register
|
Register
|
||||||
|
|
Loading…
Reference in a new issue