/**
  * Authentifier un utilisateur:
  * - Récupère l'utilisateur inscrit avec l'e-mail indiquée. S'il y en a un:
  *  - Vérifie le mot de passe. S'il correspond:
  *      - Récupère son compte
  * @author Alban Truc
  * @param string $email
  * @param string $password
  * @since 02/2014
  * @return User|array contenant le message d'erreur
  */
 public function authenticate($email, $password)
 {
     //Récupère l'utilisateur inscrit avec l'e-mail indiquée.
     $query = array('state' => (int) 1, 'email' => $email);
     $user = self::findOne($query);
     if ($user instanceof User) {
         $password = self::encrypt($password);
         if ($user->getPassword() == $password) {
             //On récupère le compte correspondant à l'utilisateur
             $accountCriteria = array('_id' => new MongoId($user->getCurrentAccount()), 'state' => (int) 1);
             $account = $this->accountPdoManager->findOne($accountCriteria);
             var_dump($account);
             if ($account instanceof Account) {
                 $refPlan = $this->refPlanPdoManager->findById($account->getRefPlan());
                 if ($refPlan instanceof RefPlan) {
                     $account->setRefPlan($refPlan);
                     $user->setCurrentAccount($account);
                     return $user;
                 } else {
                     $errorInfo = 'RefPlan with ID ' . $account->getRefPlan() . ' not found';
                     return array('error' => $errorInfo);
                 }
             } else {
                 $errorInfo = 'No active account with ID ' . $user->getCurrentAccount() . ' for user ' . $user->getId();
                 return array('error' => $errorInfo);
             }
         } else {
             $errorInfo = 'Password given (' . $password . ') does not match with password in database.';
             return array('error' => $errorInfo);
         }
     } else {
         $errorInfo = 'No ACTIVE user found for the following e-mail: ' . $email . ' Maybe you didn\'t activate your account?';
         return array('error' => $errorInfo);
     }
 }
