family login implemented
This commit was merged in pull request #89.
This commit is contained in:
@@ -52,49 +52,58 @@ export default function Login() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const userApi = new usersService();
|
const userApi = new usersService();
|
||||||
|
|
||||||
const doLogin = async () => {
|
// FUNCTION TO HANDLE USER LOGIN
|
||||||
try {
|
const doLogin = ({target:{name}}) => {
|
||||||
if (email !== "" && password !== "") {
|
setLoginLoading(true);
|
||||||
var postData = {
|
let postData = {}; // Post Data for API
|
||||||
username: email,
|
if(!email || !password){
|
||||||
password: password,
|
setLoginLoading(false);
|
||||||
sessionid: "STARTING",
|
setMsgError("Please fill in the fields");
|
||||||
};
|
return
|
||||||
const loginResult = await userApi.logInUser(postData); // just for a test
|
}
|
||||||
//debugger;
|
|
||||||
// if (email === "support@mermsemr.com") {
|
if(name == 'userlogin'){ // Post Data Info for normal Login
|
||||||
if (
|
postData = {
|
||||||
loginResult.data.status > 0 &&
|
username: email,
|
||||||
loginResult.data.internal_return == 100 &&
|
password: password,
|
||||||
loginResult.data.session != ""
|
sessionid: "STARTING",
|
||||||
) {
|
};
|
||||||
// just for a start
|
}else{
|
||||||
localStorage.setItem("member_id", `${loginResult.data.member_id}`);
|
postData = { // Post Data Info for family Login
|
||||||
localStorage.setItem("uid", `${loginResult.data.uid}`);
|
username: email,
|
||||||
localStorage.setItem("session_token", `${loginResult.data.session}`);
|
pin: password,
|
||||||
localStorage.setItem("session", `${loginResult.data.session}`);
|
sessionid: "20067A92714",
|
||||||
setLoginLoading(true);
|
login_mode: 1105,
|
||||||
// userApi.getUserReminders(); //testing
|
action: 11025
|
||||||
dispatch(updateUserDetails(loginResult.data));
|
};
|
||||||
setTimeout(() => {
|
}
|
||||||
navigate("/", { replace: true });
|
|
||||||
setLoginLoading(false);
|
userApi.logInUser(postData).then((res)=>{
|
||||||
}, 2000);
|
if(res.status != 200 || res.data.internal_return < 0){
|
||||||
} else {
|
// setMsgError("Wrong, email/password");
|
||||||
// toast.error("Invalid Credential");
|
setLoginError(true);
|
||||||
setLoginError(true);
|
setLoginLoading(false);
|
||||||
}
|
return
|
||||||
} else {
|
|
||||||
setMsgError("Please fill in the fields");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
localStorage.setItem("member_id", `${res.data.member_id}`);
|
||||||
setMsgError("An error occurred");
|
localStorage.setItem("uid", `${res.data.uid}`);
|
||||||
} finally {
|
localStorage.setItem("session_token", `${res.data.session}`);
|
||||||
|
// localStorage.setItem("session", `${res.data.session}`);
|
||||||
|
dispatch(updateUserDetails(res.data));
|
||||||
|
setTimeout(() => {
|
||||||
|
navigate("/", { replace: true });
|
||||||
|
setLoginLoading(false);
|
||||||
|
}, 2000);
|
||||||
|
}).catch(error => {
|
||||||
|
setMsgError("Unable to login, try again");
|
||||||
|
setLoginLoading(false);
|
||||||
|
}).finally(()=>{
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setLoginError(false);
|
setLoginError(false);
|
||||||
setMsgError(null);
|
setMsgError(null);
|
||||||
|
setLoginLoading(false);
|
||||||
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
|
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
|
||||||
}
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -197,8 +206,10 @@ export default function Login() {
|
|||||||
<div className="signin-area mb-3.5">
|
<div className="signin-area mb-3.5">
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<button
|
<button
|
||||||
|
name='userlogin'
|
||||||
onClick={doLogin}
|
onClick={doLogin}
|
||||||
type="button"
|
type="button"
|
||||||
|
disabled={loginLoading}
|
||||||
className={`btn-login rounded-[0.475rem] mb-6 text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
|
className={`btn-login rounded-[0.475rem] mb-6 text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
|
||||||
>
|
>
|
||||||
{loginLoading ? (
|
{loginLoading ? (
|
||||||
@@ -265,7 +276,9 @@ export default function Login() {
|
|||||||
<div className="signin-area mb-1.5">
|
<div className="signin-area mb-1.5">
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<button
|
<button
|
||||||
onClick={()=>{console.log('working')}}
|
name='familylogin'
|
||||||
|
onClick={doLogin}
|
||||||
|
disabled={loginLoading}
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn-login rounded-[0.475rem] text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
|
className={`btn-login rounded-[0.475rem] text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ export default function Layout({ children }) {
|
|||||||
};
|
};
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const logOut = () => {
|
const logOut = () => {
|
||||||
localStorage.removeItem("email");
|
localStorage.removeItem("session_token");
|
||||||
localStorage.clear();
|
localStorage.removeItem("member_id");
|
||||||
|
localStorage.removeItem("uid");
|
||||||
|
// localStorage.clear();
|
||||||
// toast.success("Come Back Soon", {
|
// toast.success("Come Back Soon", {
|
||||||
// icon: `🙂`,
|
// icon: `🙂`,
|
||||||
// });
|
// });
|
||||||
|
|||||||
Reference in New Issue
Block a user