/** * Finds user by [[username, email]] * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(['username' => $this->username, 'email' => $this->email, 'active' => true]); } return $this->_user; }
/** * Задание пароля суперпользователя */ public function actionPassword() { do { $pass = $this->prompt(Yii::t('main/app', 'Input root password:'******'main/app', 'Confirm root password:'), ["required" => true]); $user = User::findOne(["username" => "root"]); $user->password = $pass; $user->confirm_password = $confPass; $res = $user->save(); if (!$res) { foreach ($user->getErrors() as $errorArr) { foreach ($errorArr as $error) { $this->stdout($error . "\n", Console::FG_RED); } } } } while (!$res); return 0; }
/** * Тест просмотра пользователя */ public function testViewUser() { $model = User::findOne(["username" => "root"]); $route = $this->viewRoute; $this->getRequest([$route, "id" => $model->id]); $res = Yii::$app->runAction($route, ["id" => $model->id]); $this->specify('action result is text', function () use($res) { $this->assertTrue(strlen($res) > 0); }); }