Ejemplo n.º 1
0
 function getUserId($token, $bdd)
 {
     if (!empty($token)) {
         $tokenManager = new TokenManager($bdd);
         if ($tokenbdd = $tokenManager->get($token, 'token')) {
             if ($tokenbdd->userip() == $_SERVER['REMOTE_ADDR']) {
                 $userId = $tokenbdd->userid();
                 return $userId;
             } else {
                 header('Location: ?controler=user&action=logoutForced');
                 exit;
             }
         }
     }
 }
Ejemplo n.º 2
0
<?php

switch ($action) {
    case 'login':
        if (!empty($_POST['login']) && !empty($_POST['pass'])) {
            $_POST['pass'] = sha1($_POST['pass']);
            $userToLog = new User($_POST);
            $userManager = new UserManager($bdd);
            if ($userToBdd = $userManager->get($userToLog->login(), 'login')) {
                if ($userToLog->pass() == $userToBdd->pass()) {
                    $tokenParams = array('token' => sha1($userToBdd->id() . $userToBdd->login() . $userToBdd->pass() . $_SERVER['REMOTE_ADDR'] . date("Y-m-d H:i:s")), 'userid' => $userToBdd->id(), 'userip' => $_SERVER['REMOTE_ADDR'], 'datetime' => date("Y-m-d H:i:s"));
                    $token = new Token($tokenParams);
                    $tokenManager = new TokenManager($bdd);
                    if ($lastToken = $tokenManager->get($userToBdd->id(), 'userid')) {
                        $token->setId($lastToken->id());
                        $tokenManager->update($token);
                    } else {
                        $tokenManager->add($token);
                    }
                    $_SESSION['token'] = $token->token();
                    header('Location: ?controler=index');
                } else {
                    //mot de passe incorrect
                    echo 'pass error';
                }
            } else {
                //login incorrect
                echo 'login error';
            }
        } else {
            header('Location: ?controler=index');