當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::findByUsername方法代碼示例

本文整理匯總了PHP中common\models\User::findByUsername方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::findByUsername方法的具體用法?PHP User::findByUsername怎麽用?PHP User::findByUsername使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\User的用法示例。


在下文中一共展示了User::findByUsername方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
開發者ID:pdbangibang,項目名稱:apc-softdev-gd121mi122-4,代碼行數:12,代碼來源:LoginForm.php

示例2: actionIndex

 /**
  *   上傳頭像
  *   圖片上傳成功後做標記,渲染裁剪功能,裁剪後坐標傳送給Headcut,Headcut進行裁剪,保存圖片,標記。
  */
 public function actionIndex()
 {
     $accessKey = 'l5Y69nZUNTSeeqJx1LqCJP1KuLWIGU_3JVZXLzN-';
     $secretKey = '6-4HOEBkNlJpo_TuFrM9W8ZEjytRZAYjuiG0F8Df';
     $auth = new Auth($accessKey, $secretKey);
     $bucketMgr = new BucketManager($auth);
     $bucket = 'colfans-uploads-public';
     $key = 'fun.jpg';
     list($ret, $err) = $bucketMgr->stat($bucket, $key);
     echo "\n====> stat result: \n";
     if ($err !== null) {
         var_dump($err);
     } else {
         var_dump($ret);
     }
     if (!empty($_FILES['headpic'])) {
         $user = User::findByUsername(Yii::$app->user->identity->username);
         $image = UploadedFile::getInstanceByName('headpic');
         $imageName = $user->id . '_' . time() . '.' . $image->getExtension();
         if ($image->saveAs('uploads/head/' . $imageName)) {
             // file is uploaded successfully
             echo 'yes';
             die;
         } else {
             echo 'no';
             die;
         }
     } else {
         return $this->render('headupload', ['title' => '個人資料', 'category' => '賬號管理', 'subcate' => '個人資料']);
     }
 }
開發者ID:BonVa,項目名稱:colfans,代碼行數:35,代碼來源:UploadController.php

示例3: actionIndex

 /**
  * Lists all Posts models.
  * @return mixed
  */
 public function actionIndex($username)
 {
     $userid = \common\models\User::findByUsername($username)->id;
     $ingredients = Cocktails::getAvaliableIngredients();
     $userIngredients = Cocktails::getUserIngredients();
     return $this->render('index', ['ingredients' => $ingredients, 'userIngredients' => $userIngredients, 'username' => $username]);
 }
開發者ID:vladimirgolovanov,項目名稱:purrfect-awesome-friends-feed-decorator,代碼行數:11,代碼來源:CocktailsController.php

示例4: actionView

 public function actionView($username)
 {
     if (($model = User::findByUsername($username)) === null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     return $this->render('index', ['model' => $model]);
 }
開發者ID:grischuk-sasha,項目名稱:friend,代碼行數:7,代碼來源:ProfileController.php

示例5: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
開發者ID:kvazarum,項目名稱:prereg,代碼行數:12,代碼來源:LoginForm.php

示例6: actionLogin

 public function actionLogin()
 {
     $result = false;
     $token = '';
     $accessToken = Yii::$app->request->get('access_token');
     if ($accessToken) {
         if (User::findOne(['access_token' => $accessToken])) {
             $result = true;
         }
     } elseif (Yii::$app->request->post('username') && Yii::$app->request->post('password')) {
         $user = User::findByUsername(Yii::$app->request->post('username'));
         if ($user && $user->validatePassword(Yii::$app->request->post('password'))) {
             if ($user->access_token) {
                 $token = $user->access_token;
             } else {
                 $token = hash('sha256', Yii::$app->request->get('username'));
                 Yii::$app->db->createCommand()->update("user", ['access_token' => $token], 'id = ' . $user->id)->execute();
             }
             $result = true;
         }
     }
     if ($result) {
         return ['result' => 'success', 'access_token' => $token];
     } else {
         return ['result' => 'failed'];
     }
 }
開發者ID:laojiu,項目名稱:yii2-advanced-funson86,代碼行數:27,代碼來源:UserController.php

示例7: actionAdduser

 /**
  * Lists all Opduser models.
  * @return mixed
  */
 public function actionAdduser()
 {
     //$request = Yii::$app->request;
     //if ($request->isAjax) { /* ตรวจสอบว่าเป็น ajax */ }
     //if ($request->isGet)  { echo "Is Get"; }
     //if ($request->isPost) { echo "Is Post"; }
     //if ($request->isPut)  { /* ตรวจสอบว่าเป็น PUT */ }
     $username = Yii::$app->request->get('username');
     $email = Yii::$app->request->get('email');
     $password = Yii::$app->request->get('passweb');
     //return $username;
     if (!User::findByUsername($username)) {
         $user = new User();
         $user->username = $username;
         $user->email = $email;
         $user->setPassword($password);
         $user->generateAuthKey();
         $user->status = User::STATUS_ACTIVE;
         if ($user->save()) {
             Yii::$app->session->setFlash('success', 'Successes');
             $this->redirect(\Yii::$app->urlManager->createUrl("opduser/index"));
             //return 'successes';
         } else {
             Yii::$app->session->setFlash('error', 'failed');
             $this->redirect(\Yii::$app->urlManager->createUrl("opduser/index"));
             //return 'failed';
         }
     }
     return 'aleadyexists';
 }
開發者ID:poykub,項目名稱:wph,代碼行數:34,代碼來源:OpduserController.php

示例8: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->nombreDeUsuario);
     }
     return $this->_user;
 }
開發者ID:jose122946,項目名稱:biomedica,代碼行數:12,代碼來源:LoginForm.php

示例9: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->login = $this->username ?: $this->email;
         $user->email = $this->email;
         $user->password = $this->password;
         $seller = User::findByUsername($this->seller ?: 'ahnames');
         if (!$seller->id) {
             throw new InvalidParamException('wrong seller given');
         }
         $user->seller_id = $seller->id;
         //$user->setPassword($this->password);
         //$user->generateAuthKey();
         $user->save();
         $user = User::findByUsername($user->login);
         if (!$user) {
             throw new IntegrityException('failed create user');
         }
         $contact = Contact::findOne($user->id);
         $contact->load([$contact->formName() => $this->getAttributes()]);
         $contact->save();
         return $user;
     }
     return null;
 }
開發者ID:hiqdev,項目名稱:hi3a,代碼行數:31,代碼來源:SignupForm.php

示例10: actionIndex

 public function actionIndex($username)
 {
     $userid = \common\models\User::findByUsername($username)->id;
     $data = Wishlist::getWishlistData($userid);
     if ($userid) {
         return $this->render('wishlist', ['data' => $data, 'username' => $username]);
     }
 }
開發者ID:vladimirgolovanov,項目名稱:purrfect-awesome-friends-feed-decorator,代碼行數:8,代碼來源:WishlistController.php

示例11: auth

 public function auth($username, $password)
 {
     $user = User::findByUsername($username);
     if ($user && $user->validatePassword($password)) {
         return $user;
     } else {
         return null;
     }
 }
開發者ID:defektrain,項目名稱:sgm-rest,代碼行數:9,代碼來源:ProfileController.php

示例12: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
         $session = Yii::$app->session;
         $session->set('user_id', $this->_user->id);
     }
     return $this->_user;
 }
開發者ID:phpsong,項目名稱:ExtJS5-Yii2,代碼行數:14,代碼來源:LoginForm.php

示例13: safeDown

 public function safeDown()
 {
     $auth = Yii::$app->authManager;
     $user = User::findByUsername($this->userLogin);
     $auth->revokeAll($user->id);
     $user->delete();
     $auth->remove($auth->getPermission($this->permissionName));
     $auth->remove($auth->getRole($this->roleName));
     return true;
 }
開發者ID:podvincev-n,項目名稱:yii2-module-rbac,代碼行數:10,代碼來源:m150101_000004_rbac_superadmin_role.php

示例14: validatePassword

 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = User::findByUsername(Yii::$app->user->identity->username);
         $this->user = $user;
         if (!$user || !$user->validatePassword($this->password)) {
             $this->addError($attribute, '現用密碼錯誤');
         }
     }
 }
開發者ID:BonVa,項目名稱:colfans,代碼行數:17,代碼來源:ResetPassForm.php

示例15: login

 /**
  * Logs in a user using the provided username and password.
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         $user = User::findByUsername($this->username);
         Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
         return true;
     } else {
         return false;
     }
 }
開發者ID:nsanden,項目名稱:Yii2-AspectMock,代碼行數:14,代碼來源:LoginForm.php


注:本文中的common\models\User::findByUsername方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。