2013-06-26 14:35:33 +00:00
|
|
|
<?php
|
2013-09-13 22:39:03 +00:00
|
|
|
/**
|
|
|
|
* This function is beign used to login a user.
|
|
|
|
* It will first check if the sent POST data returns a match with the DB, if it does, some session variables will be appointed to the user and he will be redirected to the index page again.
|
|
|
|
* If it didn't match, the template will be reloaded and a matching error message will be shown.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-06-26 14:35:33 +00:00
|
|
|
function login(){
|
2013-09-09 01:47:32 +00:00
|
|
|
global $INGAME_WEBPATH;
|
|
|
|
global $WEBPATH;
|
2013-06-26 14:35:33 +00:00
|
|
|
try{
|
2014-03-24 11:37:53 +00:00
|
|
|
$login_value = filter_var($_POST['LoginValue'],FILTER_SANITIZE_STRING);
|
2013-07-18 19:12:03 +00:00
|
|
|
$password = filter_var($_POST['Password'],FILTER_SANITIZE_STRING);
|
2014-03-24 11:37:53 +00:00
|
|
|
|
2013-09-13 22:39:03 +00:00
|
|
|
//check if the filtered sent POST data returns a match with the DB
|
2014-03-25 06:35:21 +00:00
|
|
|
$result = WebUsers::checkLoginMatch($login_value, $password);
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 16:28:37 +00:00
|
|
|
if( $result != "fail"){
|
2013-06-26 14:35:33 +00:00
|
|
|
//handle successful login
|
2014-03-25 06:35:21 +00:00
|
|
|
$_SESSION['user'] = $result['Login'];
|
|
|
|
$_SESSION['id'] = $result['UId'];
|
2013-09-09 01:47:32 +00:00
|
|
|
$_SESSION['ticket_user'] = serialize(Ticket_User::constr_ExternId($_SESSION['id']));
|
2013-08-25 04:27:44 +00:00
|
|
|
$user = new WebUsers($_SESSION['id']);
|
|
|
|
$_SESSION['Language'] = $user->getLanguage();
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-09-20 03:33:39 +00:00
|
|
|
$GETString = "";
|
|
|
|
foreach($_GET as $key => $value){
|
|
|
|
$GETString = $GETString . $key . '=' . $value . "&";
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
2013-09-20 03:33:39 +00:00
|
|
|
if($GETString != ""){
|
|
|
|
$GETString = '?'.$GETString;
|
|
|
|
}
|
|
|
|
|
2013-09-09 01:47:32 +00:00
|
|
|
|
2013-06-26 14:35:33 +00:00
|
|
|
//go back to the index page.
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-09-09 01:47:32 +00:00
|
|
|
if (Helpers::check_if_game_client()) {
|
2013-09-20 03:33:39 +00:00
|
|
|
header( 'Location: '. $INGAME_WEBPATH . $GETString);
|
2013-09-09 01:47:32 +00:00
|
|
|
}else{
|
2013-09-20 03:33:39 +00:00
|
|
|
header( 'Location: '. $WEBPATH . $GETString);
|
2013-09-09 01:47:32 +00:00
|
|
|
}
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-06-26 14:35:33 +00:00
|
|
|
}else{
|
|
|
|
//handle login failure
|
2013-07-02 01:36:49 +00:00
|
|
|
$result = Array();
|
2013-06-26 14:35:33 +00:00
|
|
|
$result['login_error'] = 'TRUE';
|
|
|
|
$result['no_visible_elements'] = 'TRUE';
|
|
|
|
helpers :: loadtemplate( 'login', $result);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-26 14:35:33 +00:00
|
|
|
}catch (PDOException $e) {
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
print_r($e);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-06-26 14:35:33 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2014-03-24 11:37:53 +00:00
|
|
|
}
|