예제 #1
0
 public function onSecurityInteractivelogin(InteractiveLoginEvent $event)
 {
     $url = $this->router->generate('fos_user_profile_show');
     $user = $event->getAuthenticationToken()->getUser();
     $obj = $this->em->getRepository('SywFrontApiBundle:ApiAccess')->findOneBy(array("user" => $user));
     if (false === isset($obj) || false === is_object($obj) || $obj == null) {
         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $charactersLength = strlen($characters);
         $apikey = '';
         for ($i = 0; $i < 48; $i++) {
             $apikey .= $characters[rand(0, $charactersLength - 1)];
         }
         $apikey = md5($apikey);
         $ApiAccess = new ApiAccess();
         $ApiAccess->setUser($user);
         $ApiAccess->setApiKey($apikey);
         $this->em->persist($ApiAccess);
         $this->em->flush();
     }
     $this->container->get('session')->getFlashBag()->add('success', 'You have successfully logged in.');
     $response = new RedirectResponse($url);
     return $response;
 }
 /**
  * Show the user
  */
 public function showAction()
 {
     $user = $this->getUser();
     $em = $this->get('doctrine')->getManager();
     $obj = $em->getRepository('SywFrontApiBundle:ApiAccess')->findOneBy(array("user" => $user));
     if (false === isset($obj) || false === is_object($obj) || $obj == null) {
         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $charactersLength = strlen($characters);
         $apikey = '';
         for ($i = 0; $i < 48; $i++) {
             $apikey .= $characters[rand(0, $charactersLength - 1)];
         }
         $apikey = md5($apikey);
         $ApiAccess = new ApiAccess();
         $ApiAccess->setUser($user);
         $ApiAccess->setApiKey($apikey);
         $em->persist($ApiAccess);
         $em->flush();
     }
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException('This user does not have access to this section.');
     }
     $locale = $user->getLocale();
     $userProfile = $this->get('doctrine')->getRepository('SywFrontMainBundle:UserProfile')->findOneBy(array('user' => $user));
     $apiaccess = $this->get('doctrine')->getRepository('SywFrontApiBundle:ApiAccess')->findOneBy(array('user' => $user));
     $machines = $this->get('doctrine')->getRepository('SywFrontMainBundle:Machines')->findBy(array('user' => $user));
     $language = $this->get('doctrine')->getRepository('SywFrontMainBundle:Languages')->findOneBy(array('locale' => $locale));
     $languages = $this->get('doctrine')->getRepository('SywFrontMainBundle:Languages')->findBy(array('active' => 1), array('language' => 'ASC'));
     $metatitle = $this->get('translator')->trans('The user profile', array(), 'fos_user_profile_show');
     $title = $metatitle;
     $online = $this->getOnlineUsers();
     $host = $this->getHost();
     $return2 = $this->getTransForm($user);
     $return1 = array('accountInfo' => $this->getAccountInfo(), 'language' => $language->getLanguage(), 'host' => $host, 'online' => $online, 'metatitle' => $metatitle, 'title' => $title, 'user' => $user, 'apiaccess' => $apiaccess, 'userprofile' => $userProfile, 'machines' => $machines, 'languages' => $languages);
     return $this->render('FOSUserBundle:Profile:show.html.twig', array_merge($return1, $return2));
 }