/** * 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); } }
<?php /** * Created by PhpStorm. * User: Ken * 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>
<link rel="stylesheet" type="text/css" href="../content/css/compiled/theme.css" /> <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,900,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css' /> <link rel="stylesheet" href="../content/css/compiled/pricing.css" type="text/css" media="screen" /> <link rel="stylesheet" type="text/css" href="../content/css/lib/animate.css" media="screen, projection" /> <link rel="stylesheet" href="../content/css/style.css" type="text/css" media="screen" /> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <?php include '../header/menu.php'; $refPlanPdoManager = new RefPlanPdoManager(); //Plan Fre $freePlans = $refPlanPdoManager->findFreePlans(); //Plan Premium $premiumPlans = $refPlanPdoManager->findPremiumPlans(); ?> <!-- Pricing Option3 --> <div id="in_pricing2"> <?php if (isset($_SESSION['user'])) { //recharge la session avec les nouvelles données refreshUserSession(); //condition d'affichage de la bannière une fois l'user revenu sur la page $refPlanName = unserialize($_SESSION['user']); //recupère le nom du plan en session switch ($refPlanName->getCurrentAccount()->getRefPlan()->getName()) {
<?php /** * Created by PhpStorm. * User: Ken * Date: 10/06/14 * Time: 15:02 * Permet la désactivation d'un Plan */ $projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes'; require_once $projectRoot . '/required.php'; $id = $_GET['id']; var_dump($id); $refPlanManager = new RefPlanPdoManager(); $criteria = array('_id' => new MongoId($id)); $updateCriteria = array('$set' => array('state' => (int) 0)); $disablePlan = $refPlanManager->findAndModify($criteria, $updateCriteria, NULL, array('new' => TRUE)); header('Location: ../pages/plan.php');
<?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>
/** * 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); } }
* Time: 21:33 */ session_start(); $projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes'; require_once $projectRoot . '/required.php'; $id = $_GET['id']; //Traitement pour l'ajout du plan en bdd if (isset($_POST['edit_plan'])) { $name = $_POST['name']; $price = $_POST['price']; $maxStorage = $_POST['maxStorage']; $dl = $_POST['downL']; $up = $_POST['upL']; $maxRatio = $_POST['maxRatio']; if (!empty($name) && !empty($price) && !empty($maxStorage)) { $refPlanManager = new RefPlanPdoManager(); $criteria = array('_id' => new MongoId($id)); $updatePlan = array('$set' => array('name' => $name, 'price' => new MongoInt32($price), 'maxStorage' => new MongoInt32($maxStorage), 'downloadSpeed' => new MongoInt32($dl), 'uploadSpeed' => new MongoInt32($up), 'maxRatio' => new MongoInt32($maxRatio), 'state' => new MongoInt32(1))); $options = array('new' => true); $editPlan = $refPlanManager->findAndModify($criteria, $updatePlan, null, $options); if ($editPlan == true) { $message = 'Your plan has successfully changed'; $_SESSION['editPlanMessage'] = $message; header('Location: ../pages/plan.php'); die; } else { $message = 'Update error'; $_SESSION['editPlanMessage'] = $message; header('Location: ../pages/plan.php'); die; }
<?php /** * Created by PhpStorm. * User: Ken * 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());
//$hostname, port, errno, errstr, timeout $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; //$payment_status = 'Canceled_Reversal'; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $payment_date = $_POST['payment_date']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $custom = explode('|', $_POST['custom']); //parse du champ custom, pour l'instant idUser | idRefPlan //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
/** * @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); } } }
<?php /** * Created by PhpStorm. * User: Ken * Date: 09/06/14 * Time: 15:02 */ include '../header/header.php'; $usersManager = new UserPdoManager(); $accountManager = new AccountPdoManager(); $planManager = new RefPlanPdoManager(); $allUsers = $usersManager->findAll(); 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" /> <link href="../css/datatables/dataTables.tableTools.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>
<?php /** * Created by PhpStorm. * User: Ken * Date: 09/06/14 * Time: 15:02 */ include '../header/header.php'; $planManager = new RefPlanPdoManager(); $userManager = new UserPdoManager(); $allPlan = $planManager->findAll(); $id = $allPlan[0]->getId(); 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>
<?php /** * Created by PhpStorm. * User: Crocell * Date: 12/03/14 * Time: 09:50 * * Fichier de tests de fonctions. */ $projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Cubbyhole'; require $projectRoot . '/required.php'; $refPlanPdoManager = new RefPlanPdoManager(); echo 'Utilisation du find<br />'; 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);
<?php /** * Created by PhpStorm. * User: Ken * Date: 10/06/14 * Time: 21:33 */ session_start(); $projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes'; require_once $projectRoot . '/required.php'; $addPlanOK = false; //Traitement pour l'ajout du plan en bdd if (isset($_POST['add_plan'])) { $name = $_POST['name']; $price = $_POST['price']; $maxStorage = $_POST['maxStorage']; $dl = $_POST['downL']; $up = $_POST['upL']; $maxRatio = $_POST['maxRatio']; if (!empty($name) && !empty($price) && !empty($maxStorage)) { $refPlanManager = new RefPlanPdoManager(); $newPlan = array('name' => $name, 'price' => new MongoInt32($price), 'maxStorage' => new MongoInt32($maxStorage), 'downloadSpeed' => new MongoInt32($dl), 'uploadSpeed' => new MongoInt32($up), 'maxRatio' => new MongoInt32($maxRatio), 'state' => new MongoInt32(1)); $addPlan = $refPlanManager->create($newPlan); $addPlanOK = true; $message = 'Your plan has successfully inserted'; $_SESSION['addPlanMessage'] = $message; header('Location: ../pages/plan.php'); } }