2013-06-06 06:04:46 +00:00
|
|
|
<?php
|
2013-09-13 22:39:03 +00:00
|
|
|
/**
|
|
|
|
* This function is beign used to add a new user to the www database.
|
|
|
|
* it will first check if the sent $_POST variables are valid for registering, if one or more rules are broken (eg the username is too short) the template will be reloaded
|
|
|
|
* but this time with the appropriate error messages. If the checking was successful it will call the write_user() function (located in this same file). That function will create
|
|
|
|
* a new www user and matching ticket_user. It will also push the newly created user to the shard. In case the shard is offline, the new user will be temporary stored in the ams_querycache,
|
|
|
|
* waiting for the sync cron job to update it.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-06-17 19:42:33 +00:00
|
|
|
function add_user(){
|
2013-09-09 01:47:32 +00:00
|
|
|
global $INGAME_WEBPATH;
|
2013-07-01 16:28:37 +00:00
|
|
|
$params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'ConfirmPass' => $_POST["ConfirmPass"], 'Email' => $_POST["Email"]);
|
2013-08-05 15:31:36 +00:00
|
|
|
$webUser = new WebUsers();
|
2013-09-13 22:39:03 +00:00
|
|
|
|
|
|
|
//check if the POST variables are valid, before actual registering
|
2013-06-29 03:02:54 +00:00
|
|
|
$result = $webUser->check_Register($params);
|
2013-06-28 04:18:23 +00:00
|
|
|
|
2014-09-03 06:24:41 +00:00
|
|
|
global $SITEBASE;
|
|
|
|
require_once($SITEBASE . '/inc/settings.php');
|
2013-06-19 04:50:08 +00:00
|
|
|
// if all are good then create user
|
|
|
|
if ( $result == "success"){
|
|
|
|
$edit = array(
|
|
|
|
'name' => $_POST["Username"],
|
|
|
|
'pass' => $_POST["Password"],
|
|
|
|
'mail' => $_POST["Email"],
|
|
|
|
'init' => $_POST["Email"],
|
|
|
|
'unhashpass' => $_POST["Password"],
|
|
|
|
'status' => 1,
|
2013-06-19 21:53:53 +00:00
|
|
|
'access' => $_SERVER['REQUEST_TIME']
|
2013-06-19 04:50:08 +00:00
|
|
|
);
|
2013-06-26 02:03:16 +00:00
|
|
|
$status = write_user( $edit );
|
2013-09-17 02:58:02 +00:00
|
|
|
if(Helpers::check_if_game_client()){
|
|
|
|
//if registering ingame then we have to set the header and dont need to reload the template.
|
|
|
|
header('Location: email_sent.php');
|
2014-09-03 06:30:25 +00:00
|
|
|
throw new SystemExit();
|
2013-09-17 02:58:02 +00:00
|
|
|
}
|
2014-09-03 06:24:41 +00:00
|
|
|
$pageElements = settings();
|
|
|
|
$pageElements['ingame_webpath'] = $INGAME_WEBPATH;
|
|
|
|
$pageElements['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
|
|
|
|
$pageElements['SUCCESS_ADD'] = $status;
|
|
|
|
if (isset($_GET['page']) && $_GET['page']=="settings"){
|
|
|
|
helpers :: loadtemplate( 'settings', $pageElements);
|
|
|
|
}else{
|
|
|
|
$pageElements['no_visible_elements'] = 'TRUE';
|
|
|
|
helpers :: loadtemplate( 'register_feedback', $pageElements);
|
|
|
|
}
|
2014-09-03 06:30:25 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 06:24:41 +00:00
|
|
|
}elseif (isset($_GET['page']) && $_GET['page']=="settings"){
|
|
|
|
$pageElements = array_merge(settings(), $result);
|
2014-02-09 04:15:38 +00:00
|
|
|
// pass error and reload template accordingly
|
2014-09-03 06:24:41 +00:00
|
|
|
$pageElements['prevUsername'] = $_POST["Username"];
|
|
|
|
$pageElements['prevPassword'] = $_POST["Password"];
|
|
|
|
$pageElements['prevConfirmPass'] = $_POST["ConfirmPass"];
|
|
|
|
$pageElements['prevEmail'] = $_POST["Email"];
|
|
|
|
$pageElements['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
|
2014-09-03 07:23:47 +00:00
|
|
|
$pageElements['do'] = "add_user";
|
2014-09-03 06:24:41 +00:00
|
|
|
helpers :: loadtemplate( 'settings', $pageElements);
|
2014-09-03 06:30:25 +00:00
|
|
|
throw new SystemExit();
|
2013-06-18 17:48:54 +00:00
|
|
|
}else{
|
2013-09-13 22:39:03 +00:00
|
|
|
// pass error and reload template accordingly
|
2013-06-19 04:50:08 +00:00
|
|
|
$result['prevUsername'] = $_POST["Username"];
|
|
|
|
$result['prevPassword'] = $_POST["Password"];
|
|
|
|
$result['prevConfirmPass'] = $_POST["ConfirmPass"];
|
|
|
|
$result['prevEmail'] = $_POST["Email"];
|
|
|
|
$result['no_visible_elements'] = 'TRUE';
|
2014-02-09 04:15:38 +00:00
|
|
|
$pageElements['ingame_webpath'] = $INGAME_WEBPATH;
|
2013-06-19 04:50:08 +00:00
|
|
|
helpers :: loadtemplate( 'register', $result);
|
2014-09-03 06:30:25 +00:00
|
|
|
throw new SystemExit();
|
2013-06-17 05:57:09 +00:00
|
|
|
}
|
2013-06-18 17:48:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 22:39:03 +00:00
|
|
|
//use the valid userdata to create the new user.
|
2013-06-19 21:53:53 +00:00
|
|
|
function write_user($newUser){
|
2013-07-06 16:27:25 +00:00
|
|
|
|
2013-06-26 01:26:25 +00:00
|
|
|
//create salt here, because we want it to be the same on the web/server
|
2013-06-29 03:02:54 +00:00
|
|
|
$hashpass = crypt($newUser["pass"], WebUsers::generateSALT());
|
2013-06-19 21:53:53 +00:00
|
|
|
|
2013-06-26 01:26:25 +00:00
|
|
|
$params = array(
|
2014-05-27 22:18:44 +00:00
|
|
|
'Login' => $newUser["name"],
|
|
|
|
'Password' => $hashpass,
|
|
|
|
'Email' => $newUser["mail"]
|
2013-06-26 01:26:25 +00:00
|
|
|
);
|
|
|
|
try{
|
2013-08-25 04:27:44 +00:00
|
|
|
//make new webuser
|
2014-05-27 22:18:44 +00:00
|
|
|
$user_id = WebUsers::createWebuser($params['Login'], $params['Password'], $params['Email']);
|
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
//Create the user on the shard + in case shard is offline put copy of query in query db
|
|
|
|
//returns: ok, shardoffline or liboffline
|
|
|
|
$result = WebUsers::createUser($params, $user_id);
|
2013-09-09 21:30:45 +00:00
|
|
|
Users::createPermissions(array($newUser["name"]));
|
2013-07-08 12:49:03 +00:00
|
|
|
|
2013-06-26 01:26:25 +00:00
|
|
|
|
|
|
|
}catch (PDOException $e) {
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
print_r($e);
|
2014-09-03 06:30:25 +00:00
|
|
|
throw new SystemExit();
|
2013-06-26 01:26:25 +00:00
|
|
|
}
|
2013-06-26 02:03:16 +00:00
|
|
|
|
|
|
|
return $result;
|
2013-06-18 17:48:54 +00:00
|
|
|
|
2013-06-26 02:03:16 +00:00
|
|
|
}
|