예제 #1
0
 public function checkexists()
 {
     if (!$this->hasErrors()) {
         // we only want to authenticate when no input errors
         /**@var User $user*/
         if (strpos($this->login_or_email, "@")) {
             $user = User::findOne(['email' => $this->login_or_email]);
             if ($user) {
                 $this->user_id = $user->id;
             }
         } else {
             $user = User::findOne(['username' => $this->login_or_email]);
             if ($user) {
                 $this->user_id = $user->id;
             }
         }
         if ($user === null) {
             if (strpos($this->login_or_email, "@")) {
                 $this->addError("login_or_email", Module::t("Email is incorrect."));
             } else {
                 $this->addError("login_or_email", Module::t("Username is incorrect."));
             }
         }
     }
 }
예제 #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the primary key value. Defaults to null, meaning using the 'id' GET variable
  * @return User
  * @throws NotFoundHttpException
  */
 public function loadUser($id = null)
 {
     if ($this->model === null) {
         if ($id !== null || Yii::$app->request->get('id')) {
             $this->model = User::findOne($id !== null ? $id : Yii::$app->request->get('id'));
         }
         if ($this->model === null) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $this->model;
 }
예제 #3
0
 /**
  * Return safe user data.
  * @param $username string user name
  * @return user object or false
  */
 public static function getUserByName($username)
 {
     $_userByName = [];
     if (!isset(self::$userByName[$username])) {
         $_userByName[$username] = User::findOne(['username' => $username]);
     }
     return $_userByName[$username];
 }
예제 #4
0
 private function lastVisit()
 {
     /** @var $lastVisit User*/
     $lastVisit = User::findOne(Yii::$app->user->id);
     $lastVisit->lastvisit_at = date('Y-m-d H:i:s');
     $lastVisit->save();
 }