本文整理匯總了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;
}
}
示例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();
}
}