Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/pages/
Upload File :
Current File : /home/emeraadmin/public_html/pages/login.php

<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Login | Emera Facility Services</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="icon" href="../cropped-emera-holdings-favicon-1-32x32.png" type="image/x-icon" />
    <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
    <link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../node_modules/@fortawesome/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="../node_modules/ionicons/dist/css/ionicons.min.css">
    <link rel="stylesheet" href="../node_modules/icon-kit/dist/css/iconkit.min.css">
    <link rel="stylesheet" href="../node_modules/perfect-scrollbar/css/perfect-scrollbar.css">
    <link rel="stylesheet" href="../dist/css/theme.min.css">
    <script src="../src/js/vendor/modernizr-2.8.3.min.js"></script>
</head>

<body>


<div class="auth-wrapper">
    <div class="container-fluid h-100">
        <div class="row flex-row h-100 bg-white">
            <div class="col-xl-4 col-lg-6 col-md-5 p-0 d-md-block d-lg-block d-sm-none d-none">
<!--                <div class="lavalite-bg" style="background-image: url(../src/img/cover.jpg)"></div>-->
            </div>
            <div class="col-xl-4 col-lg-12 col-md-7 my-auto p-0">
                <div class="authentication-form mx-auto">
                    <div class="logo-centered">
                        <a href="login.php"> <img src="https://localhost/emera/img/emera.png" alt="" class="center-image"></a>
                    </div>

                    <div class="text-center my-4">
                        <img src="../src/img/Emera-Primary-Logo.png" alt="Emera Logo" class="img-fluid" style="height: 100px;">
                    </div>
                    <p>Happy to see you again!</p>
                    <form method="post" name="login" id="login">
                        <div class="form-group">
                            <input type="text" class="form-control" name="email" placeholder="Email" required>
                            <i class="ik ik-user"></i>
                        </div>
                        <div class="form-group">
                            <input type="password" class="form-control" name="password" placeholder="Password" required>
                            <i class="ik ik-lock"></i>
                        </div>
                        <div class="row">
                            <div class="col text-left">
                                <label class="custom-control custom-checkbox">
<!--                                    <input type="checkbox" class="custom-control-input" id="item_checkbox" name="item_checkbox" value="option1">-->
<!--                                    <span class="custom-control-label">&nbsp;Remember Me</span>-->
                                </label>
                            </div>
                            <div class="col text-right">
                                <a href="forgot-password.html">Forgot Password?</a>
                            </div>
                        </div>
                        <div class="sign-btn text-center">
                            <button class="btn btn-theme" type="submit">Sign In</button>
                        </div>
                        <div id="login-error" class="alert alert-danger d-none mt-3"></div>
                    </form>
                    <div class="register">
<!--                        <p>Don't have an account? <a href="register.html">Create an account</a></p>-->
                    </div>
                    <?php if (isset($error)) { echo "<div class='alert alert-danger'>$error</div>"; } ?>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>window.jQuery || document.write('<script src="../src/js/vendor/jquery-3.3.1.min.js"><\/script>')</script>

<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
<script src="../dist/js/theme.js"></script>

<script>
    $(document).ready(function(){
        $("#login").submit(function(e){
            e.preventDefault();
            var email = $("input[name='email']").val();
            var password = $("input[name='password']").val();

            $.ajax({
                url: 'authenticateuser.php',
                type: 'POST',
                data: {email: email, password: password},
                success: function(response){
                    if (response.includes("Authenticated")) {
                        Swal.fire({
                            title: 'Success!',
                            text: 'You have successfully logged in',
                            icon: 'success',
                            confirmButtonText: 'Ok'
                        }).then(() => {
                            window.location.href = determineDashboard(response);
                        });
                    } else {
                        Swal.fire({
                            title: 'Error!',
                            text: response,
                            icon: 'error',
                            confirmButtonText: 'Ok'
                        });
                    }
                },
                error: function(){
                    $("#login-error").text("An error occurred during login. Please try again.").removeClass("d-none");
                }
            });
        });

        function determineDashboard(response) {
            if (response.includes("emera_admin")) {
                return "emeraadmin/dashboard.php";
            } else if (response.includes("subcontractor")) {
                return "subcontractor/dashboard.php";
            }
            else if (response.includes("task_provider")) {
                return "taskprovider/dashboard.php";
            }
            else {
                Swal.fire({
                    title: 'We Couldn\'t Determine Your Role',
                    text: 'Please contact the system administrator',
                    icon: 'error',
                    confirmButtonText: 'Ok'
                });
                // Redirect to a default page or handle as needed
                return "index.php"; // Example redirect
            }
        }
    });


</script>

</body>
</html>