Exemplo n.º 1
0
 /**
  * Profile index
  *
  * @return mixed
  */
 public function actionIndex()
 {
     // profile
     $profileForm = UserForm::findOne(Yii::$app->user->getId());
     $profileForm->setScenario('profile');
     $ret = $this->performAjaxValidation($profileForm);
     if (is_array($ret)) {
         // AJAX validation
         return $ret;
     }
     $dataLoaded = $profileForm->load(Yii::$app->request->post());
     $profileForm->uploadedAvatar = UploadedFile::getInstance($profileForm, 'uploadedAvatar');
     if ($dataLoaded && $profileForm->validate()) {
         // change user's profile
         return $this->changeProfile($profileForm);
     }
     // change password
     $changePasswordForm = new ChangePasswordForm();
     $ret = $this->performAjaxValidation($changePasswordForm);
     if (is_array($ret)) {
         // AJAX validation
         return $ret;
     }
     if ($changePasswordForm->load(Yii::$app->request->post()) && $changePasswordForm->validate()) {
         // change user's password
         return $this->changePassword($changePasswordForm);
     }
     return $this->render('index', ['profileForm' => $profileForm, 'changePasswordForm' => $changePasswordForm]);
 }
Exemplo n.º 2
0
 /**
  * Tests user  update form
  *
  * @depends testCreateUser
  */
 public function testUpdateUser()
 {
     /* @var $user UserForm */
     $user = UserForm::findOne($this->getModule('Yii2')->grabFixture('users', 'activeUser1')->id);
     $this->assertInstanceOf(UserForm::className(), $user);
     $user->setScenario('update');
     $oldPassword = $user->password;
     // remove role
     $user->roles = [];
     $this->assertFalse($user->validate());
     $this->assertArrayHasKey('roles', $user->getErrors(), 'Check empty roles');
     $user->roles[] = 'admin';
     // generate new password
     $user->generateRandomPassword = true;
     $user->sendNotification = true;
     $result = $this->userModule->updateUser($user);
     $this->assertTrue($result);
     $this->assertNotEquals($oldPassword, $user->password);
     // user can authenticate
     $this->assertTrue($user->canSignIn());
     return $user;
 }