当前位置: 首页>>代码示例>>PHP>>正文


PHP User::findByUsername方法代码示例

本文整理汇总了PHP中User::findByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findByUsername方法的具体用法?PHP User::findByUsername怎么用?PHP User::findByUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User的用法示例。


在下文中一共展示了User::findByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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:humanized,项目名称:yii2-user-module,代码行数:12,代码来源:LoginForm.php

示例2: before_filter

 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     // Lock context to user id
     $this->owner = $GLOBALS['user'];
     $this->context_id = $this->owner->id;
     $this->full_access = true;
     if (Config::get()->PERSONALDOCUMENT_OPEN_ACCESS) {
         $username = Request::username('username', $GLOBALS['user']->username);
         $user = User::findByUsername($username);
         if ($user && $user->id !== $GLOBALS['user']->id) {
             $this->owner = $user;
             $this->context_id = $user->id;
             $this->full_access = Config::get()->PERSONALDOCUMENT_OPEN_ACCESS_ROOT_PRIVILEDGED && $GLOBALS['user']->perms === 'root';
             URLHelper::bindLinkParam('username', $username);
         }
     }
     $this->limit = $GLOBALS['user']->cfg->PERSONAL_FILES_ENTRIES_PER_PAGE ?: Config::get()->ENTRIES_PER_PAGE;
     $this->userConfig = DocUsergroupConfig::getUserConfig($GLOBALS['user']->id);
     if ($this->userConfig['area_close'] == 1) {
         $this->redirect('document/closed/index');
     }
     if (Request::isPost()) {
         CSRFProtection::verifySecurityToken();
     }
     if (($ticket = Request::get('studip-ticket')) && !check_ticket($ticket)) {
         $message = _('Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten.') . "\n" . _('Bitte versuchen Sie es erneut.');
         PageLayout::postMessage(MessageBox::error($message));
         $this->redirect('document/files/index');
     }
 }
开发者ID:ratbird,项目名称:hope,代码行数:31,代码来源:document_controller.php

示例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;
 }
开发者ID:absol3112,项目名称:sonneboutique,代码行数:12,代码来源:LoginForm.php

示例4: getUser

 /**
  * Finds user by username.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $scope = $this->scenario === 'admin' ? ['admin', 'active'] : 'active';
         $this->_user = User::findByUsername($this->username, $scope);
     }
     return $this->_user;
 }
开发者ID:dvizh,项目名称:yii2-users-module,代码行数:13,代码来源:LoginForm.php

示例5: updatePassword

 /**
  * @test
  */
 public function updatePassword()
 {
     $user1 = User::findByUsername("test1");
     $this->eq(md5("test1"), $user1->password);
     $user1->updatePassword("foo");
     $user1 = new User($user1->id);
     $this->eq(md5("foo"), $user1->password);
     $user1->updatePassword("test1");
 }
开发者ID:hamaco,项目名称:phwittr-on-xoops,代码行数:12,代码来源:User.php

示例6: check

 public static function check()
 {
     return function ($req, $res) {
         $user = User::findByUsername($req->user);
         if ($user) {
             $res->code(200);
         } else {
             $res->code(404);
         }
     };
 }
开发者ID:samdubey,项目名称:ads2,代码行数:11,代码来源:registerctrl.php

示例7: validateUser

 /**
  * Validate existence of user and save it's model.
  *
  * @param string $attribute
  * @param array $params
  */
 public function validateUser($attribute, $params = [])
 {
     if (!$this->hasErrors()) {
         $res = User::findByUsername($this->{$attribute});
         if (!$res instanceof User) {
             $this->addError($attribute, \Yii::t('user', 'User not found'));
         } else {
             $this->user = $res;
         }
     }
 }
开发者ID:kalyabin,项目名称:comitka,代码行数:17,代码来源:ForgotPasswordForm.php

示例8: initialize

 function initialize(&$controller)
 {
     $this->controller = $controller;
     if ($controller->Auth->user()) {
         // already authenticated
         return;
     }
     $cookie = $controller->Cookie->read(AuthExtensionComponent::cookie_name);
     if (!$cookie) {
         return;
     }
     $all_fields = isset($cookie['username']) && isset($cookie['hash1']) && isset($cookie['time']) && isset($cookie['hash']);
     // all fields present?
     if (!$all_fields) {
         $this->logout();
         return;
     }
     // global hash correct?
     if (Security::hash($cookie['username'] . $cookie['hash1'] . $cookie['time']) !== $cookie['hash']) {
         $this->logout();
         return;
     }
     if (time() - $cookie['time'] > AuthExtensionComponent::cookie_expire_seconds) {
         $this->logout();
         return;
     }
     // find the user
     App::import('Model', 'User');
     $User = new User();
     $u = $User->findByUsername($cookie['username']);
     if (!$u) {
         $this->logout();
         return;
     }
     if (Security::hash($u['User']['password'] . 'another random string', null, true) === $cookie['hash1']) {
         // user confirmed
         $login_array = array('User' => array('username' => $u['User']['username'], 'password' => $u['User']['password']));
         $u = null;
         if ($controller->Auth->login($login_array)) {
             //  Clear auth message, just in case we use it.
             $controller->Session->del('Message.auth');
             $controller->redirect($controller->Auth->redirect());
         } else {
             // Delete invalid Cookie
             $this->logout();
         }
     } else {
         $u = null;
     }
 }
