Created
October 16, 2013 20:40
-
-
Save jburns131/7014456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
public function loginAttempt() | |
{ | |
$sql = new Db(); | |
$form_helper = new FormHelper($this->basePath); | |
// Check for form errors | |
$form_helper->checkRequired(['login_name', 'password']); | |
$form_helper->sendErrors('/user/login'); | |
// No Errors | |
// Attempt login | |
$sql->dbSelect('users', | |
'id, display_name, password', | |
'login_name = :login_name', | |
[ | |
'login_name' => $_POST['login_name'], | |
] | |
); | |
$result = $sql->dbFetch('one'); | |
if ($result !== false) { | |
// User exists, check password | |
$passwordAttempt = $_POST['password']; | |
$passwordStored = $result['password']; | |
if ((crypt($passwordAttempt, $passwordStored)) == $passwordStored) { | |
// Setup Session | |
$this->segmentUser->display_name = $result['display_name']; | |
$this->sessionAxis->commit(); | |
$acms_id = crypt($result['display_name'], $this->acmsSalt); | |
$tableColumns = [ | |
'acms_id' => $acms_id, | |
'modified' => date("Y-m-d H:i:s", time()), | |
]; | |
$conditions = 'id = :id'; | |
$bind = ['id' => $result['id']]; | |
$result = $sql->dbUpdate('users', $tableColumns, $conditions, $bind); | |
$cookieName = str_replace('.', '_', $_SERVER['SERVER_NAME']) . '_acms'; | |
setcookie($_SERVER['SERVER_NAME'] . '_acms', false, time() - 3600, '/', $_SERVER['SERVER_NAME']); | |
if ((isset($_POST['stay_logged_in'])) && ($_POST['stay_logged_in'] === '1')) { | |
setcookie($_SERVER['SERVER_NAME'] . '_acms', $acms_id, time()+60*60*24*365, '/', $_SERVER['SERVER_NAME']); | |
} else { | |
setcookie($_SERVER['SERVER_NAME'] . '_acms', $acms_id, 0, '/', $_SERVER['SERVER_NAME']); | |
} | |
header('Location: ' . $this->basePath); | |
exit; | |
} else { | |
$form_helper->addError('invalid_password'); | |
$form_helper->sendErrors('/user/login'); | |
} | |
} else { | |
$form_helper->addError('invalid_login_name'); | |
$form_helper->sendErrors('/user/login'); | |
} | |
return false; | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment