Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
ProfileController Class Reference
Inheritance diagram for ProfileController:
Controller BaseController

Public Member Functions

 actionProfile ()
 actionEdit ()
 actionChangepassword ()
 actionApproveEmail ($email, $key)
 loadUser ()

Public Attributes

 $defaultAction = 'profile'
- Public Attributes inherited from Controller
 $menu = array()
 $breadcrumbs = array()
- Public Attributes inherited from BaseController
 $layout = '//layouts/gportal'
 $mailLayout = '//layouts/mail'

Additional Inherited Members

- Protected Member Functions inherited from BaseController
 beforeAction ($action)

Detailed Description

Definition at line 3 of file ProfileController.php.

Member Function Documentation

ProfileController::actionChangepassword ( )

Change password

Definition at line 98 of file ProfileController.php.

References UserModule\encrypting(), User\model(), UserModule\t(), and UActiveForm\validate().

{
$model = new UserChangePassword;
if (Yii::app()->user->id) {
// ajax validator
if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
echo UActiveForm::validate($model);
Yii::app()->end();
}
if (isset($_POST['UserChangePassword'])) {
$model->attributes = $_POST['UserChangePassword'];
if ($model->validate()) {
$new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
$new_password->password = UserModule::encrypting($model->password);
$new_password->activkey = UserModule::encrypting(microtime() . $model->password);
$new_password->save();
Yii::app()->user->setFlash('passwordChangeMessage', UserModule::t("New password is saved."));
if (isset($_GET['return_url'])) {
$this->redirect($_GET['return_url']);
}
$this->redirect(array("profile"));
}
}
$this->render('changepassword', array('model' => $model));
}
}
ProfileController::actionEdit ( )

Updates a particular model. If update is successful, the browser will be redirected to the 'view' page.

Definition at line 29 of file ProfileController.php.

References UserModule\encrypting(), loadUser(), UserModule\t(), and UActiveForm\validate().

{
$user = $this->loadUser();
if (!$user) {
throw new CHttpException(400);
}
$profile = $user->profile;
// ajax validator
if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
echo UActiveForm::validate(array($user, $profile));
Yii::app()->end();
}
if (isset($_POST['User'], $_POST['Profile'])) {
//save old email in case it was changed, for future validation
$oldEmail = $user->email;
$user->attributes = $_POST['User'];
$profile->attributes = $_POST['Profile'];
$uv = $user->validate();
$pv = $profile->validate();
if ($uv && $pv) {
$profile->save();
if(isset($_POST['Profile']['firstname'])){
Yii::app()->user->firstname = $_POST['Profile']['firstname'];
}
if(isset($_POST['Profile']['lastname'])){
Yii::app()->user->lastname = $_POST['Profile']['lastname'];
}
if(isset($_POST['User']['email'])){
Yii::app()->user->email = $_POST['User']['email'];
}
if ($oldEmail != $user->email) {
$newEmail = $user->email;
$user->activkey = UserModule::encrypting($newEmail . $user->password . microtime());
if(Yii::app()->getModule('user')->profileEditUrl[Yii::app()->language] !== false){
$activation_url = Yii::app()->createAbsoluteUrl(Yii::app()->getModule('user')->profileEditUrl[Yii::app()->language])."?approveEmail=1&email={$newEmail}&key={$user->activkey}";
}else{
$activation_url = Yii::app()->createAbsoluteUrl('/user/profile/approveEmail', array('email' => $newEmail, 'key' => $user->activkey));
}
$subject = UserModule::t("Email address changed.");
$message = $this->renderMail('/mail_templates/approve_email', $subject, array('activation_url' => $activation_url));
$notification = new Notification($subject, $message, array(new EmailRecipient($newEmail, Yii::app()->getModule('user')->activationEmail, '', true)));
Yii::app()->notificationManager->notifyAbout($notification);
Yii::app()->user->setFlash(
'profileMessage',
UserModule::t("Changes is saved. To activate your new email please confirm it in mail which was sent to {email}", array('{email}' => $newEmail))
);
} else {
Yii::app()->user->setFlash('profileMessage', UserModule::t("Changes is saved."));
}
$user->update(array('status', 'username', 'activkey'));
} else {
Yii::app()->user->setState('User', array('attributes' => $user->attributes, 'errors' => $user->getErrors()));
Yii::app()->user->setState('Profile', array('attributes' => $profile->attributes, 'errors' => $profile->getErrors()));
}
}
/* if is set returl_url - we heed to redirect user there */
if (isset($_REQUEST['return_url'])) {
$this->redirect($_REQUEST['return_url']);
}
$this->render('edit');
}
ProfileController::actionProfile ( )

Shows a particular model.

Definition at line 15 of file ProfileController.php.

References loadUser().

{
$model = $this->loadUser();
$this->render('profile', array(
'model' => $model,
'profile' => $model->profile,
));
}
ProfileController::loadUser ( )

Returns the data model based on the primary key given in the GET variable. If the data model is not found, an HTTP exception will be raised.

Parameters
integerthe primary key value. Defaults to null, meaning using the 'id' GET variable

Definition at line 147 of file ProfileController.php.

References User\model().

Referenced by actionEdit(), and actionProfile().

{
if ($this->_model === null) {
if (Yii::app()->user->id) {
$this->_model = RegistrationForm::model()->findByPk(Yii::app()->user->id);
}
if ($this->_model === null) {
$this->redirect(Yii::app()->controller->module->loginUrl);
}
}
return $this->_model;
}

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