本文整理汇总了PHP中UserRepository::getOneByHash方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRepository::getOneByHash方法的具体用法?PHP UserRepository::getOneByHash怎么用?PHP UserRepository::getOneByHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository::getOneByHash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}