Changeset 54

Show
Ignore:
Timestamp:
05/25/08 22:40:52 (2 years ago)
Author:
nperriault
Message:

Moved signing and activation email resending forms, added use of sfContext::set() to store form instance which can now be accessible from templates, layout, partial and so on (useful for global error messages in the layout for example)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/main/lib/myActions.class.php

    r48 r54  
    382382    } 
    383383  } 
     384   
     385  /** 
     386   * Post execution: if a form has been set, we put it in sfContext to be able  
     387   * to reference it in the layout or partials 
     388   * 
     389   */ 
     390  public function postExecute() 
     391  { 
     392    if (isset($this->form) && $this->form instanceof sfForm) 
     393    { 
     394      $this->getContext()->set('form', $this->form); 
     395    } 
     396  } 
    384397 
    385398} 
  • trunk/apps/main/modules/sfGuardAuth/actions/actions.class.php

    r53 r54  
    280280  public function executeResendActivation(sfWebRequest $request) 
    281281  { 
     282    $this->form = new ResendActivationForm(); 
     283     
    282284    if ($request->isMethod('post')) 
    283285    { 
    284       $email = $request->getParameter('email'); 
    285       $user = sfGuardUserPeer::retrieveByEmail($email); 
     286      // Recaptcha parameters 
     287      $captcha = array( 
     288        'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 
     289        'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'), 
     290      ); 
     291      $params = array_merge($request->getParameter('user', array()), array('captcha' => $captcha)); 
    286292       
    287       $c = new Criteria; 
    288       $c->add(ActivationPeer::USER_ID, $user->getId()); 
    289       $activation = ActivationPeer::doSelectOne($c); 
    290       $request->setAttribute('activation', $activation); 
     293      $this->form->bind($params); 
    291294       
    292       $mailSent = $this->sendSwiftSmtpPlainMail('mail', 'resendActivation', 
    293                                                 $user->getEmail(), 
    294                                                 $this->__('Please activate your account')); 
    295       if (!$mailSent) 
    296       { 
    297         $request->setError('errors', $this->__('We were unable to send you an email. We are digging the problem, stay tuned.')); 
    298         return sfView::SUCCESS; 
    299       } 
    300       $this->getUser()->setFlash('notice', $this->__('Your activation mail has been sent to '.$user->getEmail())); 
    301       $this->redirect('@homepage'); 
     295      if ($this->form->isValid()) 
     296      { 
     297        $user = sfGuardUserPeer::retrieveByEmail($params['email']); 
     298        $this->forward404Unless($user); // theoricaly, can't happen 
     299         
     300        $c = new Criteria(); 
     301        $c->add(ActivationPeer::USER_ID, $user->getId()); 
     302        $activation = ActivationPeer::doSelectOne($c); 
     303        $request->setAttribute('activation', $activation); 
     304         
     305        $mailSent = $this->sendSwiftSmtpPlainMail('mail', 'resendActivation', 
     306                                                  $user->getEmail(), 
     307                                                  $this->__('Please activate your account')); 
     308        if (!$mailSent) 
     309        { 
     310          $this->getUser()->setFlash('warning', $this->__('We were unable to send you an email. We are digging the problem, stay tuned.')); 
     311          return sfView::SUCCESS; 
     312        } 
     313        $this->getUser()->setFlash('notice', $this->__('Your activation mail has been sent to '.$user->getEmail())); 
     314        $this->redirect('@homepage'); 
     315      } 
    302316    } 
    303317  } 
     
    309323   
    310324  public function handleErrorRegister() 
    311   { 
    312     return sfView::SUCCESS; 
    313   } 
    314    
    315   public function handleErrorResendActivation() 
    316325  { 
    317326    return sfView::SUCCESS; 
     
    381390  } 
    382391   
    383   public function validateResendActivation() 
    384   { 
    385     if ($this->getRequest()->isMethod('post')) 
    386     { 
    387       $user = sfGuardUserPeer::retrieveByEmail(trim($this->getRequestParameter('email'))); 
    388       if (!$user) 
    389       { 
    390         $this->getRequest()->setError('errors', $this->__('This email has never been registered here')); 
    391         return false; 
    392       } 
    393        
    394       if ($user->getIsActive()) 
    395       { 
    396         $this->getRequest()->setError('errors', $this->__('This account is already activated. You do not need an activation mail to log in.')); 
    397         return false; 
    398       } 
    399        
    400       $c = new Criteria; 
    401       $c->add(ActivationPeer::USER_ID, $user->getId()); 
    402       $activation = ActivationPeer::doSelectOne($c); 
    403       if (!$activation) 
    404       { 
    405         $this->getRequest()->setError('errors', $this->__('We cannot find your activation informations. This is badly weird.')); 
    406         $this->logMessage(sprintf('Account "%s" is weird. Check it.', $user->getUsername())); 
    407         return false; 
    408       } 
    409     } 
    410     return true; 
    411   } 
    412    
    413392} 
  • trunk/apps/main/modules/sfGuardAuth/templates/registerSuccess.php

    r53 r54  
    3131    <fieldset> 
    3232      <legend><?php echo __('Account informations') ?></legend> 
    33       <?php echo $form->renderGlobalErrors() ?> 
    3433      <?php echo $form['username']->renderRow() ?> 
    3534      <?php echo $form['email']->renderRow() ?> 
  • trunk/apps/main/modules/sfGuardAuth/templates/resendActivationSuccess.php

    r53 r54  
    2222    <fieldset> 
    2323      <legend><?php echo __('Account informations') ?></legend> 
    24       <?php echo $form->renderGlobalErrors() ?> 
    2524      <?php echo $form['email']->renderRow() ?> 
    26       <?php /* 
    27       <div class="form-row required"> 
    28         <label for="email"><?php echo __('Email address you provided at registration time') ?></label> 
    29         <?php echo input_tag('email', $sf_params->get('email')) ?> 
    30         <?php echo form_error('email') ?> 
    31       </div> 
    32       <div class="form-row required"> 
    33         <?php echo label_for('captcha', __('Security code')) ?> 
    34         <?php echo input_tag('captcha', null, 'id=captcha style=width:100px'); ?> 
    35         <?php echo cryptographp_picture() ?> 
    36         <?php echo cryptographp_reload() ?> 
    37         <?php echo form_error('captcha') ?> 
    38         <p class="form-help"> 
    39           <?php echo __('This codes aims at detecting if you are a bot or a human person.') ?> 
    40         </p> 
    41       </div> 
    42       */ ?> 
     25      <span class="form-help"><?php echo __('Enter the email address you entered when you have registered here.') ?></span> 
     26      <?php echo $form['captcha']->renderRow() ?> 
     27      <p class="form-help"> 
     28        <?php echo __('This codes aims at detecting if you are a bot or a human person.') ?> 
     29      </p> 
    4330      <p> 
    4431        <?php echo $form['_csrf_token'] ?> 
  • trunk/apps/main/modules/sfGuardAuth/templates/signinSuccess.php

    r53 r54  
    1515      <fieldset> 
    1616        <legend><?php echo __('Please sign in') ?></legend> 
    17         <?php echo $form->renderGlobalErrors() ?> 
    1817        <?php echo $form['username']->renderRow() ?> 
    1918        <?php echo $form['password']->renderRow() ?> 
  • trunk/apps/main/templates/_messages.php

    r48 r54  
    1 <?php /* 
    2 <?php if ($sf_request->hasErrors()): ?> 
     1<?php if ($sf_context->has('form') && $form = $sf_context->get('form') && $sf_context->get('form')->hasGlobalErrors()): ?> 
    32<div class="form-errors"> 
    43  <h4><?php echo __('Errors have been encountered') ?></h4> 
    5   <ul> 
    6   <?php foreach ($sf_request->getErrorNames() as $name): ?> 
    7     <li><?php echo $sf_request->getError($name) ?></li> 
    8   <?php endforeach; ?> 
    9   </ul> 
     4  <?php echo $sf_context->get('form')->renderGlobalErrors() ?> 
    105</div> 
    116<?php endif; ?> 
     7 
    128<?php if ($sf_user->hasFlash('notice')): ?> 
    139<p class="notice"> 
     
    1511</p> 
    1612<?php endif; ?> 
     13 
    1714<?php if ($sf_user->hasFlash('warning')): ?> 
    1815<p class="warning"> 
     
    2017</p> 
    2118<?php endif; ?> 
    22 */ ?> 
     19 
  • trunk/config/ProjectConfiguration.class.php

    r48 r54  
    77  public function setup() 
    88  { 
     9    sfWidgetFormSchema::setDefaultFormFormatterName('div'); 
     10     
    911    // symfonians constants definition 
    1012    if (!defined('SYMFONIANS_MAIN_DOMAIN'))