daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Sign in validator
  5.  * This validator checks if user has correct data for login
  6.  *
  7.  * @package    nt
  8.  * @subpackage user
  9.  * @author     Joao Correia
  10.  * @version    SVN: $Id: myJoinCondValidator.class.php 48 2005-12-17 10:51:26Z joaocorreia $
  11.  */
  12.  
  13.  class signinValidator extends sfValidator
  14.  {
  15.  
  16. protected function configure($options = array(), $messages = array())
  17.   {
  18.     $this->addMessage('auth_failed', 'Autentication failed');  
  19.  //   $this->addOption('email_in_db');
  20. //    $this->setOption('empty_value', '');
  21.   }
  22.  
  23.  
  24.  protected function doClean($value)
  25.   {    
  26.    
  27.     $request  = sfContext::getInstance()->getRequest()->getParameter('signin');
  28.     $username = $request['username'];
  29.     $password = $request['password'];
  30.    
  31.     $clean = (string) $value;  
  32.    
  33.    
  34. // Check if user exists in email addresses with status = 0, 2 or 3 ! Very important
  35.     $c = new Criteria();
  36.     $c->add(EmailPeer::EMAIL, $username);  
  37.     $c->add(EmailPeer::EMAIL_STATUS,array('0', '2', '3'), Criteria::IN);  
  38.     $emails = EmailPeer::doSelect($c);    
  39.        
  40.     // Ouch ouch magic stuff, have to check if there are many users with same e-mail
  41.     // and try to figure out wich one is trying to identify. This is just for the case
  42.     // of several users with same email in status 0 (Primary Unconfirmed)
  43.     // Before changing ... think what are you doing and implications ! at least during 30min
  44.  
  45.     foreach ($emails as $email)
  46.     {
  47.        
  48.       // If email exists let check password
  49.         if ($email)
  50.         {
  51.           $user =  UserPeer::retrieveByPK($email->getUserId());  
  52.           // Check if password is correct
  53.           if (sha1($user->getSalt().$password) == $user->getSha1Password())
  54.           {
  55.            $auth  = sfContext::getInstance()->getUser();
  56.            $auth->setAuthenticated(true);
  57.            $auth->setAttribute('user_id', $user->getId());  
  58.            return true;
  59.           }
  60.            
  61.         }
  62.  
  63.     // End foreach 
  64.     }
  65.  
  66.   throw new sfValidatorError($this, 'auth_failed', array('value' => $value, 'auth_failed' => $this->getOption('auth_failed')));
  67.  
  68.   }
  69.  
  70.    
  71. // END  
  72. }
  73.  
  74. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand