2020-09-29 19:19:07 +00:00
|
|
|
<?php
|
2020-09-16 08:00:31 +00:00
|
|
|
|
2020-09-29 19:19:07 +00:00
|
|
|
class Session extends Dbh {
|
2020-09-16 08:00:31 +00:00
|
|
|
|
2020-09-29 19:19:07 +00:00
|
|
|
public function setSession($email) {
|
|
|
|
if(session_id() == '') session_start();
|
|
|
|
|
|
|
|
$sql = 'SELECT * FROM users WHERE email = ?';
|
|
|
|
$stmt = $this->connect()->prepare($sql);
|
|
|
|
$stmt->execute([$email]);
|
|
|
|
$row = $stmt->fetch();
|
|
|
|
$_SESSION['id'] = $row['id'];
|
|
|
|
$_SESSION['name'] = $row['name'];
|
|
|
|
$_SESSION['surname'] = $row['surname'];
|
|
|
|
$_SESSION['email'] = $email;
|
|
|
|
$_SESSION['gender'] = $row['gender'];
|
|
|
|
$_SESSION['password_change'] = $row['password_change'];
|
|
|
|
$_SESSION['profile_img'] = $row['profile_img'];
|
|
|
|
$_SESSION['profile_color'] = $row['profile_color'];
|
|
|
|
$_SESSION['google_profile_img'] = $row['google_profile_img'];
|
|
|
|
$_SESSION['facebook_profile_img'] = $row['facebook_profile_img'];
|
|
|
|
$_SESSION['github_profile_img'] = $row['github_profile_img'];
|
|
|
|
$_SESSION['profile_choice'] = $row['profile_choice'];
|
|
|
|
$_SESSION['googleID'] = $this->checkIfStringNull($row['googleID']);
|
|
|
|
$_SESSION['facebookID'] = $this->checkIfStringNull($row['facebookID']);
|
|
|
|
$_SESSION['githubID'] = $this->checkIfStringNull($row['githubID']);
|
|
|
|
$_SESSION['country'] = $this->getCountryWithID($row['country_id']);
|
2020-09-30 18:46:56 +00:00
|
|
|
$_SESSION['letter'] = strtoupper($email[0]);
|
2020-10-04 13:23:25 +00:00
|
|
|
if($row['password'] == null) $_SESSION['password-set'] = 'Not set';
|
|
|
|
else $_SESSION['password-set'] = '••••••••••';
|
|
|
|
$_SESSION['admin'] = $this->checkIfUserIsAdmin($email);
|
|
|
|
}
|
|
|
|
public function checkIfUserIsAdmin($email) {
|
|
|
|
$sql = 'SELECT * FROM admins WHERE user_id = (SELECT id FROM users WHERE email = ?);';
|
|
|
|
$stmt = $this->connect()->prepare($sql);
|
|
|
|
$stmt->execute([$email]);
|
|
|
|
$row = $stmt->fetch();
|
|
|
|
if($row) return 'yes';
|
|
|
|
else return 'no';
|
2020-09-29 19:19:07 +00:00
|
|
|
}
|
|
|
|
public function checkIfStringNull($string) {
|
|
|
|
if($string == null) return 0;
|
|
|
|
else return 1;
|
|
|
|
}
|
|
|
|
public function getCountryWithID($countryID) {
|
|
|
|
$sql = 'SELECT * FROM countries WHERE id = ?';
|
|
|
|
$stmt = $this->connect()->prepare($sql);
|
|
|
|
$stmt->execute([$countryID]);
|
|
|
|
$row = $stmt->fetch();
|
|
|
|
$country = array($row['name'], $row['acronym']);
|
|
|
|
return $country;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|