<!-- Realisatsiooni aluseks on võetud:
Login Registration with Email Verification, Forgot Password using PHP
Kasutatud 6.04.2016
http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html
-->

<?php
include "config.php";
session_start();
include_once ROOT . 'db/dbconfig.php';
require_once ROOT . 'admin/objects/kasutaja.class.php';
$user_home = new Kasutaja();

if($user_home->is_logged_in()!="")
{
    $user_home->redirect('../index.php');
}

if(isset($_POST['btn-login']))
{
    $email = trim($_POST['email']);
    $parool = trim($_POST['parool']);
    
    if($user_home->login($email,$parool))
    {
        $user_home->redirect('../index.php');
    }
}

include ROOT . "header.php";
?>

  <div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
         <form class="form-signin" method="post">

            <h2>Logi sisse</h2>
            <hr />
                <?php 
        if(isset($_GET['inactive']))
        {
            ?>
            <div class='alert alert-danger'>
                <button class='close' data-dismiss='alert'>&times;</button>
                Kasutaja ei ole aktiivne. Palun aktiveeri kasutaja läbi saadetud e-maili. 
            </div>
            <?php
        }

        if(isset($_GET['error']))
        {
            ?>
            <div class='alert alert-danger'>
                <button class='close' data-dismiss='alert'>&times;</button>
                <strong>Vale e-mail või parool!</strong> 
            </div>
            <?php
        }

            if(isset($msg)){
             echo $msg;
         }
         ?>

         <div class="form-group">
                 <label>E-mail:</label>
                 <input type="email" class="form-control" placeholder="E-mail" name="email" required  />
</div>
         <div class="form-group">
                <label>Parool:</label>
                <input type="password" class="form-control" placeholder="Parool" name="parool" required  />
            </div>

        <div class="form-group">
            <center>             
                <button type="submit" class="btn btn-default" name="btn-login">
                  <span class="glyphicon glyphicon-log-in"></span> &nbsp; Logi sisse
              </button> 
              <a href="signup.php" class="btn btn-default">Registreeru kasutajaks</a>
          </center>
      </div> 

  </form>
<hr />
<center>
        <a href="fpass.php">Unustasid salasõna? </a>
</center>
</div>

</div>
<?php
include ROOT . "footer.php";
?>
