本文整理汇总了PHP中app\models\User::findByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findByUsername方法的具体用法?PHP User::findByUsername怎么用?PHP User::findByUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::findByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeValidate
/**
* @inheritdoc
*/
public function beforeValidate()
{
if (parent::beforeValidate()) {
if ($this->scenario == 'user-update') {
// Верификация должностей и пользователей
foreach ($this->position as $key => $positionId) {
if (!isset($this->user[$key])) {
continue;
}
if (!($position = Position::findOne($positionId))) {
continue;
}
if (is_numeric($this->user[$key])) {
$user = User::findIdentity($this->user[$key]);
} else {
$user = User::findByUsername(trim($this->user[$key]));
}
if (!$user) {
continue;
}
$this->_verifyPositions[] = ['positionId' => $position->id, 'userId' => $user->id];
}
if (empty($this->_verifyPositions)) {
$this->addError('position', 'Вы должны указать минимум одну должность');
}
}
return true;
}
return false;
}
示例2: getUser
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username, sha1($this->password));
}
return $this->_user;
}
示例3: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例4: getUser
/**
* Finds user by session's 'username'.
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername(Yii::$app->session->get('username'));
}
return $this->_user;
}
示例5: validateUsernameUnique
public function validateUsernameUnique()
{
$user = User::findByUsername($this->username);
if ($user) {
$this->addError('username', 'Username must be unique.');
}
}
示例6: getUser
/**
* @return User|null
*/
public function getUser()
{
if ($this->_user !== null) {
return $this->_user;
}
return $this->_user = User::findByUsername($this->email);
}
示例7: actionAssignRole
public function actionAssignRole($username, $roleName)
{
$user = User::findByUsername($username);
$auth = Yii::$app->authManager;
$role = $auth->getRole($roleName);
$auth->assign($role, $user);
}
示例8: testAUserCanBeFoundByUsername
public function testAUserCanBeFoundByUsername()
{
$createdUser = factory(User::class)->create(['username' => 'janedoe', 'name' => 'Jane Doe', 'created_timestamp_utc' => 1, 'updated_timestamp_utc' => 1]);
$foundUser = User::findByUsername('janedoe');
$this->assertEquals($createdUser->id, $foundUser->id);
$this->assertEquals($createdUser->username, $foundUser->username);
}
示例9: actionIndex
public function actionIndex()
{
//没登录就回到主页
if (Yii::$app->user->isGuest) {
return $this->render('/site/index');
}
//没加入队伍就到/team/error页面
if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") {
return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']);
}
$myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname;
$myteam = Team::findOne(['teamname' => $myteamname]);
//上传文件
$model = new UploadForm();
if (Yii::$app->request->isPost) {
if ($myteam->uploaded_time < 50) {
$model->sourcecode = UploadedFile::getInstance($model, 'sourcecode');
if ($id = $model->upload()) {
$myteam->uploaded_time++;
$myteam->save(false);
//上传成功就render到uploadsuccess页面
return $this->render('uploadsuccess', ['id' => $id]);
}
}
}
//上传文件$model,
return $this->render('index', ['model' => $model, 'myteam' => $myteam]);
//,'indexs'=>$indexs]);
}
示例10: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例11: actionUser
/**
* регистрация юзера по имейл
* если регистрация для покупки, то передаются параметры рекомендатель и урл
* @param type $affiliate_id
* @param type $url_id
* @return type
* @throws \yii\web\NotFoundHttpException
*/
public function actionUser($affiliate_id = null, $url_id = null)
{
$request = Yii::$app->request;
$model = new \app\models\registration\UserForm();
if ($request->isAjax && $model->load($request->post())) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load($request->post()) && $model->validate()) {
$user = User::findByUsername($model->email);
if (!$user) {
$user = $model->save();
}
$user->setCookie();
if ($affiliate_id === null || $url_id === null) {
Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту');
return $this->goHome();
}
$url = Url::findOne($url_id);
if (!$url) {
throw new \yii\web\NotFoundHttpException('Урл не найден');
}
$user->purchase($affiliate_id, $url);
return $this->redirect($url->link);
}
return $this->render('user', ['model' => $model]);
}
示例12: actionPerson
public function actionPerson()
{
$user = User::findByUsername('123');
var_dump($user);
die;
return $this->render('person');
}
示例13: actionIndex
public function actionIndex()
{
//没登录就回到主页
if (Yii::$app->user->isGuest) {
return $this->render('/site/index');
}
//没加入队伍就到/team/error页面
if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") {
return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']);
}
$myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname;
$myteam = Team::findOne(['teamname' => $myteamname]);
//上传文件
$model = new UploadForm();
if (Yii::$app->request->isPost) {
if ($myteam->uploaded_time < 50) {
$model->sourcecode = UploadedFile::getInstance($model, 'sourcecode');
if ($id = $model->upload_first_round()) {
return $this->render('uploadsuccess');
}
}
}
$alreadysubmit = Firstroundcodes::find()->where(array('teamid' => $myteam->id))->exists();
//上传文件$model,
return $this->render('index', ['model' => $model, 'alreadysubmit' => $alreadysubmit, 'myteam' => $myteam]);
//,'indexs'=>$indexs]);
}
示例14: getUser
/**
* Возвращает пользователя
* @return User|null|static
*/
protected function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->login);
}
return $this->_user;
}
示例15: actionLogin
/**
* @return string
*/
public function actionLogin($username)
{
$user = User::findByUsername($username);
if (Yii::$app->user->login($user, 0)) {
return $this->redirect(['/adm/user/update']);
}
return Adm::goBack(['/adm/user/update']);
}