Location: PHPKode > projects > Yup! - Yii based filehoster > yup/protected/components/UserIdentity.php
<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
    
    const ERROR_NOT_ACTIVATED = 3;
    
    
    public $id;
    
    public $email;
    
    
    public function getId()
    {
        return $this->id;
    }
    
    public function getName()
    {
        return $this->email;
    }
    
    
    public function __construct($email, $password)
    {
        $this->email    = $email;
        $this->password = $password;
    }
    
    
	public function authenticate()
	{
	    // Versuchen User anhand der E-Mail zu holen
	    $user = User::model()->findByAttributes(array('email' => $this->email));
	    
	    // Email checken
		if(!is_object($user)) {
			$this->errorCode = self::ERROR_USERNAME_INVALID;
		}
		// Passwort checken
		else if($user->password != sha1($user->salt . $this->password)) {
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
		}
		// Checken ob aktiviert
		else if (is_object($user->activation)) {
		    $this->errorCode = self::ERROR_NOT_ACTIVATED;
		}
		// ... alles gut
		else {
			$this->errorCode = self::ERROR_NONE;
			$this->id = $user->id;
			
			// Model in User-Instanz speichern
			Yii::app()->user->setState('model', $user);
		}
		
		return !$this->errorCode;
	}
}
Return current item: Yup! - Yii based filehoster