Add TokensServiceProvider

This commit is contained in:
Romain Neutron
2013-04-30 18:02:09 +02:00
parent 9651640bc7
commit cf0f13d9c9
21 changed files with 138 additions and 83 deletions

View File

@@ -84,6 +84,7 @@ use Alchemy\Phrasea\Core\Provider\NotificationDelivererServiceProvider;
use Alchemy\Phrasea\Core\Provider\ORMServiceProvider;
use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider;
use Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider;
use FFMpeg\FFMpegServiceProvider;
use Neutron\Silex\Provider\ImagineServiceProvider;
@@ -207,6 +208,7 @@ class Application extends SilexApplication
$this->register(new ServiceControllerServiceProvider());
$this->register(new SwiftmailerServiceProvider());
$this->register(new TaskManagerServiceProvider());
$this->register(new TokensServiceProvider());
$this->register(new TwigServiceProvider(), array(
'twig.options' => array(
'cache' => realpath(__DIR__ . '/../../../../../../tmp/cache_twig/'),

View File

@@ -41,7 +41,7 @@ class Lightbox implements ControllerProviderInterface
}
try {
$datas = \random::helloToken($app, $request->query->get('LOG'));
$datas = $app['tokens']->helloToken($request->query->get('LOG'));
} catch (\Exception_NotFound $e) {
return;
}
@@ -482,8 +482,8 @@ class Lightbox implements ControllerProviderInterface
$expires = new \DateTime('+10 days');
$url = $app['phraseanet.registry']->get('GV_ServerName')
. 'lightbox/index.php?LOG=' . \random::getUrlToken(
$app, \random::TYPE_VALIDATE
. 'lightbox/index.php?LOG=' . $app['tokens']->getUrlToken(
\random::TYPE_VALIDATE
, $basket->getValidation()->getInitiator($app)->get_id()
, $expires
, $basket->getId()

View File

@@ -92,7 +92,7 @@ class DoDownload implements ControllerProviderInterface
public function prepareDownload(Application $app, Request $request, $token)
{
try {
$datas = \random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) {
$app->abort(404, 'Invalid token');
}
@@ -141,7 +141,7 @@ class DoDownload implements ControllerProviderInterface
public function downloadDocuments(Application $app, Request $request, $token)
{
try {
$datas = \random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) {
$app->abort(404, 'Invalid token');
}
@@ -201,7 +201,7 @@ class DoDownload implements ControllerProviderInterface
public function downloadExecute(Application $app, Request $request, $token)
{
try {
$datas = \random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) {
return $app->json(array(
'success' => false,

View File

@@ -78,8 +78,7 @@ class Download implements ControllerProviderInterface
$list['export_name'] = sprintf('%s.zip', $download->getExportName());
$token = \random::getUrlToken(
$app,
$token = $app['tokens']->getUrlToken(
\random::TYPE_DOWNLOAD,
$app['phraseanet.user']->get_id(),
new \DateTime('+3 hours'), // Token lifetime

View File

@@ -267,7 +267,7 @@ class Export implements ControllerProviderInterface
//generate validation token
$endDateObject = new \DateTime('+1 day');
$token = \random::getUrlToken($app, \random::TYPE_EMAIL, false, $endDateObject, serialize($list));
$token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, false, $endDateObject, serialize($list));
if (count($destMails) > 0 && $token) {
//zip documents

View File

@@ -218,7 +218,7 @@ class Push implements ControllerProviderInterface
$url = $app['phraseanet.registry']->get('GV_ServerName')
. 'lightbox/index.php?LOG='
. \random::getUrlToken($app, \random::TYPE_VALIDATE, $user_receiver->get_id(), null, $Basket->getId());
. $app['tokens']->getUrlToken(\random::TYPE_VALIDATE, $user_receiver->get_id(), null, $Basket->getId());
$receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : '';
@@ -415,7 +415,7 @@ class Push implements ControllerProviderInterface
$url = $app['phraseanet.registry']->get('GV_ServerName')
. 'lightbox/index.php?LOG='
. \random::getUrlToken($app, \random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId());
. $app['tokens']->getUrlToken(\random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId());
$receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : '';

View File

@@ -263,10 +263,10 @@ class Account implements ControllerProviderInterface
{
if (null !== $token = $request->request->get('token')) {
try {
$datas = \random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
$user = \User_Adapter::getInstance((int) $datas['usr_id'], $app);
$user->set_email($datas['datas']);
\random::removeToken($app, $token);
$app['tokens']->removeToken($token);
return $app->redirect('/account/reset-email/?update=ok');
} catch (\Exception $e) {
@@ -296,7 +296,7 @@ class Account implements ControllerProviderInterface
}
$date = new \DateTime('1 day');
$token = \random::getUrlToken($app, \random::TYPE_EMAIL, $app['phraseanet.user']->get_id(), $date, $app['phraseanet.user']->get_email());
$token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, $app['phraseanet.user']->get_id(), $date, $app['phraseanet.user']->get_email());
$url = $app['phraseanet.registry']->get('GV_ServerName') . 'account/reset-email/?token=' . $token;
try {

View File

@@ -251,7 +251,7 @@ class Login implements ControllerProviderInterface
if ($receiver) {
$expire = new \DateTime('+3 days');
$token = \random::getUrlToken($app, \random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email());
$token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email());
$mail = MailRequestEmailConfirmation::create($app, $receiver);
$mail->setButtonUrl($app['phraseanet.registry']->get('GV_ServerName') . "register-confirm/?code=" . $token);
@@ -277,7 +277,7 @@ class Login implements ControllerProviderInterface
}
try {
$datas = \random::helloToken($app, $code);
$datas = $app['tokens']->helloToken($code);
} catch (\Exception_NotFound $e) {
return $app->redirect('/login/?redirect=prod&error=token-not-found');
}
@@ -292,7 +292,7 @@ class Login implements ControllerProviderInterface
return $app->redirect('/login/?redirect=prod&notice=already');
}
\random::removeToken($app, $code);
$app['tokens']->removeToken($code);
try {
$receiver = Receiver::fromUser($user);
@@ -301,7 +301,7 @@ class Login implements ControllerProviderInterface
}
$user->set_mail_locked(false);
\random::removeToken($app, $code);
$app['tokens']->removeToken($code);
if (count($user->ACL()->get_granted_base()) > 0) {
$mail = MailSuccessEmailConfirmationRegistered::create($app, $receiver);
@@ -338,7 +338,7 @@ class Login implements ControllerProviderInterface
return $app->redirect($app['url_generator']->generate('login_forgot_password', array('error' => 'invalidmail')));
}
$token = \random::getUrlToken($app, \random::TYPE_PASSWORD, $user->get_id(), new \DateTime('+1 day'));
$token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), new \DateTime('+1 day'));
if ($token) {
$url = $app['url_generator']->generate('login_forgot_password', array('token' => $token), true);
@@ -364,12 +364,12 @@ class Login implements ControllerProviderInterface
}
try {
$datas = \random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
$user = \User_Adapter::getInstance($datas['usr_id'], $app);
$user->set_password($passwordConfirm);
\random::removeToken($app, $token);
$app['tokens']->removeToken($token);
return $app->redirect('/login/?notice=password-update-ok');
} catch (\Exception_NotFound $e) {
@@ -392,7 +392,7 @@ class Login implements ControllerProviderInterface
if (null !== $token = $request->query->get('token')) {
try {
\random::helloToken($app, $token);
$app['tokens']->helloToken($token);
$tokenize = true;
} catch (\Exception $e) {
$errorMsg = 'token';
@@ -703,7 +703,7 @@ class Login implements ControllerProviderInterface
$user->set_mail_locked(true);
$expire = new \DateTime('+3 days');
$token = \random::getUrlToken($app, \random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email());
$token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email());
$mail = MailRequestEmailConfirmation::create($app, $receiver);
$mail->setButtonUrl($app['phraseanet.registry']->get('GV_ServerName') . "register-confirm/?code=" . $token);
@@ -913,7 +913,7 @@ class Login implements ControllerProviderInterface
$basketId = $validationSession->getBasket()->getId();
try {
$token = \random::getValidationToken($this->app, $participantId, $basketId);
$token = $this->app['tokens']->getValidationToken($participantId, $basketId);
} catch (\Exception_NotFound $e) {
continue;
}
@@ -1036,7 +1036,7 @@ class Login implements ControllerProviderInterface
return $app->redirect($app['url_generator']->generate('login_forgot_password', array(
'salt' => 1,
'token' => \random::getUrlToken($app, \random::TYPE_PASSWORD, $usr_id, $date)
'token' => $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $usr_id, $date)
)));
} catch (\Exception $e) {
return $app->redirect("/login/?redirect=" . ltrim($request->request->get('redirect'), '/') . "&error=unexpected");

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
class TokensServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['tokens'] = $app->share(function($app) {
return new \random($app);
});
}
public function boot(Application $app)
{
}
}

View File

@@ -180,7 +180,7 @@ class Manage extends Helper
if ($receiver) {
$expire = new \DateTime('+3 days');
$token = \random::getUrlToken($this->app, \random::TYPE_PASSWORD, $createdUser->get_id(), $expire, $createdUser->get_email());
$token = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->get_id(), $expire, $createdUser->get_email());
$mail = MailRequestPasswordSetup::create($this->app, $receiver);
$mail->setButtonUrl($this->app['phraseanet.registry']->get('GV_ServerName') . "register-confirm/?code=" . $token);
@@ -191,7 +191,7 @@ class Manage extends Helper
}
if ($sendCredentials) {
$urlToken = \random::getUrlToken($this->app, \random::TYPE_PASSWORD, $createdUser->get_id());
$urlToken = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->get_id());
if ($receiver && false !== $urlToken) {
$mail = MailSuccessEmailConfirmationUnregistered::create($this->app, $receiver);

View File

@@ -38,7 +38,7 @@ class Session_Authentication_Token implements Session_Authentication_Interface
$this->token = $token;
try {
$datas = random::helloToken($app, $token);
$datas = $app['tokens']->helloToken($token);
$usr_id = $datas['usr_id'];
$this->user = User_Adapter::getInstance($usr_id, $this->app);
} catch (Exception_NotFound $e) {

View File

@@ -474,7 +474,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$stmt->closeCursor();
}
if ($token === false) {
$token = random::getUrlToken($this->app, \random::TYPE_RSS, $this->id);
$token = $this->app['tokens']->getUrlToken(\random::TYPE_RSS, $this->id);
}
return new system_url($this->app['phraseanet.registry']->get('GV_ServerName') . 'atom/' . $token);

View File

@@ -94,8 +94,7 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
if ($this->shouldSendNotificationFor($user_to_notif->get_id())) {
$readyToSend = false;
try {
$token = \random::getUrlToken(
$this->app,
$token = $this->app['tokens']->getUrlToken(
\random::TYPE_FEED_ENTRY
, $user_to_notif->get_id()
, null

View File

@@ -34,17 +34,23 @@ class random
const TYPE_VALIDATE = 'validate';
const TYPE_RSS = 'rss';
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
*
* @return Void
* @return Boolean
*/
public static function cleanTokens(Application $app)
public function cleanTokens()
{
try {
$conn = connection::getPDOConnection($app);
$conn = connection::getPDOConnection($this->app);
$date = new DateTime();
$date = $app['date-formatter']->format_mysql($date);
$date = $this->app['date-formatter']->format_mysql($date);
$sql = 'SELECT * FROM tokens WHERE expire_on < :date
AND datas IS NOT NULL AND (type="download" OR type="email")';
@@ -103,7 +109,6 @@ class random
/**
*
* @param Application $app
* @param string $type
* @param int $usr
* @param DateTime $end_date
@@ -111,10 +116,10 @@ class random
*
* @return boolean
*/
public static function getUrlToken(Application $app, $type, $usr, DateTime $end_date = null, $datas = '')
public function getUrlToken($type, $usr, DateTime $end_date = null, $datas = '')
{
self::cleanTokens($app);
$conn = connection::getPDOConnection($app);
$this->cleanTokens();
$conn = connection::getPDOConnection($this->app);
$token = $test = false;
switch ($type) {
@@ -167,12 +172,12 @@ class random
return $token;
}
public static function removeToken(Application $app, $token)
public function removeToken($token)
{
self::cleanTokens($app);
$this->cleanTokens();
try {
$conn = connection::getPDOConnection($app);
$conn = connection::getPDOConnection($this->app);
$sql = 'DELETE FROM tokens WHERE value = :token';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':token' => $token));
@@ -186,10 +191,10 @@ class random
return false;
}
public static function updateToken(Application $app, $token, $datas)
public function updateToken($token, $datas)
{
try {
$conn = connection::getPDOConnection($app);
$conn = connection::getPDOConnection($this->app);
$sql = 'UPDATE tokens SET datas = :datas
WHERE value = :token';
@@ -206,11 +211,11 @@ class random
return false;
}
public static function helloToken(Application $app, $token)
public function helloToken($token)
{
self::cleanTokens($app);
$this->cleanTokens();
$conn = connection::getPDOConnection($app);
$conn = connection::getPDOConnection($this->app);
$sql = 'SELECT * FROM tokens
WHERE value = :token
AND (expire_on > NOW() OR expire_on IS NULL)';
@@ -228,7 +233,6 @@ class random
/**
* Get the validation token for one user and one validation basket
*
* @param Application $app
* @param integer $userId
* @param integer $basketId
*
@@ -236,9 +240,9 @@ class random
*
* @throws \Exception_NotFound
*/
public static function getValidationToken(Application $app, $userId, $basketId)
public function getValidationToken($userId, $basketId)
{
$conn = \connection::getPDOConnection($app);
$conn = \connection::getPDOConnection($this->app);
$sql = '
SELECT value FROM tokens
WHERE type = :type

View File

@@ -718,7 +718,7 @@ class set_export extends set_abstract
$list['complete'] = false;
random::updateToken($app, $token, serialize($list));
$app['tokens']->updateToken($token, serialize($list));
$toRemove = array();
@@ -751,7 +751,7 @@ class set_export extends set_abstract
$list['complete'] = true;
random::updateToken($app, $token, serialize($list));
$app['tokens']->updateToken($token, serialize($list));
$app['filesystem']->remove($toRemove);
$app['filesystem']->chmod($zipFile, 0760);

View File

@@ -70,7 +70,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
self::$DI['app']->closeAccount();
$Basket = $this->insertOneBasket();
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_VIEW, self::$DI['user_alt2']->get_id(), null, $Basket->getId());
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VIEW, self::$DI['user_alt2']->get_id(), null, $Basket->getId());
self::$DI['client']->request('GET', '/lightbox/?LOG='.$token);

View File

@@ -166,7 +166,7 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$token = $this->getToken($list);
// Get token
$datas = \random::helloToken(self::$DI['app'], $token);
$datas = self::$DI['app']['tokens']->helloToken($token);
// Build zip
\set_export::build_zip(
self::$DI['app'],
@@ -341,8 +341,7 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
private function getToken($datas = array())
{
return \random::getUrlToken(
self::$DI['app'],
return self::$DI['app']['tokens']->getUrlToken(
\random::TYPE_DOWNLOAD,
self::$DI['user']->get_id(),
new \DateTime('+10 seconds'), // Token lifetime

View File

@@ -91,7 +91,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/
public function testPostResetMailWithToken()
{
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, self::$DI['user']->get_id(), null, 'new_email@email.com');
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, 'new_email@email.com');
self::$DI['client']->request('POST', '/account/reset-email/', array('token' => $token));
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isRedirect());
@@ -100,7 +100,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals('new_email@email.com', self::$DI['user']->get_email());
self::$DI['user']->set_email('noone@example.com');
try {
\random::helloToken(self::$DI['app'], $token);
self::$DI['app']['tokens']->helloToken($token);
$this->fail('TOken has not been removed');
} catch (\Exception_NotFound $e) {
@@ -186,7 +186,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostResetMailEmail()
{
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate');
$password = \random::generatePassword();
self::$DI['app']['phraseanet.user']->set_password($password);
self::$DI['client']->request('POST', '/account/reset-email/', array(

View File

@@ -96,7 +96,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
self::$DI['app']->closeAccount();
$email = $this->generateEmail();
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, 0, null, $email);
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, 0, null, $email);
self::$DI['client']->request('GET', '/login/register-confirm/', array('code' => $token));
$response = self::$DI['client']->getResponse();
@@ -111,7 +111,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
self::$DI['app']->closeAccount();
$email = $this->generateEmail();
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email);
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email);
self::$DI['user']->set_mail_locked(false);
@@ -132,7 +132,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['app']->closeAccount();
$email = $this->generateEmail();
$appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']);
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email);
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email);
self::$DI['user']->set_mail_locked(true);
$this->deleteRequest();
@@ -156,7 +156,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['app']->closeAccount();
$email = $this->generateEmail();
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, $user->get_id(), null, $email);
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, $user->get_id(), null, $email);
$user->set_mail_locked(true);
@@ -253,7 +253,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRenewPassword()
{
self::$DI['app']->closeAccount();
$token = \random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, self::$DI['user']->get_id());
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id());
self::$DI['client']->request('POST', '/login/forgot-password/', array(
'token' => $token,

View File

@@ -0,0 +1,16 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
/**
* @covers Alchemy\Phrasea\Core\Provider\TokensServiceProvider
*/
class TokensServiceProvidertest extends ServiceProviderTestCase
{
public function provideServiceDescription()
{
return array(
array('Alchemy\Phrasea\Core\Provider\TokensServiceProvider', 'tokens', '\random'),
);
}
}

View File

@@ -2,16 +2,23 @@
class randomTest extends PhraseanetPHPUnitAbstract
{
protected $random;
public function setUp()
{
parent::setUp();
$this->random = new \random(self::$DI['app']);
}
public function testCleanTokens()
{
$expires_on = new DateTime('-5 minutes');
$usr_id = self::$DI['user']->get_id();
$token = random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
random::cleanTokens(self::$DI['app']);
$token = $this->random->getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
$this->random->cleanTokens(self::$DI['app']);
try {
random::helloToken(self::$DI['app'], $token);
$this->random->helloToken($token);
$this->fail();
} catch (Exception_NotFound $e) {
@@ -58,13 +65,13 @@ class randomTest extends PhraseanetPHPUnitAbstract
public function testGetUrlToken()
{
$usr_id = self::$DI['user']->get_id();
$token = random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = random::helloToken(self::$DI['app'], $token);
$token = $this->random->getUrlToken(\random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = $this->random->helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
random::updateToken(self::$DI['app'], $token, 'some very nice datas');
$datas = random::helloToken(self::$DI['app'], $token);
$this->random->updateToken($token, 'some very nice datas');
$datas = $this->random->helloToken($token);
$this->assertEquals('some very nice datas', $datas['datas']);
random::removeToken(self::$DI['app'], $token);
$this->random->removeToken($token);
}
public function testRemoveToken()
@@ -80,8 +87,8 @@ class randomTest extends PhraseanetPHPUnitAbstract
public function testHelloToken()
{
$usr_id = self::$DI['user']->get_id();
$token = random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = random::helloToken(self::$DI['app'], $token);
$token = $this->random->getUrlToken(\random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = $this->random->helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
$this->assertNull($datas['expire_on']);
$created_on = new DateTime($datas['created_on']);
@@ -91,9 +98,9 @@ class randomTest extends PhraseanetPHPUnitAbstract
$this->assertTrue($date >= $created_on);
$this->assertEquals('password', $datas['type']);
random::removeToken(self::$DI['app'], $token);
$this->random->removeToken($token);
try {
random::helloToken(self::$DI['app'], $token);
$this->random->helloToken($token);
$this->fail();
} catch (Exception_NotFound $e) {
@@ -101,8 +108,8 @@ class randomTest extends PhraseanetPHPUnitAbstract
$expires_on = new DateTime('+5 minutes');
$usr_id = self::$DI['user']->get_id();
$token = random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
$datas = random::helloToken(self::$DI['app'], $token);
$token = $this->random->getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
$datas = $this->random->helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
$sql_expires = new DateTime($datas['expire_on']);
$this->assertTrue($sql_expires == $expires_on);
@@ -113,9 +120,9 @@ class randomTest extends PhraseanetPHPUnitAbstract
$this->assertTrue($date >= $created_on);
$this->assertEquals('password', $datas['type']);
random::removeToken(self::$DI['app'], $token);
$this->random->removeToken($token);
try {
random::helloToken(self::$DI['app'], $token);
$this->random->helloToken($token);
$this->fail();
} catch (Exception_NotFound $e) {
@@ -124,10 +131,10 @@ class randomTest extends PhraseanetPHPUnitAbstract
$expires_on = new DateTime('-5 minutes');
$usr_id = self::$DI['user']->get_id();
$token = random::getUrlToken(self::$DI['app'], \random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
$token = $this->random->getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
try {
random::helloToken(self::$DI['app'], $token);
$this->random->helloToken($token);
$this->fail();
} catch (Exception_NotFound $e) {