Пример #1
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);
    }
}
Пример #2
0
<?php

//appel la session
session_start();
//variable de session a false
$loginOK = false;
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes';
//require $projectRoot.'/controller/functions.php';
require $projectRoot . '/required.php';
//On check si loginForm est bien defini
//S'il est defini alors on entre dans la condition
if (isset($_POST['loginForm'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];
    //Avant de se logger on verifie bien que les champs mail et password ne sont pas vide
    if (!empty($email) && !empty($password)) {
        $userPdoManager = new UserPdoManager();
        $criteria = array('email' => $email, 'password' => $userPdoManager->encrypt($password), 'isAdmin' => true);
        $user = $userPdoManager->findOne($criteria);
        var_dump($user);
        if (!array_key_exists('error', $user)) {
            $_SESSION['owleyesOK'] = serialize($user);
            //redirection vers index
            header('Location:../index.php');
        } else {
            $_SESSION['errorMessageLogin'] = $user['error'];
            header('Location:../pages/login.php');
            die;
        }
    }
}
Пример #3
0
 * Date: 31/03/14
 * Time: 15:17
 */
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Cubbyhole';
require $projectRoot . '/required.php';
$userPdoManager = new UserPdoManager();
echo 'Utilisation du find<br />';
echo '____Retourne uniquement le champ state';
$userFind = $userPdoManager->find(array('state' => 1), array('state' => 0));
var_dump($userFind);
echo '____Retourne en objet';
$userFind = $userPdoManager->find(array('state' => 1));
var_dump($userFind);
echo '----------------------------------------<br />';
echo 'Utilisation du findOne';
$userFindOne = $userPdoManager->findOne($userFind[0], array('_id'));
var_dump($userFindOne);
echo '____equivalent du findById';
$userFindOne = $userPdoManager->findOne(array('_id' => $userFind[0]->getId()));
var_dump($userFindOne);
echo '----------------------------------------<br />';
echo 'Utilisation du findById avec un MongoId en parametre';
$userFoundById = $userPdoManager->findById(new MongoId('53388c1d09413a282e00002a'));
var_dump($userFoundById);
echo 'Utilisation du findById avec une string en parametre';
$userFoundById = $userPdoManager->findById('53388c1d09413a282e00002a');
var_dump($userFoundById);
echo '----------------------------------------<br />';
echo 'Recuperer tous les utilisateurs';
$allUsers = $userPdoManager->findAll();
var_dump($allUsers);
Пример #4
0
function shareWithAnonymous($idElement, $idOwner, $recipientEmail = '')
{
    $idElement = new MongoId($idElement);
    $idOwner = new MongoId($idOwner);
    $elementPdoManager = new ElementPdoManager();
    $elementCriteria = array('state' => (int) 1, '_id' => $idElement);
    $element = $elementPdoManager->findOne($elementCriteria);
    if ($element->getDownloadLink() == '') {
        /*
         * vérification que l'idOwner en param de la fonction est le même que celui de l'element, la gestion des partages
         * n'étant dans cette version qu'accessible au propriétaire de l'élément
         */
        if ($idOwner == $element->getOwner()) {
            //vérification que l'email indiquée appartient bien à un utilisateur inscrit
            $userCriteria = array('state' => (int) 1, 'email' => $recipientEmail);
            $userPdoManager = new UserPdoManager();
            $recipientUser = $userPdoManager->findOne($userCriteria);
            /*
             * Tentative de génération de lien de téléchargement anonyme pour un utilsateur existant.
             * L'interdire ici ne résoudra cependant que partiellement cet éventuel problème,
             * mais au moins on limite la permissivité.
             */
            if ($recipientUser instanceof User) {
                return array('error' => 'The email you entered belongs to one of our users, please use the \'share with a user\' functionality.');
            }
            $downloadLink = $elementPdoManager->generateGUID();
            $updateDownloadLink = array('$set' => array('downloadLink' => $downloadLink));
            $updateStatus = $elementPdoManager->update($elementCriteria, $updateDownloadLink);
            if (is_bool($updateStatus) && $updateStatus == TRUE) {
                return array('downloadLink' => $downloadLink);
            } else {
                return $updateStatus;
            }
        } else {
            return array('error' => 'You are not the owner of this element, you cannot share it.');
        }
    } else {
        return array('error', 'There is already a download link for this element.');
    }
}