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

@ -23,7 +23,7 @@
}
$logindata = $logindata[0];
if($logindata['isDeleted']) {
if ($logindata['isDeleted']) {
$_SESSION['notice'] .= '<div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-label="Schließen"><span aria-hidden="true">&times;</span></button><strong>Der Account wurde deaktiviert!</strong> Dein Account wurde vom System deaktiviert, womöglich aufgrund von Fehlverhalten (beispielsweise in Form von anstößigen, unerwünschten, diskriminierenden oder volksverhetzenden Kommentaren, Posts oder Namen). Solltest du dies für ein Fehler halten, nutze bitte das Kontaktformular, um dich <b>höflich</b> zu beschweren.</div>';
return;
}
@ -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)
{
$this->db->cache_off();
@ -64,12 +53,6 @@
return $passwordHash;
}
private function generateRandomUserHash($username) {
$base = uniqid();
$seed = $username . date(time());
return md5($base . $seed);
}
public function startLoginSession($logindata, $rememberMe)
{
$this->reloadLoginSession($logindata);
@ -91,19 +74,44 @@
public function reloadLoginSession($logindata)
{
$_SESSION['user']['displayname'] = $logindata['displayname'];
$_SESSION['user']['username'] = $logindata['username'];
$_SESSION['user']['rank'] = $logindata['rank'];
$_SESSION['user']['ID'] = $logindata['ID'];
$_SESSION['user']['ads'] = $logindata['showAds'];
$profilePic = $logindata['profile_picture'];
if (empty($profilePic)) {
$_SESSION['user']['profilePic'] = '/assets/images/steam.jpg';
} else {
$_SESSION['user']['profilePic'] = $profilePic;
list(
'ID' => $id,
'username' => $username,
'displayname' => $displayname,
'rank' => $rank,
'showAds' => $ads,
'profile_picture' => $avatar,
) = $logindata;
$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)
@ -161,7 +169,7 @@
$result = $this->db->query('SELECT rememberToken FROM users WHERE ID = ?', [$logindata['ID']])->result_array();
$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');
}
}