<?php

include_once 'includes/users/Member.inc.php';
include_once 'includes/users/MemberLister.inc.php';

/**
 * This class is responsible for the login and logout tasks.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class Login {

    public static function authentificate($login, $password) {

        $_SESSION['username'] = $login;
        $_SESSION['loggedin'] = false;
        
        $result = Localization::wrongUser;

        $user = MemberLister::getByLogin($login);
        if ($user AND $user->checkPassword($password)) {
            $result = Localization::loginOk;
            $_SESSION['loggedin'] = true;
        } else {
            unset($_SESSION['loggedin']);
            unset($_SESSION['username']);
        }
        return $result;
    }

    public static function deauthentificate() {
        $_SESSION['loggedin'] = false;
        unset($_SESSION['loggedin']);
        unset($_SESSION['username']);
        @session_destroy();

        return true;
    }
}
?>
