<?php

/**
 * Created by PhpStorm.
 * User: sean
 * Date: 10/29/17
 * Time: 6:59 PM
 */
class SecureLoginController
{
    public function __construct($get, $post, $logins)
    {

        $this->get = $get;
        $this->post = $post;
        $this->logins = $logins;

        if(isset($post['username'])){
            $username = $post['username'];
            if(array_key_exists($username,$logins)){
                if(isset($post['password'])) {
                    $hash = hash("sha256", $post['password']);
                    if ($hash == $logins[$username]) {
                        $this->success = true;
                        $this->redirect = "secure/minutes.php";
                    }
                    else{
                        $this->redirect = "secure/index.php";
                    }
                }
                else{
                    $this->redirect = "secure/index.php";
                }

            }
            else{
                $this->redirect = "secure/index.php";
            }
        }
        else{
            $this->redirect = "secure/index.php";
        }

    }

    public function getRedirect(){
        return $this->redirect;
    }

    public function validLogin(){
        return $this->success;
    }

    private $get; //Get data
    private $post; //Post data
    private $logins; //Login data
    private $success = false; // successful login flag
    private $redirect; //Redirect location
}