Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username, sha1($this->password));
     }
     return $this->_user;
 }
Exemplo n.º 3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 public function validateUsernameUnique()
 {
     $user = User::findByUsername($this->username);
     if ($user) {
         $this->addError('username', 'Username must be unique.');
     }
 }
 /**
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user !== null) {
         return $this->_user;
     }
     return $this->_user = User::findByUsername($this->email);
 }
Exemplo n.º 7
0
 public function actionAssignRole($username, $roleName)
 {
     $user = User::findByUsername($username);
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($roleName);
     $auth->assign($role, $user);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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]);
 }
Exemplo n.º 10
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Exemplo n.º 11
0
 /**
  * регистрация юзера по имейл
  * если регистрация для покупки, то передаются параметры рекомендатель и урл
  * @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]);
 }
Exemplo n.º 12
0
 public function actionPerson()
 {
     $user = User::findByUsername('123');
     var_dump($user);
     die;
     return $this->render('person');
 }
Exemplo n.º 13
0
 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]);
 }
Exemplo n.º 14
0
 /**
  * Возвращает пользователя
  * @return User|null|static
  */
 protected function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->login);
     }
     return $this->_user;
 }
Exemplo n.º 15
0
 /**
  * @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']);
 }
Exemplo n.º 16
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 private function getUser()
 {
     //echo "<script>alert('getuser');</script>";
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Exemplo n.º 17
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username, $this->password);
         //$this->_user = TbUser::findOne([name=>'admin',password=>'admin']);
     }
     return $this->_user;
 }
Exemplo n.º 18
0
 public function actionLogout()
 {
     $user = User::findByUsername(Yii::$app->user->identity->username);
     $user->removeAccessToken();
     $user->save(false);
     Yii::$app->user->logout();
     return $this->goHome();
 }
Exemplo n.º 19
0
 /**
  * @depends testFindUserByUsername
  */
 public function testValidateUser($user)
 {
     $user = User::findByUsername('admin');
     expect_that($user->validateAuthKey('test100key'));
     expect_not($user->validateAuthKey('test102key'));
     expect_that($user->validatePassword('admin'));
     expect_not($user->validatePassword('123456'));
 }
Exemplo n.º 20
0
 public function getUser()
 {
     if ($this->_user === false) {
         return $this->_user = User::findByUsername($this->login);
     } else {
         return $this->_user;
     }
 }
Exemplo n.º 21
0
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
         $this->_user->generateAccessToken();
         $this->_user->save(false);
     }
     return $this->_user;
 }
Exemplo n.º 22
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $usr = new User();
         $this->_user = $usr->findByUsername($this->username);
         //$this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Exemplo n.º 23
0
 public function login()
 {
     if ($this->validate()) {
         $user = User::findByUsername($this->username);
         Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
         return true;
     }
     return false;
 }
Exemplo n.º 24
0
 public function init()
 {
     parent::init();
     $identity = \app\models\User::findByUsername('console_user');
     if ($identity) {
         $this->setIdentity($identity);
     } else {
         throw new Exception("Error console_user not found cannot set console user identity", 1);
     }
 }
Exemplo n.º 25
0
 /**
  * @return string
  */
 public function actionLogin($username)
 {
     /* @var $user User */
     $user = User::findByUsername($username);
     Yii::$app->user->login($user, 0);
     if (Yii::$app->user->can('AdmRoot') || Yii::$app->user->can('AdmAdmin')) {
         return $this->redirect(['/adm/user/update']);
     }
     return $this->redirect(Url::getLangUrl());
 }
Exemplo n.º 26
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
         if (is_null($this->_user)) {
             $this->_user = User::findByEmail($this->username);
         }
     }
     return $this->_user;
 }
Exemplo n.º 27
0
 public function getUser()
 {
     if ($this->_user === false) {
         if ($this->scenario === 'loginWithEmail') {
             $this->_user = User::findByEmail($this->email);
         } else {
             $this->_user = User::findByUsername($this->username);
         }
     }
     return $this->_user;
 }
Exemplo n.º 28
0
 public function updatepwd()
 {
     var_dump($this->getErrors());
     $user = User::findByUsername(Yii::$app->user->identity->username);
     $user->password = $this->newpwd;
     //Yii::$app->getSecurity()->generatePasswordHash($model->newpwd);
     if ($user->update(false)) {
         return $user;
     }
     return null;
 }
Exemplo n.º 29
0
 public function login()
 {
     if ($this->validate()) {
         if (!($user = User::findByUsername($this->username))) {
             $user = User::findByEmail($this->username);
         }
         if ($login = \Gbox::$components->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0)) {
         }
         return $login;
     }
     return false;
 }
Exemplo n.º 30
0
 /**
  * Logs in a user using the provided username and password.
  *
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     $user = User::findByUsername($this->username);
     if ($user && $this->validate() && $user->validatePassword($this->password) && $user->validateCode($this->code)) {
         Yii::$app->session->open();
         Yii::$app->session['ip'] = $_SERVER['REMOTE_ADDR'];
         return Yii::$app->user->login($user, 0);
     } else {
         $this->addError('username', 'Username or password is invalid');
         return false;
     }
 }