Repair user login logout

This commit is contained in:
Léo Serre 2018-10-13 15:25:37 +02:00
parent 228cacb664
commit a701597333
3 changed files with 17 additions and 17 deletions

View File

@ -8,7 +8,7 @@ if(isset($controller->splitted_url[1])) {
switch ($controller->splitted_url[1]) { switch ($controller->splitted_url[1]) {
case 'login': case 'login':
$head['title'] = "Connexion"; $head['title'] = "Connexion";
if ($user->role == 0) { if ($user->rank == "visitor") {
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
// PROCESS DATA FROM FORM // PROCESS DATA FROM FORM
$user = new User(); $user = new User();
@ -34,14 +34,14 @@ if(isset($controller->splitted_url[1])) {
case 'signin': case 'signin':
$head['js'] = "d.captcha.js"; $head['js'] = "d.captcha.js";
$head['title'] = "Création de compte"; $head['title'] = "Création de compte";
if ($user->role == 0) { if ($user->rank == "visitor") {
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
// PROCESS DATA FROM FORM // PROCESS DATA FROM FORM
$user = new User(); $user = new User();
$user->password = sha1($_POST['password']); $user->password = sha1($_POST['password']);
$user->name = $_POST['login']; $user->name = $_POST['login'];
$user->mail = strtolower($_POST['mail']); $user->mail = strtolower($_POST['mail']);
$user->role = 400; $user->rank = "registered";
$user->avatar = 'f'; $user->avatar = 'f';
$user->locale = "fr"; $user->locale = "fr";
@ -75,7 +75,7 @@ if(isset($controller->splitted_url[1])) {
break; break;
case 'password_lost': case 'password_lost':
$head['title'] = "Récupération de mot de passe"; $head['title'] = "Récupération de mot de passe";
if ($user->role == 0) { if ($user->rank == "visitor") {
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
// PROCESS DATA FROM FORM // PROCESS DATA FROM FORM
$user = new User(); $user = new User();
@ -95,7 +95,7 @@ if(isset($controller->splitted_url[1])) {
} }
break; break;
case 'p': case 'p':
if ($user->role >= 200) { if ($user->rank_is_higher("registered")) {
$userProfile = new User(); $userProfile = new User();
if (!isset($controller->splitted_url[2]) OR $controller->splitted_url[2]=="") { if (!isset($controller->splitted_url[2]) OR $controller->splitted_url[2]=="") {
// WE DISPLAY THE CONNECTED USER PROFILE // WE DISPLAY THE CONNECTED USER PROFILE
@ -111,7 +111,7 @@ if(isset($controller->splitted_url[1])) {
} }
// If we are editing the profile // If we are editing the profile
if(isset($controller->splitted_url[3]) && $controller->splitted_url[3]=="edit" && ($user->role >= 800 || $user->id == $userProfile->id)) { if(isset($controller->splitted_url[3]) && $controller->splitted_url[3]=="edit" && ($user->rank_is_higher("moderator") || $user->id == $userProfile->id)) {
$head['js'] = "d.avatar.js"; $head['js'] = "d.avatar.js";
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
$receivedUser = new User(); $receivedUser = new User();
@ -128,8 +128,8 @@ if(isset($controller->splitted_url[1])) {
if($_POST['password']!='') if($_POST['password']!='')
$userProfile->password=sha1($_POST['password']); $userProfile->password=sha1($_POST['password']);
$userProfile->locale=$_POST['locale']; $userProfile->locale=$_POST['locale'];
if($user->role>=1000) if($user->rank_is_higher("administrator"))
$userProfile->role = $_POST['role']; $userProfile->rank = $_POST['rank'];
$userProfile->website=$_POST['website']; $userProfile->website=$_POST['website'];
// Is the file correctly sent to the server ? // Is the file correctly sent to the server ?
@ -164,7 +164,7 @@ if(isset($controller->splitted_url[1])) {
} }
// If we are displaying the profile // If we are displaying the profile
else { else {
if (isset($_POST['submit']) && $user->role >= 400) { if (isset($_POST['submit']) && $user->rank_is_higher("registered")) {
// PROCESS DATA FROM CONTACT FORM // PROCESS DATA FROM CONTACT FORM
$message = $_POST['message']; $message = $_POST['message'];
@ -179,7 +179,7 @@ if(isset($controller->splitted_url[1])) {
} }
break; break;
case 'member_list': case 'member_list':
if ($user->role >= 200) { if ($user->rank_is_higher("registered")) {
$rows_per_pages = 50; $rows_per_pages = 50;
// Get the correct page number // Get the correct page number
if (!isset($controller->splitted_url[2]) OR $controller->splitted_url[2]=="" OR $controller->splitted_url[2]=="0" OR !is_numeric($controller->splitted_url[2])) { if (!isset($controller->splitted_url[2]) OR $controller->splitted_url[2]=="" OR $controller->splitted_url[2]=="0" OR !is_numeric($controller->splitted_url[2])) {

View File

@ -6,14 +6,13 @@ ini_set("session.cookie_lifetime",60*60*24*30);
session_start(); session_start();
$user = new User(); $user = new User();
$user->rank == 'visitor'; // All users are visitors $user->rank = "visitor"; // All users are visitors
if(isset($_SESSION['userid'])) { if(isset($_SESSION['userid'])) {
$user->checkID($_SESSION['userid']); $user->checkID($_SESSION['userid']);
if ($user->get_id() != 0) { if ($user->checkID($_SESSION['userid'])) {
$user->updateLoginDate(); $user->updateLoginDate();
$user->populate(); //setlocale(LC_ALL, $config['locales'][$user->locale][4]);
setlocale(LC_ALL, $config['locales'][$user->locale][4]);
} }
else { else {
session_destroy(); session_destroy();

View File

@ -81,6 +81,7 @@ class User
** Populate the object using raw data from SQL ** Populate the object using raw data from SQL
*****/ *****/
private function populate($row) { private function populate($row) {
$this->id = $row['id'];
$this->name = $row['name']; $this->name = $row['name'];
$this->version = $row['version']; $this->version = $row['version'];
$this->email = $row['email']; $this->email = $row['email'];
@ -306,16 +307,16 @@ class User
public function updateLoginDate() { public function updateLoginDate() {
global $config; global $config;
$this->lastlogin = date('r'); $this->visit_date = date('r');
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n"); or die ("Could not connect to server\n");
$query = "UPDATE users SET lastlogin = $1 WHERE id = $2"; $query = "UPDATE users SET visit_date = $1 WHERE id = $2";
pg_prepare($con, "prepare1", $query) pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n"); or die ("Cannot prepare statement\n");
pg_execute($con, "prepare1", array($this->lastlogin, $this->id)) pg_execute($con, "prepare1", array($this->visit_date, $this->id))
or die ("Cannot execute statement\n"); or die ("Cannot execute statement\n");
pg_close($con); pg_close($con);