Exemple #2
0
 * Date: 12/06/14
 * Time: 09:53
 */
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes';
require_once $projectRoot . '/required.php';
session_start();
$userManager = new UserPdoManager();
$planManager = new RefPlanPdoManager();
$accountManager = new AccountPdoManager();
if (isset($_SESSION['owleyesOK'])) {
    $userSession = unserialize($_SESSION['owleyesOK']);
    $user = $userManager->findById($userSession->getId());
    //retrouve l'user connecté grâce à l'id en session
    $userAccount = $accountManager->findById($user->getCurrentAccount());
    //retrouve le compte user
    $userPlan = $planManager->findById($userAccount->getRefPlan());
    //retrouve le plan user
    $startDateArray = $accountManager->formatMongoDate($userAccount->getStartDate());
    $endDateArray = $accountManager->formatMongoDate($userAccount->getEndDate());
} else {
    header('Location:/OwlEyes/pages/login.php');
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Owl Eyes | Dashboard</title>
        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
        <link rel="shortcut icon" href="/OwlEyes/img/icons/icons.ico">
Exemple #3
0
<?php

/**
 * Created by PhpStorm.
 * User: Ken
 * Date: 09/06/14
 * Time: 15:02
 */
include '../header/header.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
$planManager = new RefPlanPdoManager();
$plan = $planManager->findById($id);
include '../header/menu.php';
?>
    <!-- bootstrap 3.0.2 -->
    <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- font Awesome -->
    <link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <!-- Ionicons -->
    <link href="../css/ionicons.min.css" rel="stylesheet" type="text/css" />
    <!-- DATA TABLES -->
    <link href="../css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="../css/AdminLTE.css" rel="stylesheet" type="text/css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
Exemple #4
0
/**
 * Recharger une session avec les nouvelles données en bdd
 */
function refreshUserSession()
{
    //Initialise nos objets
    $userPdoManager = new UserPdoManager();
    $accountPdoManager = new AccountPdoManager();
    $refPlanPdoManager = new RefPlanPdoManager();
    //Récupère l'utilisateur inscrit avec l'id indiquée.
    $id = array('state' => (int) 1, '_id' => unserialize($_SESSION['user'])->getId());
    $user = $userPdoManager->findOne($id);
    if ($user instanceof User) {
        //On récupère le compte correspondant à l'utilisateur
        $accountCriteria = array('_id' => new MongoId($user->getCurrentAccount()), 'state' => (int) 1);
        $account = $accountPdoManager->findOne($accountCriteria);
        if ($account instanceof Account) {
            $refPlan = $refPlanPdoManager->findById($account->getRefPlan());
            if ($refPlan instanceof RefPlan) {
                $account->setRefPlan($refPlan);
                $user->setCurrentAccount($account);
                $u = $_SESSION['user'] = serialize($user);
                //met les infos user en session
                return $u;
            } else {
                $errorInfo = 'RefPlan with ID ' . $account->getRefPlan() . ' not found';
                return array('error' => $errorInfo);
            }
        } else {
            $errorInfo = 'No active account with ID ' . $user->getCurrentAccount() . ' for user ' . $user->getId();
            return array('error' => $errorInfo);
        }
    } else {
        $errorInfo = 'No ACTIVE user found for the following e-mail: ' . $id . ' Maybe you didn\'t activate your account?';
        return array('error' => $errorInfo);
    }
}
Exemple #5
0
 * Date: 09/06/14
 * Time: 15:02
 */
include '../header/header.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
$userManager = new UserPdoManager();
$planManager = new RefPlanPdoManager();
$accountManager = new AccountPdoManager();
$allplan = $planManager->findAll();
$account = $accountManager->findById($id);
//id account
$accountUser = $account->getUser();
//id user
$currentPlan = $planManager->findById($account->getRefPlan());
//id du plan
$user = $userManager->findById($accountUser);
//récupère la collection user via id
/*********************************/
$criteria2014 = array('idUser' => $accountUser, 'startDate' => array('$gt' => new MongoDate(strtotime("2014-01-01 00:00:00")), '$lte' => new MongoDate(strtotime("2014-12-30 23:59:59"))));
$filterDate = $accountManager->find($criteria2014);
//foreach($filterDate as $thisAccount)
//{
//
//    var_dump($thisAccount->getStorage());
//    echo 'getUser';
//    var_dump($thisAccount->getUser());
//    var_dump($thisAccount->getRatio());
//}
//
Exemple #6
0
//récupère le prix du plan en bdd pour une vérification avec Paypal
$refPlan = new RefPlanPdoManager();
$paymentPdoManager = new PaymentPdoManager();
$accountPdoManager = new AccountPdoManager();
$userPdoManager = new UserPdoManager();
if (!$fp) {
} else {
    fputs($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets($fp, 1024);
        if (strcmp($res, "VERIFIED") == 0) {
            // vérifier que payment_status a la valeur Completed
            if ($payment_status == "Completed") {
                //Vérifie si le mail du marchant est == au mail du receveur
                if ($emailAccount == $receiver_email) {
                    $refPrice = $refPlan->findById($custom[1])->getPrice();
                    //Vérifie la somme en bdd et celle enregistré sur Paypal
                    if ($refPrice == $payment_amount) {
                        /*
                         * Insertion en bdd du plan acheté (state(1), idUser, prix , date, retour paypal
                         */
                        $payment = array('state' => (int) 1, 'paymentStatus' => $payment_status, 'idUser' => new MongoId($custom[0]), 'amount' => $payment_amount, 'date' => new MongoDate(), 'paypalReturn' => $_POST);
                        $paymentPdoManager->create($payment);
                        /*
                         * Récupère le compte actuel
                         */
                        $criteria = array('state' => (int) 1, 'idUser' => new MongoId($custom[0]));
                        $updateAccount = array('$set' => array('state' => new MongoInt32(0)));
                        $account = $accountPdoManager->findAndModify($criteria, $updateAccount, NULL, array('new' => TRUE));
                        /*Si le compte existe*/
                        if ($account instanceof Account) {
Exemple #7
0
/**
 * @todo vérification du ratio (suffisant ou non pour autoriser le téléchargement)
 * @todo support de lourds fichiers
 * @author Alban Truc
 * @param string|MongoId $idUser
 * @param string|MongoId $idElement
 * @since 15/06/2014
 * @return array
 */
function userDownload($idUser, $idElement)
{
    $idUser = new MongoId($idUser);
    $idElement = new MongoId($idElement);
    $elementPdoManager = new ElementPdoManager();
    $elementCriteria = array('state' => (int) 1, '_id' => $idElement);
    $element = $elementPdoManager->findOne($elementCriteria);
    if (!$element instanceof Element) {
        return $element;
    }
    //récupération de la vitesse de téléchargement de l'utilisateur
    $accountPdoManager = new AccountPdoManager();
    $accountCriteria = array('state' => 1, 'idUser' => $idUser);
    $account = $accountPdoManager->findOne($accountCriteria);
    if (!$account instanceof Account) {
        return $account;
    }
    $refPlanPdoManager = new RefPlanPdoManager();
    $refPlan = $refPlanPdoManager->findById($account->getRefPlan());
    if (!$refPlan instanceof RefPlan) {
        return $refPlan;
    }
    $downloadSpeed = $refPlan->getDownloadSpeed();
    //return $downloadSpeed;
    //récupère le code et l'extension de notre élément
    $refElementPdoManager = new RefElementPdoManager();
    $fieldsToReturn = array('code' => TRUE, 'extension' => TRUE);
    $refElement = $refElementPdoManager->findById($element->getRefElement(), $fieldsToReturn);
    if (!array_key_exists('error', $refElement)) {
        if (preg_match('/^4/', $refElement['code']) || preg_match('/^9/', $refElement['code'])) {
            // dossier ou non reconnu, pas d'extension à rajouter
            return array('error' => 'Donwload not available on folder or unrecognized element');
        }
    } else {
        return $refElement;
    }
    // 01 correspond au droit de lecture.
    $hasRight = actionAllowed($idElement, $idUser, array('01'));
    if (is_bool($hasRight) && $hasRight == FALSE) {
        return array('error' => 'You are not allowed to download this file.');
    } elseif (is_array($hasRight)) {
        return $hasRight;
    }
    $filePath = PATH . $idUser . $element->getServerPath();
    $fileName = $element->getName() . $refElement['extension'];
    $fullFilePath = $filePath . $fileName;
    $fileSize = round($element->getSize() * 1024);
    set_time_limit(0);
    if ($fd = fopen($fullFilePath, 'r')) {
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=\"{$fileName}\"");
        header("Content-Transfer-Encoding: binary");
        header("Content-length: {$fileSize}");
        $fileExtension = pathinfo($fullFilePath, PATHINFO_EXTENSION);
        //déterminer le Content-Type
        $ctype = getContentType($fileExtension);
        //nécessite http://pecl.php.net/package/pecl_http
        /*
        http_send_content_disposition($fileName);
        http_send_content_type($ctype);
        http_throttle(0.1, $downloadSpeed * 1024);
        http_send_file($fullFilePath);
        */
        header("Content-Type: {$ctype}");
        $file = @fopen($fullFilePath, 'rb');
        if ($file) {
            while (!feof($file)) {
                print fread($file, 1024 * $downloadSpeed);
                flush();
                usleep(500);
                if (connection_status() != 0) {
                    @fclose($file);
                    die;
                }
            }
            @fclose($file);
        }
    }
}
Exemple #8
0
    echo $user->getLastName();
    ?>
</td>
                                <td class="infoStorage"><?php 
    echo $user->getEmail();
    ?>
</td>
                                <td class="infoDL"><?php 
    echo $user->getGeolocation();
    ?>
</td>
                                <?php 
    if ($account instanceof Account) {
        $startDateArray = $accountManager->formatMongoDate($account->getStartDate());
        $endDateArray = $accountManager->formatMongoDate($account->getEndDate());
        $plan = $planManager->findById($account->getRefPlan());
    }
    ?>
                                <td class="info"><?php 
    echo $startDateArray['date'];
    ?>
</td>
                                <td class="info"><?php 
    echo $endDateArray['date'];
    ?>
</td>
                                <td class="info"><?php 
    echo $plan->getName();
    ?>
</td>
                                <td class="info"><?php 
echo '____Retourne uniquement le champ state';
$refPlanFind = $refPlanPdoManager->find(array('state' => 1), array('state'));
var_dump($refPlanFind);
echo '____Retourne en objet';
$refPlanFind = $refPlanPdoManager->find(array('state' => 1));
var_dump($refPlanFind);
echo '----------------------------------------<br />';
echo 'Utilisation du findOne';
$refPlanFindOne = $refPlanPdoManager->findOne($refPlanFind[0], array('_id'));
var_dump($refPlanFindOne);
echo '____equivalent du findById';
$refPlanFindOne = $refPlanPdoManager->findOne(array('_id' => new MongoId('52eb5e743263d8b6a4395df0')));
var_dump($refPlanFindOne);
echo '----------------------------------------<br />';
echo 'Utilisation du findById avec un MongoId en parametre';
$refPlanFoundById = $refPlanPdoManager->findById(new MongoId('52eb5e743263d8b6a4395df0'));
var_dump($refPlanFoundById);
echo 'Utilisation du findById avec une string en parametre';
$refPlanFoundById = $refPlanPdoManager->findById('52eb5e743263d8b6a4395df0');
var_dump($refPlanFoundById);
echo '----------------------------------------<br />';
echo 'Retrouver les plans gratuits';
$freePlans = $refPlanPdoManager->findFreePlans();
var_dump($freePlans);
echo '----------------------------------------<br />';
echo 'Retrouver les plans premium';
$premiumPlans = $refPlanPdoManager->findPremiumPlans();
var_dump($premiumPlans);
echo '----------------------------------------<br />';
echo 'Recuperer tous les plans';
$allPlans = $refPlanPdoManager->findAll();