开发者ID:masayukiando,项目名称:googlemap-search_ActionScript3.0,代码行数:50,代码来源:auth_extension.php

示例9: buddy_action

 /**
  * Controller for all buddy related action.
  *
  * The following actions are supported:
  * - "add" to add a user to the current user's buddy list
  * - "remove" to remove a user from the current user's buddy list
  *
  * @param String $action The action to be executed
  */
 public function buddy_action($action = 'add')
 {
     $username = Request::username('username');
     if ($action === 'add' && $username !== null) {
         if (Contact::import(array('owner_id' => User::findCurrent()->id, 'user_id' => User::findByUsername($username)->id))->store()) {
             PageLayout::postMessage(MessageBox::success(_('Der Benutzer wurde zu Ihren Kontakten hinzugefügt.')));
         }
     } elseif ($action === 'remove' && $username !== null) {
         $contact = Contact::find(array(User::findCurrent()->id, User::findByUsername($username)->id));
         if ($contact && $contact->delete()) {
             PageLayout::postMessage(MessageBox::success(_('Der Benutzer gehört nicht mehr zu Ihren Kontakten.')));
         }
     }
     $this->redirect('online');
 }
开发者ID:ratbird,项目名称:hope,代码行数:24,代码来源:online.php

示例10: post

 public static function post($userId, $comment)
 {
     $status = new self();
     $comment = self::normalizeComment($comment);
     if (preg_match('/^@(\\w{1,20})/', $comment, $matches) === 1) {
         $targetUser = User::findByUsername($matches[1]);
         if ($targetUser->isActive()) {
             $status->reply_user_id = $targetUser->uid;
         }
     }
     $status->user_id = $userId;
     $status->comment = $comment;
     $status->created_at = now();
     $status->save();
     return $status;
 }
开发者ID:hamaco,项目名称:phwittr-on-xoops,代码行数:16,代码来源:Status.php

示例11: before_filter

 /**
  * Sets up the controller
  *
  * @param String $action Which action shall be invoked
  * @param Array $args Arguments passed to the action method
  */
 public function before_filter(&$action, &$args)
 {
     // Abwärtskompatibilität, erst ab 1.1 bekannt
     if (!isset($GLOBALS['ALLOW_CHANGE_NAME'])) {
         $GLOBALS['ALLOW_CHANGE_NAME'] = TRUE;
     }
     parent::before_filter($action, $args);
     // Ensure user is logged in
     $GLOBALS['auth']->login_if($action !== 'logout' && $GLOBALS['auth']->auth['uid'] === 'nobody');
     // extract username
     $username = Request::username('username', $GLOBALS['user']->username);
     $user = User::findByUsername($username);
     if (!$GLOBALS['perm']->have_profile_perm('user', $user->user_id)) {
         $username = $GLOBALS['user']->username;
     } else {
         $username = $user->username;
         URLHelper::addLinkParam('username', $username);
     }
     $this->about = new about($username, null);
     $this->about->get_user_details();
     if (!$this->about->check) {
         $this->reportErrorWithDetails(_('Zugriff verweigert.'), array(_("Wahrscheinlich ist Ihre Session abgelaufen. Bitte " . "nutzen Sie in diesem Fall den untenstehenden Link, " . "um zurück zur Anmeldung zu gelangen.\n\n" . "Eine andere Ursache kann der Versuch des Zugriffs " . "auf Userdaten, die Sie nicht bearbeiten dürfen, sein. " . "Nutzen Sie den untenstehenden Link, um zurück auf " . "die Startseite zu gelangen."), sprintf(_('%s Hier%s geht es wieder zur Anmeldung beziehungsweise Startseite.'), '<a href="index.php">', '</a>')));
         $this->render_nothing();
         return;
     }
     $this->user = User::findByUsername($username);
     $this->restricted = $GLOBALS['perm']->get_profile_perm($this->user->user_id) !== 'user' && $username !== $GLOBALS['user']->username;
     $this->config = UserConfig::get($this->user->user_id);
     $this->validator = new email_validation_class();
     # Klasse zum Ueberpruefen der Eingaben
     $this->validator->timeout = 10;
     // Default auth plugin to standard
     if (!$this->user->auth_plugin) {
         $this->user->auth_plugin = 'standard';
     }
     PageLayout::addSqueezePackage('settings');
     // Show info message if user is not on his own profile
     if ($username != $GLOBALS['user']->username) {
         $message = sprintf(_('Daten von: %s %s (%s), Status: %s'), htmlReady($this->user->Vorname), htmlReady($this->user->Nachname), $username, $this->user->perms);
         $this->reportInfo($message);
     }
     Sidebar::get()->setImage('sidebar/person-sidebar.png');
     $this->set_layout($GLOBALS['template_factory']->open('layouts/base'));
 }
