예제 #1
0
 /**
  * @param string $id
  * @return \Symforce\DiscuzBundle\Entity\User
  */
 public function loadUserById($id)
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = \Dev::getContainer()->get('doctrine')->getManager();
     $user = $em->getRepository('Symforce\\DiscuzBundle\\Entity\\User')->findOneBy(array('uid' => $id));
     return $user;
 }
 /**
  * @param string $template
  * @param array $content
  * @return string
  */
 public final function render($template, array $content = null)
 {
     /**
      * @var $twig \Twig_Environment
      */
     $twig = \Dev::getContainer()->get('twig');
     if (!$content) {
         $content = array();
     }
     if (!isset($content['pm'])) {
         $content['pm'] = $this;
     }
     $content['_G'] = $GLOBALS['_G'];
     if (false === strpos($template, ':') && false === strpos($template, '\\') && false === strpos($template, '//')) {
         $template = sprintf('%s:PluginModule:%s', $this->bundle_name, $template);
     }
     return $twig->render($template, $content);
 }
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserById($token->getUserId());
     if ($user && $token instanceof UserToken) {
         $token->setUser($user);
         global $_G;
         $em = \Dev::getDoctrine()->getManager();
         $user->setupDiscuzRoles($em, $_G);
         return $token;
     }
     if (\Dev::getContainer()->getParameter('kernel.debug')) {
         throw new AuthenticationException('The app authentication failed.');
     } else {
         if (\Dev::getContainer()->getParameter('debug_redirects')) {
             \Dev::dump('The app authentication failed.');
             exit;
         }
         $host = \Dev::getContainer()->getParameter('sf.web_host');
         header('location:' . $host);
         exit;
     }
 }