Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
UserIdentity Class Reference

Public Member Functions

 authenticate ()
 getId ()

Public Attributes

 $email
 $firstname
 $lastname
 $gender
 $personalisation
const ERROR_AUTH_FIELD_INVALID = 3
const ERROR_STATUS_NOTACTIV = 4
const ERROR_STATUS_BAN = 5

Detailed Description

UserIdentity represents the data needed to identity a user. It contains the authentication method that checks if the provided data can identity the user.

Definition at line 8 of file UserIdentity.php.

Member Function Documentation

UserIdentity::authenticate ( )

Authenticates a user. The example implementation makes sure if the username and password are both 'demo'. In practical applications, this should be changed to authenticate against some persistent user identity storage (e.g. database).

Returns
boolean whether authentication succeeds.

Definition at line 39 of file UserIdentity.php.

References PersonalisationAttribute\flatListForUser(), and User\model().

{
if (Yii::app()->getModule('user')->authField == 'email') {
$user = User::model()->with('profile')->notsafe()->findByAttributes(array('email' => $this->username));
} else {
$user = User::model()->with('profile')->notsafe()->findByAttributes(array('username' => $this->username));
}
if ($user === null)
$this->errorCode = self::ERROR_AUTH_FIELD_INVALID;
else if (Yii::app()->getModule('user')->encrypting($this->password) !== $user->password)
$this->errorCode = self::ERROR_PASSWORD_INVALID;
else if ($user->status == 0 && Yii::app()->getModule('user')->loginNotActiv == false)
$this->errorCode = self::ERROR_STATUS_NOTACTIV;
else if ($user->status == -1)
$this->errorCode = self::ERROR_STATUS_BAN;
else {
$this->_id = $user->id;
$this->email = $user->email;
$this->username = !empty($user->username) ? $user->username : $user->email;
$this->errorCode = self::ERROR_NONE;
Yii::app()->getModule('personalisation');
$this->setPersistentStates(array(
'email' => $this->email,
'firstname' => $user->profile->firstname,
'lastname' => $user->profile->lastname,
'gender' => $user->profile->gender,
'personalisation' => PersonalisationAttribute::flatListForUser($user->id)
));
}
return !$this->errorCode;
}
UserIdentity::getId ( )
Returns
integer the ID of the user record

Definition at line 76 of file UserIdentity.php.

{
return $this->_id;
}

The documentation for this class was generated from the following file: