<?php
 session_start();
require_once "SystemController/DbConnection.php";

$msg = "";
$username = "";

if(isset($_SESSION['id'])){
    header("location: dashboard/index.php");
}

if($_SERVER['REQUEST_METHOD'] == "POST"){

    
    $db_handle= new DbConnection();
    
$username = $db_handle->sanitize($_POST['email']);
$upass = $db_handle->sanitize($_POST['password']);
   
$conn = mysqli_connect('localhost','spcxinvs_com','spcxinvs_com','spcxinvs_com');

     $sql = "select * from members where email  = '$username' OR username = '$username' and password = '$upass'";
    
   // $sql = "select * from members where email OR username = '$username' and password = '$upass'";
    $query = mysqli_query($conn, $sql);

        
        $row = mysqli_fetch_array($query, MYSQLI_ASSOC);
        
        $count = mysqli_num_rows($query);
        
        if($count == 1){
            
        $_SESSION['userID'] = $row["id"];
        $_SESSION['msg'] = "";
        
        $verified = $row['verified'];
$id = $row['id'];
$username = $row['username'];
//3.1.2 If the posted values are equal to the database values, then session will be created for the user.

        
        $_SESSION['username'] = $id;
$_SESSION['id'] = $id;
$_SESSION['verified'] = $verified;
   // Redirect user to index.php
        header("Location: dashboard/index.php");
        
        
        
         
        }else{
            $msg = '<div class="alert alert-danger mx-auto"><i class="fa fa-info-circle"></i>Email or Password is incorrect.</div>';
        
       
}
}



?>
<!DOCTYPE html>
<html lang="en">


<head>

    <meta charset="utf-8" />
    <title>SpaceX Tesla Investments Trades </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <!-- Favicon -->
    <link rel="shortcut icon" href="assets/img/favicon.png">

    <!-- Template CSS Files -->
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/magnific-popup.css">
    <link rel="stylesheet" href="css/select2.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/skins/orange.css">

    <!-- Live Style Switcher - demo only 
    <link rel="alternate stylesheet" type="text/css" title="orange" href="css/skins/orange.css" />
    <link rel="alternate stylesheet" type="text/css" title="green" href="css/skins/green.css" />
    <link rel="alternate stylesheet" type="text/css" title="blue" href="css/skins/blue.css" />-->
    <link rel="stylesheet" type="text/css" href="css/styleswitcher.css" />

    <!-- Template JS Files -->
    <script src="js/modernizr.js"></script>

</head>

<script src="//code.jivosite.com/widget/pfNW6yUA29" async></script>
<!-- /GetButton.io widget -->


