/**
  * 
  * @param Token $token
  * @return boolean
  */
 protected function isTokenOwner(Token $token)
 {
     foreach ($this->getCookieTokens() as $value) {
         if ($token->getToken() == $value) {
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * 
  * @param string $token
  * @return Token
  */
 public function newToken($token)
 {
     $entity = new Token();
     $entity->setCode($this->generateNewCode());
     $entity->setToken($token);
     $entity->setData(['rights' => ['account', 'characters']]);
     $this->_em->persist($entity);
     $this->_em->flush();
     return $entity;
 }
Exemple #3
0
 /**
  * 
  * @param Token $token
  * @return array
  */
 public function getItems(Token $token = null)
 {
     if ($token === null) {
         return $this->items;
     }
     $items = [];
     foreach ($this->items as $item) {
         if ($item->getRight() == '' || $token->hasRight($item->getRight())) {
             $items[] = $item;
         }
     }
     return $this->trimSeparators($items);
 }
 /**
  * @Route("/send_email", name="send_email")
  * @Method("POST")
  */
 public function SendEmailAction(Request $request)
 {
     $random = openssl_random_pseudo_bytes(24, $cstrong);
     $nip = bin2hex($random);
     $expDate = new \DateTime();
     $expDate->format('Y-m-d H:i:s');
     $em = $this->getDoctrine()->getManager();
     $user = $em->getRepository('AppBundle:User')->findOneBy(array('username' => $request->get('email')));
     if (empty($user)) {
         return $this->render('AppBundle:Security:retrieve_password.html.twig', array('blank' => 'blank'));
     }
     $token = new Token();
     $token->setTokenId($nip);
     $token->setExpDate($expDate);
     $token->setUserId($user);
     $em->persist($token);
     $em->flush();
     // die($token);
     $message = \Swift_Message::newInstance()->setSubject('Mensaje de confirmación')->setFrom('*****@*****.**')->setTo($request->get('email'))->setBody($this->renderView('AppBundle:Security:message.html.twig', array('nip' => $nip, 'id' => $user->getUserId())), 'text/html');
     $this->get('mailer')->send($message);
     return $this->redirect($this->generateUrl('login_route', array('success' => '1')));
 }
Exemple #5
0
 /**
  * 
  * @param string $name
  * @return boolean
  */
 public function isAllowedCharacter($name)
 {
     $name = (string) $name;
     if ($this->isOwner) {
         return true;
     }
     if (empty($this->token)) {
         return false;
     }
     if (!$this->token->hasRight('other.limit_characters')) {
         return true;
     }
     return $this->token->hasRight('character/' . $name);
 }