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

Public Member Functions

 __construct ($service)
 authenticate ()
 getId ()
 getErrorDescription ()
 onNewUser (Account $account)

Public Attributes

const ERROR_NOT_AUTHENTICATED = 3
 $user = null
 $session = null
 $account = null
 $email

Protected Attributes

 $service
 $id

Detailed Description

Definition at line 5 of file SUserIdentity.php.

Constructor & Destructor Documentation

SUserIdentity::__construct (   $service)

Constructor.

Parameters
EAuthServiceBase$servicethe authorization service instance.

Definition at line 31 of file SUserIdentity.php.

{
$this->service = $service;
}

Member Function Documentation

SUserIdentity::authenticate ( )

Authenticates a user based on service. This method is required by IUserIdentity.

Returns
boolean whether authentication succeeds.

Definition at line 41 of file SUserIdentity.php.

References PersonalisationAttribute\flatListForUser(), Account\model(), and Profile\model().

{
if ($this->service->isAuthenticated) {
$id = $this->service->id;
$service = $this->service->serviceName;
$this->account = Account::model()->findByAttributes(array('service' => $service, 'service_id' => $id));
if (!$this->account) {
$this->account = Account::create($this->service);
if ($this->account) {
if (User::create($this->account, $this->service)) {
$this->onNewUser($this->account);
}
}
}
if ($this->account->user->status == 1) {
$this->id = $this->account->user_id;
$this->username = $this->account->user->username;
$this->email = $this->account->user->email;
/*echo __FILE__.'<br/>';*/
//if new data from service
$data = (object)array_merge((array)$this->account->data, $this->service->getAttributes());
$this->account->data = $data;
$this->account->save();
$profile = Profile::model()->findByAttributes(array('user_id'=>$this->account->user->id));
if (!empty($data->firstname)) {
$profile->firstname = $data->firstname;
$this->account->user->profile->firstname = $data->firstname;
}
if (!empty($data->lastname)) {
$profile->lastname = $data->lastname;
$this->account->user->profile->lastname = $data->lastname;
}
if (!empty($data->gender)) {
$profile->gender = $data->gender;
$this->account->user->profile->gender = $data->gender;
}
if (!$profile->save(false)) {
throw new Exception(print_r($profile->getErrors(), true));
}
Yii::app()->getModule('personalisation');
$this->setPersistentStates(array(
'email' => $this->email,
'firstname' => $this->account->user->profile->firstname,
'lastname' => $this->account->user->profile->lastname,
'gender' => $this->account->user->profile->gender,
'personalisation' => PersonalisationAttribute::flatListForUser($this->account->user->id)
));
$this->errorCode = self::ERROR_NONE;
} else {
$this->errorCode = self::ERROR_NOT_AUTHENTICATED;
}
}
else {
$this->errorCode = self::ERROR_NOT_AUTHENTICATED;
}
return !$this->errorCode;
}
SUserIdentity::getId ( )

Returns the unique identifier for the identity. This method is required by IUserIdentity.

Returns
string the unique identifier for the identity.

Definition at line 112 of file SUserIdentity.php.

{
return $this->id;
}

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