<body>

	 <!-- SVG Preloader Starts -->
 <div id="preloader">
    <div id="preloader-content">
       <!-- <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="150px" height="150px" viewBox="100 100 400 400" xml:space="preserve">
          <filter id="dropshadow" height="130%">
             <feGaussianBlur in="SourceAlpha" stdDeviation="5" />
             <feOffset dx="0" dy="0" result="offsetblur" />
             <feFlood flood-color="red" />
             <feComposite in2="offsetblur" operator="in" />
             <feMerge>
                <feMergeNode />
                <feMergeNode in="SourceGraphic" />
             </feMerge>
          </filter>
          <path class="path" fill="#000000" d="M446.089,261.45c6.135-41.001-25.084-63.033-67.769-77.735l13.844-55.532l-33.801-8.424l-13.48,54.068
                    c-8.896-2.217-18.015-4.304-27.091-6.371l13.568-54.429l-33.776-8.424l-13.861,55.521c-7.354-1.676-14.575-3.328-21.587-5.073
                    l0.034-0.171l-46.617-11.64l-8.993,36.102c0,0,25.08,5.746,24.549,6.105c13.689,3.42,16.159,12.478,15.75,19.658L208.93,357.23
                    c-1.675,4.158-5.925,10.401-15.494,8.031c0.338,0.485-24.579-6.134-24.579-6.134l-9.631,40.468l36.843,9.188
                    c8.178,2.051,16.209,4.19,24.098,6.217l-13.978,56.17l33.764,8.424l13.852-55.571c9.235,2.499,18.186,4.813,26.948,6.995
                    l-13.802,55.309l33.801,8.424l13.994-56.061c57.648,10.902,100.998,6.502,119.237-45.627c14.705-41.979-0.731-66.193-31.06-81.984
                    C425.008,305.984,441.655,291.455,446.089,261.45z M368.859,369.754c-10.455,41.983-81.128,19.285-104.052,13.589l18.562-74.404
                    C306.28,314.65,379.774,325.975,368.859,369.754z M379.302,260.846c-9.527,38.187-68.358,18.781-87.442,14.023l16.828-67.489
                    C327.767,212.14,389.234,221.02,379.302,260.846z" />



       </svg> -->
       <img id="logo" class="img-responsive" src="images/pionex_logo.png" alt="logo" width="">
    </div>
 </div>
 
 <!-- <div id="showSwitcher" class="styleSecondColor"><i class="fa fa-cog fa-spin"></i></div> -->
 <!-- Live Style Switcher Ends - demo only -->	<!-- Wrapper Starts -->
	<div class="wrapper">
		<!-- Header Starts -->
		
		<div class="container-fluid user-auth">
			<div class="hidden-xs col-sm-4 col-md-4 col-lg-4">
				<!-- Logo Starts -->
				<a class="logo" href="../index.html">
					<img id="logo-user" class="img-responsive" src="images/pionex_logo.png" alt="logo">
				</a>
				<!-- Logo Ends -->
				
			</div>
			<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8">
				<!-- Logo Starts -->
				<a class="visible-xs" href="../index.html">
					<img id="logo" class="img-responsive mobile-logo" src="images/pionex_logo.png" alt="logo" width="120">
				</a>
				<!-- Logo Ends -->
				<div class="form-container">
					<div><center>
						<!-- Section Title Starts -->
						<div class="row text-center">
															<h2 class="title-head hidden-xs">member <span>login</span></h2>
								<p class="p-1 m-0 font-ubuntu text-black-50">Login and enjoy additional features</p>
								<br>
								<!-- <span class="font-ubuntu text-black-50">Create a new <a href="signup.php">account</a></span> -->
							
						</div>
						<!-- Section Title Ends -->
						<!-- Form Starts -->
						<form method="post">

							<?php echo $msg; ?>
							<!-- Input Field Starts -->
							<div class="form-group">
								<input name="email" class="form-control" value="" type="text" placeholder="Your E-mail or Username" required />
							</div>
							<!-- Input Field Ends -->
							<!-- Input Field Starts -->
							<div class="form-group">
								<input name="password" class="form-control" value="" type="password" placeholder="Your password" required />
							</div>
							<!-- Input Field Ends -->
							<!-- Submit Form Button Starts -->
							<b style="font-size:14px;">								</b><br>

							<div class="form-group">
								<button class="btn btn-primary" name="login_frm_btn" type="submit">login</button>
								<p class="text-center">don't have an account ? <a href="signup.php">register now</a>
								<p class="text-center">Don't remember my password ? <a href="recover-password.php">Recover now</a>
							</div>
							</center>
							<!-- Submit Form Button Ends -->
						</form>
						<!-- Form Ends -->
					</div>
				</div>
				<!-- Copyright Text Starts -->
				<!-- <p class="text-center copyright-text"><a href="templateshub.net">Templates Hub</a></p> -->
				<!-- Copyright Text Ends -->
			</div>
		</div>
		<!-- Template JS Files -->
		<script src="js/jquery-2.2.4.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/select2.min.js"></script>
		<script src="js/jquery.magnific-popup.min.js"></script>
		<script src="js/custom.js"></script>

		<!-- Live Style Switcher JS File - only demo -->
		<script src="js/styleswitcher.js"></script>

	</div>
	<!-- Wrapper Ends -->
</body>

</html>