Archived
1
0

Fix remember me feature

This commit is contained in:
Marcel 2018-12-30 18:36:38 +01:00
parent 5652efc47e
commit b2044e15b6

View File

@ -37,17 +37,6 @@
} }
} }
public function logout() {
delete_cookie('rememberMe');
delete_cookie('rememberToken');
$userID = $_SESSION['user']['ID'];
$this->db->query('UPDATE users SET isCurrentlyOnline = false, rememberToken = null WHERE ID = ?', [$userID]);
unset($_SESSION['user']);
$_SESSION['loggedOut'] = true;
}
public function getLoginData($username) public function getLoginData($username)
{ {
$this->db->cache_off(); $this->db->cache_off();
@ -64,12 +53,6 @@
return $passwordHash; return $passwordHash;
} }
private function generateRandomUserHash($username) {
$base = uniqid();
$seed = $username . date(time());
return md5($base . $seed);
}
public function startLoginSession($logindata, $rememberMe) public function startLoginSession($logindata, $rememberMe)
{ {
$this->reloadLoginSession($logindata); $this->reloadLoginSession($logindata);
@ -91,19 +74,44 @@
public function reloadLoginSession($logindata) public function reloadLoginSession($logindata)
{ {
$_SESSION['user']['displayname'] = $logindata['displayname']; list(
$_SESSION['user']['username'] = $logindata['username']; 'ID' => $id,
$_SESSION['user']['rank'] = $logindata['rank']; 'username' => $username,
$_SESSION['user']['ID'] = $logindata['ID']; 'displayname' => $displayname,
$_SESSION['user']['ads'] = $logindata['showAds']; 'rank' => $rank,
$profilePic = $logindata['profile_picture']; 'showAds' => $ads,
if (empty($profilePic)) { 'profile_picture' => $avatar,
$_SESSION['user']['profilePic'] = '/assets/images/steam.jpg'; ) = $logindata;
} else {
$_SESSION['user']['profilePic'] = $profilePic; $this->session->set_userdata('user', [
'displayname' => $displayname,
'username' => $username,
'rank' => $rank,
'ID' => $id,
'ads' => $ads,
'permissions' => $this->UserModel->getPermissions($id),
'profilePic' => !empty($avatar) ? $avatar : '/assets/images/steam.jpg',
]);
} }
$_SESSION['user']['permissions'] = $this->UserModel->getPermissions($logindata['ID']); private function generateRandomUserHash($username)
{
$base = uniqid();
$seed = $username . date(time());
return md5($base . $seed);
}
public function logout()
{
echo 'wird aufgerufen?';
delete_cookie('rememberMe');
delete_cookie('rememberToken');
$userID = $_SESSION['user']['ID'];
$this->db->query('UPDATE users SET isCurrentlyOnline = false, rememberToken = null WHERE ID = ?', [$userID]);
unset($_SESSION['user']);
$_SESSION['loggedOut'] = true;
} }
public function isTrashMail($email) public function isTrashMail($email)
@ -161,7 +169,7 @@
$result = $this->db->query('SELECT rememberToken FROM users WHERE ID = ?', [$logindata['ID']])->result_array(); $result = $this->db->query('SELECT rememberToken FROM users WHERE ID = ?', [$logindata['ID']])->result_array();
$token = $result[0]['rememberToken']; $token = $result[0]['rememberToken'];
if ($token !== null && sizeof($token) == 32 && $_COOKIE['rememberToken'] == $token) { if ($token !== null && strlen($token) == 32 && $_COOKIE['rememberToken'] == $token) {
$this->startLoginSession($logindata, 'on'); $this->startLoginSession($logindata, 'on');
} }
} }