findByUsername() public static method

Finds user by username
public static findByUsername ( string $username ) : static | null
$username string
return static | null
コード例 #1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
コード例 #2
0
ファイル: UploadController.php プロジェクト: BonVa/colfans
 /**
  *   上传头像
  *   图片上传成功后做标记,渲染裁剪功能,裁剪后坐标传送给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' => '个人资料']);
     }
 }
 /**
  * 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]);
 }
コード例 #4
0
 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]);
 }
コード例 #5
0
ファイル: LoginForm.php プロジェクト: kvazarum/prereg
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
コード例 #6
0
 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'];
     }
 }
コード例 #7
0
ファイル: OpduserController.php プロジェクト: poykub/wph
 /**
  * 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';
 }
コード例 #8
0
ファイル: LoginForm.php プロジェクト: jose122946/biomedica
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->nombreDeUsuario);
     }
     return $this->_user;
 }
コード例 #9
0
ファイル: SignupForm.php プロジェクト: hiqdev/hi3a
 /**
  * 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;
 }
 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]);
     }
 }
コード例 #11
0
 public function auth($username, $password)
 {
     $user = User::findByUsername($username);
     if ($user && $user->validatePassword($password)) {
         return $user;
     } else {
         return null;
     }
 }
コード例 #12
0
ファイル: LoginForm.php プロジェクト: phpsong/ExtJS5-Yii2
 /**
  * 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;
 }
 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;
 }
コード例 #14
0
ファイル: ResetPassForm.php プロジェクト: BonVa/colfans
 /**
  * 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, '现用密码错误');
         }
     }
 }
コード例 #15
0
ファイル: LoginForm.php プロジェクト: nsanden/Yii2-AspectMock
 /**
  * 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;
     }
 }
コード例 #16
0
ファイル: AdminLoginForm.php プロジェクト: unix-admin/webdev
 public function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
         if (!Yii::$app->authManager->checkAccess($this->_user->id, 'admin')) {
             $this->_user = null;
         }
     }
     return $this->_user;
 }
コード例 #17
0
ファイル: LoginForm.php プロジェクト: iiyii/getyii
 /**
  * email 邮箱登录
  * @user onyony
  * @return bool|null|static
  */
 public function getUser()
 {
     if ($this->_user === false) {
         if (strpos($this->username, "@")) {
             $this->_user = User::findByEmail($this->username);
         } else {
             $this->_user = User::findByUsername($this->username);
         }
     }
     return $this->_user;
 }
コード例 #18
0
ファイル: LoginForm.php プロジェクト: James88/www.yii2.com
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         if (\common\components\Utils::isEmail($this->username)) {
             $this->_user = User::findByEmail($this->username);
         } else {
             $this->_user = User::findByUsername($this->username);
         }
     }
     //var_dump($this->_user);//die;
     return $this->_user;
 }
コード例 #19
0
ファイル: LoginForm.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
         if ($this->_user) {
             $this->_user->login_ip = Yii::$app->request->userIp;
             $this->_user->count += 1;
             $this->_user->save();
         }
     }
     return $this->_user;
 }
コード例 #20
0
ファイル: InfoForm.php プロジェクト: BonVa/colfans
 /**
  *   update infomation
  *
  */
 public function loadInfo()
 {
     $user = User::findByUsername(Yii::$app->user->identity->username);
     if ($this->validate()) {
         $user->info = $this->info;
         $user->longinfo = $this->longinfo;
         if ($user->save()) {
             return 'success';
         }
     }
     return null;
 }
コード例 #21
0
 /**
  * Finds user by username or email in 'lwe' scenario.
  *
  * @return User|null|static
  */
 public function getUser()
 {
     if ($this->_user === false) {
         // in 'lwe' scenario we find user by email, otherwise by username
         if ($this->scenario === 'lwe') {
             $this->_user = User::findByEmail($this->email);
         } else {
             $this->_user = User::findByUsername($this->username);
         }
     }
     return $this->_user;
 }
コード例 #22
0
ファイル: RequestForm.php プロジェクト: vaibhavk01/motor
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $query2 = (new Query())->select('username')->from('user')->where('city=:city AND dealer=:deal', array(':city' => $this->city, ':deal' => 1));
         $dealer = $query2->all();
         $flag = 1;
         $car = $this->model_name;
         $use = new User();
         $user = Yii::$app->user->identity->username;
         $val = $use->findByUsername($user);
         $color = $this->color;
         $variant = $this->variant;
         $city = $this->city;
         $otherr = $this->otherr;
         $delivery = $this->delivery;
         $urequest = new Userrequest();
         $urequest->car_model = $car;
         $urequest->user_id = $val->id;
         $urequest->username = $val->username;
         $urequest->color = $color;
         $urequest->variant = $variant;
         $urequest->city = $city;
         $urequest->otherr = $otherr;
         $urequest->delivery = $delivery;
         $urequest->save();
         \Yii::$app->mailer->compose(['html' => 'request-html'], ['user' => $val, 'req' => $urequest])->setFrom([\Yii::$app->params['supportEmail'] => 'motormetric' . ' robot'])->setTo($val->email)->setSubject('Your Request ' . $urequest->car_model)->send();
         foreach ($dealer as $deal) {
             $request = new Carrequest();
             $val1 = $use->findByUsername1($deal['username']);
             $request->car_model = $car;
             $request->user_id = $val->id;
             $request->user_name = $val->username;
             $request->dealer_name = $deal['username'];
             $request->color = $color;
             $request->variant = $variant;
             $request->city = $city;
             $request->dealer_id = $val1->id;
             $request->request_id = $urequest->id;
             $request->otherr = $urequest->otherr;
             \Yii::$app->mailer->compose(['html' => 'requestd-html'], ['user' => $val, 'req' => $urequest, 'deal' => $val1])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name])->setTo($val1->email)->setSubject('New Request ' . $urequest->car_model)->send();
             if (!$request->save()) {
                 $flag = 0;
             }
         }
         if ($flag) {
             $request = new Carrequest();
             return $request;
         }
         return null;
         //$user->username = $this->username;
     }
 }
コード例 #23
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === null) {
         if ($this->_user = User::findByUsername($this->username)) {
             if ($this->_user->verification == 'No') {
                 $this->_user = null;
             }
         } else {
             $this->_user = null;
         }
     }
     return $this->_user;
 }
コード例 #24
0
ファイル: LoginForm - original.php プロジェクト: ewwgit/eptri
 public function socialmediaInsert($param)
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($param['email']);
     }
     if ($this->_user == NULL) {
         $lastId = Yii::$app->db->createCommand('SELECT MAX(id) FROM user')->queryScalar();
         $lastInsertId = $lastId + 1;
         $data = Yii::$app->db->createCommand()->insert('user', ['username' => $param['email'], 'email' => $param['email'], 'status' => 10, 'uid' => $lastInsertId])->execute();
         $this->_user = User::findByUsername($param['email']);
     }
     return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
 }
コード例 #25
0
ファイル: LoginForm.php プロジェクト: iwansusanto/jurnalrumah
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
         // update last login when login success
         if (!empty($this->_user)) {
             $update = Yii::$app->db->createCommand("UPDATE jr_user SET last_login = '******'Y-m-d H:i:s') . "'\n                                                    WHERE id=:id ");
             $update->bindValue(':id', $this->_user->id);
             $update->execute();
         }
         // end
     }
     return $this->_user;
 }
コード例 #26
0
ファイル: LoginForm.php プロジェクト: CherryPieCo/SB
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     if ($this->_user === null) {
         $this->_user = User::findByEmail($this->username);
     }
     if (!Yii::$app->user->can('dashboard', ['user' => $this->_user])) {
         $this->_user = null;
         throw new \yii\web\HttpException(403, 'Access is restricted to administrators.', 403);
     }
     return $this->_user;
 }
コード例 #27
0
ファイル: AdminController.php プロジェクト: BonVa/colfans
 /**
  * 修改资料
  */
 public function actionInfo()
 {
     $infoModel = new InfoForm();
     $user = User::findByUsername(Yii::$app->user->identity->username);
     if (Yii::$app->request->post()) {
         if ($infoModel->load(Yii::$app->request->post())) {
             if ($infoModel->loadInfo()) {
                 $this->redirect(['info', 'message' => 'success']);
             } else {
                 $this->redirect(['info', 'message' => 'error']);
             }
         }
     }
     return $this->render('info', ['title' => '个人资料', 'category' => '账号管理', 'subcate' => '个人资料', 'infoModel' => $infoModel, 'user' => $user]);
 }
コード例 #28
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['except' => ['access-token-by-user'], 'class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBasicAuth::className(), 'auth' => function ($username, $password) {
         $out = null;
         $user = \common\models\User::findByUsername($username);
         if ($user != null) {
             if ($user->validatePassword($password)) {
                 $out = $user;
             }
         }
         return $out;
     }], ['class' => QueryParamAuth::className()]]];
     return $behaviors;
 }
コード例 #29
0
ファイル: UserForm.php プロジェクト: cbk808/aimocms
 public function edit()
 {
     if (!$this->validate()) {
         return null;
     }
     $user = new User();
     $user->findByUsername($this->username);
     $user->username = $this->username;
     $user->email = $this->email;
     $user->updated_at = time();
     if (!empty($this->password)) {
         $user->setPassword($this->password);
     }
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
コード例 #30
0
 public function safeUp()
 {
     yii::$app->cache->flush();
     $role = Yii::$app->authManager->createRole('admin');
     $role->description = 'Админ';
     Yii::$app->authManager->add($role);
     $roleUser = Yii::$app->authManager->createRole('user');
     $roleUser->description = 'Юзер';
     Yii::$app->authManager->add($roleUser);
     $permissions = Yii::$app->authManager->getPermissions();
     foreach ($permissions as $p) {
         \Yii::$app->authManager->addChild($role, $p);
     }
     $me = User::findByUsername('*****@*****.**');
     \Yii::$app->authManager->assign($role, $me->getId());
 }