Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Sign in validator
- * This validator checks if user has correct data for login
- *
- * @package nt
- * @subpackage user
- * @author Joao Correia
- * @version SVN: $Id: myJoinCondValidator.class.php 48 2005-12-17 10:51:26Z joaocorreia $
- */
- class signinValidator extends sfValidator
- {
- protected function configure($options = array(), $messages = array())
- {
- $this->addMessage('auth_failed', 'Autentication failed');
- // $this->addOption('email_in_db');
- // $this->setOption('empty_value', '');
- }
- protected function doClean($value)
- {
- $request = sfContext::getInstance()->getRequest()->getParameter('signin');
- $username = $request['username'];
- $password = $request['password'];
- $clean = (string) $value;
- // Check if user exists in email addresses with status = 0, 2 or 3 ! Very important
- $c = new Criteria();
- $c->add(EmailPeer::EMAIL, $username);
- $c->add(EmailPeer::EMAIL_STATUS,array('0', '2', '3'), Criteria::IN);
- $emails = EmailPeer::doSelect($c);
- // Ouch ouch magic stuff, have to check if there are many users with same e-mail
- // and try to figure out wich one is trying to identify. This is just for the case
- // of several users with same email in status 0 (Primary Unconfirmed)
- // Before changing ... think what are you doing and implications ! at least during 30min
- foreach ($emails as $email)
- {
- // If email exists let check password
- if ($email)
- {
- $user = UserPeer::retrieveByPK($email->getUserId());
- // Check if password is correct
- if (sha1($user->getSalt().$password) == $user->getSha1Password())
- {
- $auth = sfContext::getInstance()->getUser();
- $auth->setAuthenticated(true);
- $auth->setAttribute('user_id', $user->getId());
- return true;
- }
- }
- // End foreach
- }
- throw new sfValidatorError($this, 'auth_failed', array('value' => $value, 'auth_failed' => $this->getOption('auth_failed')));
- }
- // END
- }
- ?>
Add Comment
Please, Sign In to add comment