Ejemplo n.º 1
0
 public function authenticateAsGuest(PhraseaApplication $app, Request $request)
 {
     if (!$app->isGuestAllowed()) {
         $app->abort(403, $app->trans('Phraseanet guest-access is disabled'));
     }
     $context = new Context(Context::CONTEXT_GUEST);
     $app['dispatcher']->dispatch(PhraseaEvents::PRE_AUTHENTICATE, new PreAuthenticate($request, $context));
     $user = $app['manipulator.user']->createUser(uniqid('guest'), \random::generatePassword(24));
     $invite_user = $app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST);
     $usr_base_ids = array_keys($app['acl']->get($user)->get_granted_base());
     $app['acl']->get($user)->revoke_access_from_bases($usr_base_ids);
     $invite_base_ids = array_keys($app['acl']->get($invite_user)->get_granted_base());
     $app['acl']->get($user)->apply_model($invite_user, $invite_base_ids);
     $this->postAuthProcess($app, $user);
     $response = $this->generateAuthResponse($app, $app['browser'], $request->request->get('redirect'));
     $response->headers->setCookie(new Cookie('invite-usr-id', $user->getId()));
     $event = new PostAuthenticate($request, $response, $user, $context);
     $app['dispatcher']->dispatch(PhraseaEvents::POST_AUTHENTICATE, $event);
     return $response;
 }