khanat-opennel-code/code/web/public_php/ams/func/login.php

60 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* 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
*/
function login(){
global $INGAME_WEBPATH;
global $WEBPATH;
try{
$login_value = filter_var($_POST['LoginValue'],FILTER_SANITIZE_STRING);
$password = filter_var($_POST['Password'],FILTER_SANITIZE_STRING);
//check if the filtered sent POST data returns a match with the DB
$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"){
//handle successful login
$_SESSION['user'] = $result['Login'];
$_SESSION['id'] = $result['UId'];
$_SESSION['ticket_user'] = serialize(Ticket_User::constr_ExternId($_SESSION['id']));
$user = new WebUsers($_SESSION['id']);
$_SESSION['Language'] = $user->getLanguage();
2014-09-03 05:06:43 +00:00
$GETString = "";
foreach($_GET as $key => $value){
$GETString = $GETString . $key . '=' . $value . "&";
2014-09-03 05:06:43 +00:00
}
if($GETString != ""){
$GETString = '?'.$GETString;
}
//go back to the index page.
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
if (Helpers::check_if_game_client()) {
header( 'Location: '. $INGAME_WEBPATH . $GETString);
}else{
header( 'Location: '. $WEBPATH . $GETString);
}
2014-09-03 05:23:39 +00:00
throw new SystemExit();
}else{
//handle login failure
2013-07-02 01:36:49 +00:00
$result = Array();
$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
}
}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();
}
2014-09-03 05:06:43 +00:00
}