<commit_before><?php  

/**
 * citoyen actions.
 *
 * @package    cpc
 * @subpackage citoyen
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class citoyenActions extends sfActions
{  
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->citoyens_list = Doctrine::getTable('Citoyen')
      ->createQuery('c')
      ->where('c.is_active = ?', true)
      ->execute();
    $response = $this->getResponse();
    $response->setTitle('Liste des citoyens inscrits'); 
  }
  
  public function executeShow(sfWebRequest $request)
  {
    $slug = $request->getParameter('slug');
    $this->Citoyen = Doctrine::getTable('Citoyen')->findOneBySlug($slug);
    $this->forward404Unless($this->Citoyen->is_active);
    $response = $this->getResponse();
    $response->setTitle('Profil de '.$this->Citoyen->login); 
  }
  
  // Inscription
  public function executeNew(sfWebRequest $request)
  {
    if (!$this->getUser()->isAuthenticated()) {
      $this->form = new InscriptionForm();
      if ($request->isMethod('post'))
      {        
        $this->form->bind($request->getParameter('citoyen'));
        
        if ($this->form->isValid())
        {
          $this->form->save();
          
          $this->Citoyen = Doctrine::getTable('Citoyen')->findOneByEmail($this->form->getValue('email'));
          $this->connexion($this->Citoyen);
          $this->Citoyen->activation_id = md5(time()*rand());
          $this->Citoyen->save();
          
          $this->getComponent('mail', 'send', 
            array('subject'=>'Inscription NosDéputés.fr', 
            'to'=>array($this->form->getValue('email')), 
            'partial'=>'inscription', 
            'mailContext'=>array('activation_id' => $this->Citoyen->activation_id) 
            ));
          
          $this->getUser()->setFlash('notice', 'Vous allez recevoir un email de confirmation. Pour finaliser votre inscription, veuillez cliquer sur le lien d\'activation contenu dans cet email.');
          $this->redirect('@homepage');
        }
      }
    }
    else if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('is_active') == true)
    {
      $slug = $this->getUser()->getAttribute('slug');
      $this->getUser()->setFlash('notice', 'Vous êtes déja inscrit');
      $this->redirect('@citoyen?slug='.$slug);
    }
    else
    {
      $this->getUser()->setFlash('notice', 'Vous allez recevoir un email de confirmation. Pour finaliser votre inscription, veuillez cliquer sur le lien d\'activation contenu dans cet email.');
      $this->redirect('@homepage');
    }
  }
  
  /* public function executeRenvoimailactivation(sfWebRequest $request)
  {
    $id = $request->getParameter('user_id');
    
    $this->Citoyen = Doctrine::getTable('Citoyen')->findOneById($id);
    
    if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('user_id') == $id)
    {
      $this->getComponent('mail', 'send', array(
                  'subject'=>'Inscription NosDéputés.fr', 
                  'to'=>array($this->Citoyen->email), 
                  'partial'=>'inscription', 
                  'mailContext'=>array('activation_id' => $this->Citoyen->activation_id) 
                  ));
      $this->getUser()->setFlash('notice', 'Un email de confirmation vient de vous être envoyé.');
      $this->redirect($request->getReferer());
    }
    else { $this->forward404(); }
  } */
  
  public function executeEdit(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('is_active') == true) {
    
      $user = Doctrine::getTable('Citoyen')->findOneById($this->getUser()->getAttribute('user_id'));
    
      $this->form = new EditUserForm($user);
      
      if ($request->isMethod('put'))
      {
        $this->form->bind($request->getParameter('citoyen'));
        
        if ($this->form->isValid())
        {
          $this->form->save();
          $this->getUser()->setFlash('notice', 'Vous avez modifié votre profil avec succès');
          $this->redirect('@citoyen?slug='.$user->slug);
        }
      }
    }
    else { $this->redirect('@signin'); }
  }
  
  public function executeActivation(sfWebRequest $request)
  {
    $this->activation_id = $request->getParameter('activation_id');
    
    if ($this->getUser()->isAuthenticated() and ($this->getUser()->getAttribute('is_active') == true)) 
    {
      $this->forward404();
    }
    
    if (Doctrine::getTable('Citoyen')->findOneByActivationId($this->activation_id))
    {
      $user = Doctrine::getTable('Citoyen')->findOneByActivationId($this->activation_id);
      
      if (!$user->is_active == true)
      {
        $this->form = new MotdepasseForm($user);
        
        if ($request->isMethod('put'))
        {
          $values = $request->getParameter('citoyen');
          $values["password"] = <PASSWORD>($values["password"]);
          $values["password_bis"] = <PASSWORD>($values["<PASSWORD>"]);
          
          $this->form->bind($values);
          
          if ($this->form->isValid())
          {
            $this->form->save();
            $user->is_active = true;
            $user->activation_id = null;
            $user->save();
            if ($this->getUser()->isAuthenticated())
            {
              $this->getUser()->setAttribute('is_active', true);
              $this->getUser()->setFlash('notice', 'Votre compte a été activé avec succès');
              $this->redirect('@citoyen?slug='.$user->slug);
            }
            else
            {
              $this->connexion($user);
              $this->getUser()->setFlash('notice', 'Votre compte a été activé avec succès');
              $this->redirect('@citoyen?slug='.$user->slug);
            }
            $q = Doctrine_Query::create()
            ->update('Commentaire')
            ->set('is_public', 'true')
            ->where('citoyen_id = '.$user->id);
            $q->execute();
          }
        }
      }
      else
      {
        $this->forward404();
      }
    }
    else
    {
      $this->forward404();
    }
  }
  /* 
  public function executeAddcirco(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      $nom_circo = $request->getParameter('nom_circo');
      $num_circo = $request->getParameter('num_circo');
      $user = Doctrine::getTable('Citoyen')->findOneById($this->getUser()->getAttribute('user_id'));
      $user->nom_circo = $nom_circo;
      $user->num_circo = $num_circo;
      $user->save();
      $this->redirect('@citoyen?slug='.$user->slug);
    }<commit_msg>update des commentaires en is_public après activation citoyen<commit_after><?php  

/**
 * citoyen actions.
 *
 * @package    cpc
 * @subpackage citoyen
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class citoyenActions extends sfActions
{  
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->citoyens_list = Doctrine::getTable('Citoyen')
      ->createQuery('c')
      ->where('c.is_active = ?', true)
      ->execute();
    $response = $this->getResponse();
    $response->setTitle('Liste des citoyens inscrits'); 
  }
  
  public function executeShow(sfWebRequest $request)
  {
    $slug = $request->getParameter('slug');
    $this->Citoyen = Doctrine::getTable('Citoyen')->findOneBySlug($slug);
    $this->forward404Unless($this->Citoyen->is_active);
    $response = $this->getResponse();
    $response->setTitle('Profil de '.$this->Citoyen->login); 
  }
  
  // Inscription
  public function executeNew(sfWebRequest $request)
  {
    if (!$this->getUser()->isAuthenticated()) {
      $this->form = new InscriptionForm();
      if ($request->isMethod('post'))
      {        
        $this->form->bind($request->getParameter('citoyen'));
        
        if ($this->form->isValid())
        {
          $this->form->save();
          
          $this->Citoyen = Doctrine::getTable('Citoyen')->findOneByEmail($this->form->getValue('email'));
          $this->connexion($this->Citoyen);
          $this->Citoyen->activation_id = md5(time()*rand());
          $this->Citoyen->save();
          
          $this->getComponent('mail', 'send', 
            array('subject'=>'Inscription NosDéputés.fr', 
            'to'=>array($this->form->getValue('email')), 
            'partial'=>'inscription', 
            'mailContext'=>array('activation_id' => $this->Citoyen->activation_id) 
            ));
          
          $this->getUser()->setFlash('notice', 'Vous allez recevoir un email de confirmation. Pour finaliser votre inscription, veuillez cliquer sur le lien d\'activation contenu dans cet email.');
          $this->redirect('@homepage');
        }
      }
    }
    else if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('is_active') == true)
    {
      $slug = $this->getUser()->getAttribute('slug');
      $this->getUser()->setFlash('notice', 'Vous êtes déja inscrit');
      $this->redirect('@citoyen?slug='.$slug);
    }
    else
    {
      $this->getUser()->setFlash('notice', 'Vous allez recevoir un email de confirmation. Pour finaliser votre inscription, veuillez cliquer sur le lien d\'activation contenu dans cet email.');
      $this->redirect('@homepage');
    }
  }
  
  /* public function executeRenvoimailactivation(sfWebRequest $request)
  {
    $id = $request->getParameter('user_id');
    
    $this->Citoyen = Doctrine::getTable('Citoyen')->findOneById($id);
    
    if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('user_id') == $id)
    {
      $this->getComponent('mail', 'send', array(
                  'subject'=>'Inscription NosDéputés.fr', 
                  'to'=>array($this->Citoyen->email), 
                  'partial'=>'inscription', 
                  'mailContext'=>array('activation_id' => $this->Citoyen->activation_id) 
                  ));
      $this->getUser()->setFlash('notice', 'Un email de confirmation vient de vous être envoyé.');
      $this->redirect($request->getReferer());
    }
    else { $this->forward404(); }
  } */
  
  public function executeEdit(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated() and $this->getUser()->getAttribute('is_active') == true) {
    
      $user = Doctrine::getTable('Citoyen')->findOneById($this->getUser()->getAttribute('user_id'));
    
      $this->form = new EditUserForm($user);
      
      if ($request->isMethod('put'))
      {
        $this->form->bind($request->getParameter('citoyen'));
        
        if ($this->form->isValid())
        {
          $this->form->save();
          $this->getUser()->setFlash('notice', 'Vous avez modifié votre profil avec succès');
          $this->redirect('@citoyen?slug='.$user->slug);
        }
      }
    }
    else { $this->redirect('@signin'); }
  }
  
  public function executeActivation(sfWebRequest $request)
  {
    $this->activation_id = $request->getParameter('activation_id');
    
    if ($this->getUser()->isAuthenticated() and ($this->getUser()->getAttribute('is_active') == true)) 
    {
      $this->forward404();
    }
    
    if (Doctrine::getTable('Citoyen')->findOneByActivationId($this->activation_id))
    {
      $user = Doctrine::getTable('Citoyen')->findOneByActivationId($this->activation_id);
      
      if (!$user->is_active == true)
      {
        $this->form = new MotdepasseForm($user);
        
        if ($request->isMethod('put'))
        {
          $values = $request->getParameter('citoyen');
          $values["password"] = <PASSWORD>($values["password"]);
          $values["password_bis"] = <PASSWORD>($values["password_bis"]);
          
          $this->form->bind($values);
          
          if ($this->form->isValid())
          {
            $this->form->save();
            $user->is_active = true;
            $user->activation_id = null;
            $user->save();
            Doctrine_Query::create()  
            ->update('Commentaire')
            ->set('is_public', '?', true)
            ->where('citoyen_id = ?', $user->id)
            ->execute();
            if ($this->getUser()->isAuthenticated())
            {
              $this->getUser()->setAttribute('is_active', true);
              $this->getUser()->setFlash('notice', 'Votre compte a été activé avec succès');
              $this->redirect('@citoyen?slug='.$user->slug);
            }
            else
            {
              $this->connexion($user);
              $this->getUser()->setFlash('notice', 'Votre compte a été activé avec succès');
              $this->redirect('@citoyen?slug='.$user->slug);
            }
          }
        }
      }
      else
      {
        $this->forward404();
      }
    }
    else
    {
      $this->forward404();
    }
  }
  /* 
  public function executeAddcirco(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      $nom_circo = $request->getParameter('nom_circo');
      $num_circo = $request->getParameter('num_circo');
      $user = Doctrine::getTable('Citoyen')->findOneById($this->getUser()->getAttribute('user_id'));
      $user->nom_circo = $nom_circo;
      $user->num_circo = $num_circo;
      $user->save();
      $this->redirect('@citoyen?slug='.$user->slug);
    }
{'fraction_non_alphanumeric': 0.18103001111522787, 'fraction_numerical': 0.005187106335679882, 'mean_word_length': 2.526522079958192, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 330, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '412582', 'n_tokens_mistral': 4269, 'n_tokens_neox': 4158, 'n_words': 630}