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


PHP UserRepository::getOneByUsername方法代码示例

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


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

示例1: userLogin

 /**
  * log the user - if not exists register him/her and then log the user
  *
  * @return	void
  */
 public static function userLogin()
 {
     $errors = array();
     $hash = addslashes(Utils::get('hash'));
     if ($hash) {
         $userRepository = new UserRepository();
         $user = $userRepository->getOneByHash($hash);
     } else {
         if (Utils::post('username') != '') {
             $username = addslashes(Utils::post('username'));
             if (!ctype_alnum($username)) {
                 $errors['username'] = 'V používateľskom mene môžeš použiť len alfanumerické znaky';
                 // TODO localize
             }
         } else {
             $errors['username'] = 'Musíš vyplniť používateľské meno';
             // TODO localize
         }
         if (Utils::post('password') != '') {
             $password = md5(addslashes(Utils::post('password')));
         } else {
             $errors['password'] = 'Musíš vyplniť heslo';
             // TODO localize
         }
         if (empty($errors)) {
             $userRepository = new UserRepository();
             $userExist = $userRepository->getOneByUsername($username);
             if ($userExist === NULL) {
                 $colorRepository = new ColorRepository();
                 $count = $colorRepository->getCountAll();
                 $rand = rand(1, $count);
                 $params = array('username' => $username, 'password' => $password, 'color' => $rand);
                 $user = new User($params);
                 $user = $user->save(TRUE);
             } elseif ($userExist['password'] != $password) {
                 $errors['password'] = 'Nesprávne heslo';
             } else {
                 $user = $userExist;
             }
         }
     }
     if ($user && empty($errors)) {
         // TODO po prihlaseni treba nejako zmazat v memcachi query, ktora vybera usera podla cookie_value
         // lebo teraz to stale vracia vysledok z memcache -> ked sa prihlasim v dvoch browsroch, v obidvoch to funguje
         // neodhlasi ma z toho prveho
         $cookieValue = md5(time() . $user['id'] . $user['username']);
         DB::update(DB_PREFIX . 'user', array('cookie_value' => $cookieValue), 'id = ' . $user['id']);
         $expire = Utils::post('remember') == 1 ? strtotime('+1 year') : 0;
         setcookie(self::$cookieName, $cookieValue, $expire, '/');
         return TRUE;
     } else {
         return $errors;
     }
 }
开发者ID:Tomeno,项目名称:lulcobang,代码行数:59,代码来源:LoggedUser.php

示例2: run

 protected function run()
 {
     if ($this->check == self::OK) {
         $colorRepository = new ColorRepository();
         $count = $colorRepository->getCountAll();
         $randomColor = mt_rand(1, $count);
         $userParams = array('username' => 'AI-' . str_pad(mt_rand(0, 999), 3, 0, STR_PAD_LEFT), 'color' => $randomColor);
         $userRepository = new UserRepository();
         $newUser = $userRepository->getOneByUsername($userParams['username']);
         if (!$newUser) {
             $newUser = new User($userParams);
             $newUser = $newUser->save(TRUE);
         }
         $playersCount = GameUtils::getPosition($this->game);
         $strategyRepository = new AiStrategyRepository();
         $strategyRepository->addOrderBy(array('RAND()' => ''));
         $strategy = $strategyRepository->getOneBy();
         $params = array('game' => $this->game['id'], 'user' => $newUser['id'], 'seat' => GameUtils::getSeatOnPosition($playersCount), 'ai_strategy' => $strategy['id']);
         $player = new Player($params);
         $player->save();
     }
 }
开发者ID:Tomeno,项目名称:lulcobang,代码行数:22,代码来源:AddAiPlayerCommand.php


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