Move static::guest_allowed method to Application

This commit is contained in:
Nicolas Le Goff
2013-07-05 17:58:08 +02:00
parent ae9aa7f4fc
commit 0b4f8c4b07
5 changed files with 15 additions and 16 deletions

View File

@@ -682,6 +682,17 @@ class Application extends SilexApplication
return false; return false;
} }
public function isGuestAllowed()
{
$usrId = \User_Adapter::get_usr_id_from_login($this, 'invite');
if (!$usrId) {
return false;
}
return count(\User_Adapter::getInstance($usrId, $this)->ACL()->get_granted_base()) > 0;
}
/** /**
* Returns an an array of available collection for offline queries * Returns an an array of available collection for offline queries
* *

View File

@@ -704,7 +704,6 @@ class Login implements ControllerProviderInterface
'unlock_usr_id' => $app->getUnlockAccountData(), 'unlock_usr_id' => $app->getUnlockAccountData(),
'login' => new \login(), 'login' => new \login(),
'feeds' => $feeds, 'feeds' => $feeds,
'guest_allowed' => \phrasea::guest_allowed($app),
'form' => $form->createView(), 'form' => $form->createView(),
)); ));
} }
@@ -732,7 +731,7 @@ class Login implements ControllerProviderInterface
public function authenticateAsGuest(PhraseaApplication $app, Request $request) public function authenticateAsGuest(PhraseaApplication $app, Request $request)
{ {
if (!\phrasea::guest_allowed($app)) { if (!$app->isGuestAllowed()) {
$app->abort(403, _('Phraseanet guest-access is disabled')); $app->abort(403, _('Phraseanet guest-access is disabled'));
} }

View File

@@ -87,17 +87,6 @@ class phrasea
return self::$_sbas_params; return self::$_sbas_params;
} }
public static function guest_allowed(Application $app)
{
$usr_id = User_Adapter::get_usr_id_from_login($app, 'invite');
if (!$usr_id) {
return false;
}
$user = User_Adapter::getInstance($usr_id, $app);
return count($user->ACL()->get_granted_base()) > 0;
}
public static function use_i18n($locale, $textdomain = 'phraseanet') public static function use_i18n($locale, $textdomain = 'phraseanet')
{ {
$codeset = "UTF-8"; $codeset = "UTF-8";

View File

@@ -1,4 +1,4 @@
{% if guest_allowed %} {% if app.isGuestAllowed() %}
<div class="well-large sidebar-block"> <div class="well-large sidebar-block">
<div class="row-fluid"> <div class="row-fluid">
<div class="span12 text-center"> <div class="span12 text-center">

View File

@@ -110,8 +110,8 @@
</div> </div>
{% endif %} {% endif %}
{% include "login/include/register-link-block.html.twig" with {"login" : login, "last_item" : app['registration.enabled'] and not guest_allowed} %} {% include "login/include/register-link-block.html.twig" %}
{% include "login/include/guest-access-block.html.twig" with {"guest_allowed" : guest_allowed, "last_item" : guest_allowed} %} {% include "login/include/guest-access-block.html.twig" %}
{% endblock %} {% endblock %}
{% block left_content %} {% block left_content %}