开发者ID:ratbird,项目名称:hope,代码行数:50,代码来源:settings.php

示例12: go

 public function go()
 {
     $this->setViewTemplate('admin_login.tpl');
     $this->addPageTitle('Log in');
     if ($this->isLoggedIn()) {
         header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/dashboard.php");
     } else {
         if (isset($_POST['submit']) && $_POST['submit'] == 'Login' && isset($_POST['username']) && isset($_POST['pwd'])) {
             if ($_POST['username'] == '' || $_POST['pwd'] == '') {
                 if ($_POST['username'] == '') {
                     $this->addErrorMessage("Username must not be empty");
                     return $this->generateView();
                 } else {
                     $this->addErrorMessage("Password must not be empty");
                     return $this->generateView();
                 }
             } else {
                 $session = new Session();
                 $username = $_POST['username'];
                 $this->addToView('username', $username);
                 $user = User::findByUsername($username);
                 if (!$user) {
                     $this->addErrorMessage("Incorrect username");
                     return $this->generateView();
                 } elseif (!$session->pwdCheck($_POST['pwd'], $user->password)) {
                     $this->addErrorMessage("Incorrect password");
                     return $this->generateView();
                 } elseif (!$user->type) {
                     $this->addErrorMessage("You are not an administrator");
                     return $this->generateView();
                 } else {
                     // this sets variables in the session
                     $session->completeLogin($user);
                     header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/login.php");
                 }
             }
         } else {
             $this->addPageTitle('Log in');
             return $this->generateView();
         }
     }
 }
开发者ID:JoffreyO,项目名称:hackademic,代码行数:42,代码来源:class.LoginController.php

示例13: register

 /**
  * @param $username string
  * @param $password string
  * @param $firstName string
  * @param $lastName string
  * @return mixed
  */
 public static function register($username, $password, $firstName, $lastName, $accessLevel = 0, $premade = 0, $email = "", $phone = "")
 {
     if (User::findByUsername($username)) {
         return null;
     }
     $user = new User();
     $user->username = $username;
     $user->salt = Auth::generatePasswordSalt();
     $user->password = Auth::hashPassword($password, $user->salt);
     $user->firstName = $firstName;
     $user->lastName = $lastName;
     $user->email = $email;
     $user->phone = $phone;
     $user->accessLevel = $accessLevel;
     $user->premade = $premade;
     $user->createDate = Database::now();
     if (!$user->save()) {
         return null;
     }
     return $user;
 }
开发者ID:pvpalvk,项目名称:kyberkoulutus2,代码行数:28,代码来源:User.php

示例14: go

 public function go()
 {
     $this->setViewTemplate('landingpage.tpl');
     $this->addPageTitle('Log in');
     if ($this->isLoggedIn()) {
         $controller = new LandingPageController();
         return $controller->go();
     } else {
         if (isset($_POST['submit']) && $_POST['submit'] == 'Login' && isset($_POST['username']) && isset($_POST['pwd'])) {
             if ($_POST['username'] == '' || $_POST['pwd'] == '') {
                 if ($_POST['username'] == '') {
                     $this->addErrorMessage("Username must not be empty");
                     return $this->generateView();
                 } else {
                     $this->addErrorMessage("Password must not be empty");
                     return $this->generateView();
                 }
             } else {
                 $session = new Session();
                 $username = $_POST['username'];
                 $this->addToView('username', $username);
                 $user = User::findByUsername($username);
                 if (!$user) {
                     header('Location:' . SOURCE_ROOT_PATH . "pages/mainlogin.php?msg=username");
                     //return $this->generateView();
                 } elseif (!$session->pwdCheck($_POST['pwd'], $user->password)) {
                     header('Location:' . SOURCE_ROOT_PATH . "pages/mainlogin.php?msg=password");
                     return $this->generateView();
                 } else {
                     // this sets variables in the session
                     $session->completeLogin($user);
                     header('Location:' . SOURCE_ROOT_PATH . "pages/home.php");
                 }
             }
         } else {
             $this->addPageTitle('Log in');
             return $this->generateView();
         }
     }
 }
开发者ID:JoffreyO,项目名称:hackademic,代码行数:40,代码来源:class.LoginController.php

示例15: attempt

 public static function attempt($email, $password)
 {
     // $log = new Log('users.login');
     $_SESSION['LOGGED_IN_USER'] = null;
     $_SESSION['LOGGED_IN'] = false;
     $user = User::findByUsername($email);
     $hashedPassword = $user->password;
     if (password_verify($password, $hashedPassword)) {
         //echo 'loged in';
         $_SESSION['LOGGED_IN_USER'] = $user;
         $_SESSION['LOGGED_IN'] = true;
         // $log->logInfo("User {$user->username} loggin in");
         // unset($log);
         return true;
     } else {
         // $log->logError("{$email} tryed to log in");
         // unset($log);
         // header("Location: /index.php");
         // die();
         return false;
     }
 }
开发者ID:ShawnRyanRocks,项目名称:adlister.dev,代码行数:22,代码来源:Auth.php


注:本文中的User::findByUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。