/** * 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>
<?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); $accountManager = new AccountPdoManager(); $userManager = new UserPdoManager(); $account = $accountManager->findById($id); $user = $accountManager->findById($id); //Critère de recherche pour le compte $criteriaAccount = array('_id' => new MongoId($account->getId())); //Critère de recherche pour le user $criteriaUser = array('_id' => new MongoId($account->getUser())); $updateCriteria = array('$set' => array('state' => new MongoInt32(0))); var_dump($criteriaUser); var_dump($updateCriteria); $disableUserAccount = $accountManager->findAndModify($criteriaAccount, $updateCriteria, NULL, array('new' => TRUE)); $disableUser = $userManager->findAndModify($criteriaUser, $updateCriteria, NULL, array('new' => TRUE)); header('Location: ../pages/users.php');
$lastname = $_POST['lastname']; $password = $_POST['password']; $email = $_POST['email']; $geo = $_POST['geo']; $plan = $_POST['plan']; $state = $_POST['state']; if (isset($_POST['isAdmin'])) { $isAdmin = $_POST['isAdmin']; $isAdmin = true; var_dump($isAdmin); } else { $isAdmin = false; var_dump($isAdmin); } $userManager = new UserPdoManager(); $accountManager = new AccountPdoManager(); $planManager = new RefPlanPdoManager(); //Verifie la disponibilité de l'adresse mail if ($userManager->checkEmailAvailability($email) != FALSE) { $accountId = new MongoId(); $userId = new MongoId(); //crypte le password $password = $userManager->encrypt($password); //@link http://www.php.net/manual/en/class.mongodate.php $time = time(); $end = $time + 30 * 24 * 60 * 60; // + 30 jours //info compte $account = array('_id' => $accountId, 'state' => new MongoInt32($state), 'idUser' => $userId, 'idRefPlan' => new MongoId($plan), 'storage' => (int) 0, 'ratio' => (int) 0, 'startDate' => new MongoDate($time), 'endDate' => new MongoDate($end)); $isAccountAdded = $accountManager->create($account); //Si aucun pb apres ajout du compte, ajoute l'user, sinon suppresion de user
/** * 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); } }
$password = $_POST['password']; $email = $_POST['email']; $geo = $_POST['geo']; $startDate = strtotime($_POST['startDate']); $endDate = strtotime($_POST['endDate']); $plan = $_POST['plan']; var_dump($startDate); var_dump($endDate); if ($startDate == FALSE || $endDate == FALSE) { $message = 'Invalid date. It may be because you are not using the YYYY-MM-DD format or your date is after Tuesday, 19th January 2038, date that is not handled'; $_SESSION['editUserInvalidMessage'] = $message; header('Location: ../pages/users.php'); die; } $userManager = new UserPdoManager(); $accountManager = new AccountPdoManager(); $planManager = new RefPlanPdoManager(); // $sDate = $userManager->formatMongoDate($startDate); // $eDate = $userManager->formatMongoDate($endDate); $account = $accountManager->findById($id); //récupère l'idAccount $user = $account->getUser(); //récupère l'idUser $user = $userManager->findById($user); //récupère ensuite les infos user byId $criteriaAccount = array('_id' => new MongoId($account->getId())); $criteriaUser = array('_id' => new MongoId($user->getId())); $updateFieldAccount = array('$set' => array('startDate' => new MongoDate($startDate), 'endDate' => new MongoDate($endDate), 'idRefPlan' => new MongoId(_sanitize($plan)), 'state' => new MongoInt32(1))); $updateFieldUser = array('$set' => array('firstName' => _sanitize($firstname), 'lastName' => _sanitize($lastname), 'password' => _sanitize($password), 'email' => _sanitize($email), 'geo' => _sanitize($geo), 'state' => new MongoInt32(1))); $options = array('new' => true); // var_dump($updateFieldAccount);
<?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());
$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 if ($refPrice == $payment_amount) { /*
/** * @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); } } }
<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/sign-up.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../content/css/style.css" type="text/css" /> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <?php include '../header/menu.php'; if (isset($_SESSION['user'])) { refreshUserSession(); $userManager = new UserPdoManager(); $accountManager = new AccountPdoManager(); $refManager = new RefPlanPdoManager(); //Récupère les dates d'enregistrement et de fin d'abonnement $userStartDate = $user->getCurrentAccount()->getStartDate(); $userEndDate = $user->getCurrentAccount()->getEndDate(); //Formatage des dates pour une meilleur lisibilité humaine $userFormatStartDate = AbstractPdoManager::formatMongoDate($userStartDate); $userFormatEndDate = AbstractPdoManager::formatMongoDate($userEndDate); //Requête BDD $userInSession = unserialize($_SESSION['user']); $user = $userManager->findById($userInSession->getId()); //retrouve l'user connecté grâce à l'id en session $userAccount = $accountManager->findById($user->getCurrentAccount()); //retrouve le compte user $userPlan = $refManager->findById($userAccount->getRefPlan()); //retrouve le plan user
<?php /** * Created by PhpStorm. * User: Crocell * Date: 31/03/14 * Time: 11:48 * * Fichier de tests de fonctions. */ $projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Cubbyhole'; require $projectRoot . '/required.php'; $accountPdoManager = new AccountPdoManager(); echo 'Utilisation du find<br />'; echo '____Retourne tous les champs sauf le champ state'; $accountFind = $accountPdoManager->find(array('state' => 1), array('state' => 0)); var_dump($accountFind); echo '____Retourne en objet'; $accountFind = $accountPdoManager->find(array('state' => 1)); var_dump($accountFind); echo '----------------------------------------<br />'; echo 'Utilisation du findOne'; $array = array('_id' => new MongoId('52eb602d3263d8b6a4395df3'), 'state' => 1, 'idUser' => null, 'idRefPlan' => new MongoId('52eb5e783263d8b6a4395df1'), 'storage' => 2, 'ratio' => 1, 'startDate' => '01-31-2014', 'endDate' => 'none'); $manualAccount = new Account($array); $accountFindOne = $accountPdoManager->findOne($manualAccount, array('_id')); var_dump($accountFindOne); echo '____equivalent du findById'; $accountFindOne = $accountPdoManager->findOne(array('_id' => $accountFind[0]->getId())); var_dump($accountFindOne); echo '----------------------------------------<br />'; echo 'Utilisation du findById avec un MongoId en parametre';