本文整理汇总了PHP中User::find_by_username方法的典型用法代码示例。如果您正苦于以下问题:PHP User::find_by_username方法的具体用法?PHP User::find_by_username怎么用?PHP User::find_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::find_by_username方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
if ($this->input->post()) {
if (empty($this->input->post('username'))) {
$this->content_view = "forgot_pass/index";
} else {
$user_to_reset = User::find_by_username($this->input->post('username'));
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < 16; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
$user_to_reset->pass_key = $randstring;
$user_to_reset->save();
$link = "http://" . $_SERVER['HTTP_HOST'] . "/forgot_pass/reset_pass/" . $randstring;
$email_content = "A password reset has been requested for your account. If you did not request this reset please disregard this message. Otherwise, open the link below to continue.<br /><a href=" . $link . ">" . $link . "</a>";
$config = array('protocol' => 'sendmail', 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE);
$this->load->library('email', $config);
$this->email->from('noreply@smleaderboards.net', 'Stepmania Leaderboards');
$this->email->to($user_to_reset->email);
$this->email->subject('Stepmania Leaderboards - Password Recovery');
$this->email->message($email_content);
$this->email->send();
$this->content_view = "forgot_pass/recover_confirm";
}
} else {
$this->content_view = "forgot_pass/index";
}
}
示例2: authenticate
public static function authenticate($username, $password)
{
$user = User::find_by_username($username);
if (!$user->active) {
return false;
}
$hashed_password = static::hash_password($password, $user->salt);
return $hashed_password === $user->password;
}
示例3: testMakesApiKey
public function testMakesApiKey()
{
$user = User::create(array('username' => 'bobby', 'email' => 'foo@mail.com', 'password' => 'foo'));
$api = $user->api_key;
$user->active = 1;
$user->save();
$user2 = User::find_by_username('bobby');
$this->assertEquals($api, $user2->api_key);
}
示例4: show
function show($id)
{
$user = User::find($id);
$all = User::find_by_username("rajesh");
$allu = User::find_by_username_and_email("rajesh", "pillai.rajesh@gmail.com");
ActiveRecord::println($all);
ActiveRecord::println($allu);
return $this->View(array('view' => 'show', 'model' => $user));
}
示例5: create
public function create($request)
{
$data = $request->getParameters();
if (isset($data['submitLogin']) && !Session::isActive()) {
$is_admin = isset($data['is_admin']) && $data['is_admin'] == 1;
$username = Utils::secure($data['username']);
$password = Utils::secure($data['pass']);
if (User::find_by_username($username)) {
$user = User::find_by_username($username);
$current_log_fail = $user->getLogFails();
if (!$user->isAllowedToAttemptLogin()) {
$next_timestamp = $current_log_fail['next_try'];
$last_try_timestamp = $current_log_fail['last_try'];
$nb_try = $current_log_fail['nb_try'];
$next_try_tps = $next_timestamp - Utils::tps();
$next_try_min = floor($next_try_tps / 60);
$next_try_sec = round($next_try_tps - $next_try_min * 60);
$next_try_str = "{$next_try_min} m et {$next_try_sec} s";
$data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
$data['currentPageTitle'] = 'Connexion';
$response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
$response->addMessage(ViewMessage::error($nb_try . " tentatives de connexions à la suite pour ce compte. Veuillez patienter {$next_try_str}"));
return $response;
}
$realPass = User::find_by_username($username)->getPassword();
if (password_verify($password, $realPass)) {
User::connect($username, 1);
$user->resetLogFails();
return new RedirectResponse($data['redirect'] ? urldecode($data['redirect']) : WEBROOT);
} else {
if (sha1($password) == $realPass) {
$user->resetLogFails();
User::connect($username, 1)->setPassword(password_hash($password, PASSWORD_BCRYPT));
return new RedirectResponse($data['redirect'] ? urldecode($data['redirect']) : WEBROOT);
}
if (!$user->isIntervalBetweenTwoLogAttemptElapsed() || !$current_log_fail) {
$user->addLogFail();
} else {
$user->resetLogFails();
$user->addLogFail();
}
$data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
$data['currentPageTitle'] = 'Connexion';
$response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
$response->addMessage(ViewMessage::error('Mot de passe incorrect'));
return $response;
}
} else {
$data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
$data['currentPageTitle'] = 'Connexion';
$response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
$response->addMessage(ViewMessage::error('Ce nom d\'utilisateur n\'existe pas'));
return $response;
}
}
}
示例6: validate_login
public static function validate_login($username, $password)
{
$user = User::find_by_username($username, array('active' => 1));
if ($user && $user->validate_password($password)) {
User::login($user->id);
return $user;
} else {
return FALSE;
}
}
示例7: testDeleteBobsPackage
public function testDeleteBobsPackage()
{
$_SERVER['SERVER_NAME'] = 'bob.localhost.com';
$count = Version::count();
$p = Package::find_by_name('bobs_other_package');
$v = Version::find('first', array('package_id' => $p->id, 'version' => '0.0.1'));
$this->delete('delete', array(), array('id' => $v->package_id, 'version' => $v->id), array('user' => User::find_by_username('bob')->id));
$this->assertEquals($count - 1, Version::count(array('cache' => false)));
$this->assertFalse(Version::exists('id', $v->id));
$this->assertRedirect(url_for('PackageController', 'show', $p->id));
}
示例8: testUploadFailbadSig
public function testUploadFailbadSig()
{
$localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'joes_other_package-1.0.4.tgz');
$sig = PackageVerifyTest::calculatePackageSignature($localfile);
$user = User::find_by_username('joe');
try {
$p = Package::from_upload(array('file' => $localfile, 'sig' => $sig, 'user' => $user), true);
} catch (NimbleException $e) {
$this->assertEquals("Invalid package signature", $e->getMessage());
}
}
示例9: testUploadHtmlFailsnoFile
public function testUploadHtmlFailsnoFile()
{
$localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-1.0.4.tgz');
$_FILES = array();
$_FILES['file'] = array();
$_FILES['file']['tmp_name'] = '';
$key = md5(time());
$this->post('upload', array(), array('upload_key' => $key), array('upload_key' => md5(md5(time())), 'user' => User::find_by_username('bob')->id), 'html');
$this->assertEquals($_SESSION['flashes']['notice'], 'Package channel does not match bob.localhost.com');
$this->assertRedirect(url_for('LandingController', 'user_index', User::find_by_username('bob')->username));
}
示例10: testDeleteBobsPackage
public function testDeleteBobsPackage()
{
$_SERVER['SERVER_NAME'] = 'bob.localhost.com';
$count = Package::count();
$v_count = Version::count();
$p = Package::find_by_name('bobs_other_package');
$versions = $p->count('versions');
$this->delete('delete', array(), array('id' => $p->id), array('user' => User::find_by_username('bob')->id));
$this->assertEquals($count - 1, Package::count(array('cache' => false)));
$this->assertEquals($v_count - $versions, Version::count(array('cache' => false)));
$this->assertRedirect('/');
}
示例11: email_reset_token_username
function email_reset_token_username($username)
{
// $user = find_one_in_fake_db('users', 'username', sql_prep($username));
$user = User::find_by_username($username);
if ($user) {
// This is where you would connect to your emailer
// and send an email with a URL that includes the token.
$user->send_email();
return true;
} else {
return false;
}
}
示例12: validate
public function validate()
{
$this->create_inital_user();
$this->error_if_empty("username");
$this->error_if_empty("password");
$this->user = User::find_by_username($this->params["username"]);
if ($this->user) {
if ($this->user->check_password($this->params["password"])) {
return true;
} else {
$this->add_error("password", "Invalid password");
}
} else {
$this->add_error("username", "Invalid username");
}
return false;
}
示例13: show
public function show()
{
if ($this->is_logged_in()) {
$this->login_user();
}
try {
$user = User::find_by_username($_GET['username']);
$this->package = Package::find('first', array('conditions' => array('user_id' => $user->id, 'name' => $_GET['package_name'])));
$this->version = Version::find('first', array('conditions' => array('package_id' => $this->package->id, 'version' => $_GET['version'])));
$this->title = $this->package->name . ' ' . $this->version->version;
Nimble::set_title($this->title);
$this->data = unserialize($this->version->meta);
} catch (NimbleRecordNotFound $e) {
Nimble::flash('notice', 'Version does not exist');
$this->redirect_to('/');
}
}
示例14: show
public function show()
{
try {
$user = User::find_by_username($_GET['username']);
switch ($this->format) {
case 'xml':
$this->header('Content-Type: text/xml', 200);
$this->package = Package::find('first', array('conditions' => array('user_id' => $user->id, 'name' => $_GET['package_name'])));
echo $this->package->to_xml();
$this->layout = false;
$this->has_rendered = true;
break;
case 'json':
$this->header('Content-type: application/json', 200);
$this->package = Package::find('first', array('conditions' => array('user_id' => $user->id, 'name' => $_GET['package_name'])));
echo $this->package->to_json();
$this->layout = false;
$this->has_rendered = true;
break;
default:
if ($this->is_logged_in()) {
$this->login_user();
}
try {
$this->set_default_side_bar();
$this->package = Package::find('first', array('conditions' => array('user_id' => $user->id, 'name' => $_GET['package_name'])));
$this->title = $this->package->name;
Nimble::Set_title($this->title);
$this->versions = Version::find_all(array('limit' => '0,5', 'conditions' => array('package_id' => $this->package->id), 'order' => 'version DESC'));
$this->total_versions = $this->package->count('versions');
$this->version = $this->package->current_version();
if ($this->version !== false) {
$this->data = unserialize($this->version->meta);
}
} catch (NimbleRecordNotFound $e) {
Nimble::flash('notice', 'The package you were looking for does not exsist');
$this->redirect_to('/');
}
break;
}
} catch (NimbleRecordNotFound $e) {
Nimble::flash('notice', 'The package you were looking for does not exsist');
$this->redirect_to('/');
}
}
示例15: login
public function login()
{
$this->title = 'Login';
Nimble::set_title($this->title);
try {
if (isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['password']) && User::authenticate($_POST['username'], $_POST['password'])) {
$user = User::find_by_username($_POST['username']);
$_SESSION['user'] = $user->id;
$this->redirect_if_logged_in();
} else {
Nimble::flash('notice', 'Invalid Login Information');
$this->render('login/form.php');
}
} catch (NimbleRecordNotFound $e) {
Nimble::flash('notice', 'Invalid Login Information');
$this->render('login/form.php');
}
}