khanat-code-old/code/web/public_php/ams/func/add_user.php

91 lines
4 KiB
PHP
Raw Normal View History

2013-06-06 06:04:46 +00:00
<?php
/**
* 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
*/
function add_user(){
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();
2014-09-03 05:06:43 +00:00
//check if the POST variables are valid, before actual registering
$result = $webUser->check_Register($params);
// 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,
'access' => $_SERVER['REQUEST_TIME']
);
$status = write_user( $edit );
if(Helpers::check_if_game_client()){
//if registering ingame then we have to set the header and dont need to reload the template.
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
header('Location: email_sent.php');
2014-09-03 05:23:39 +00:00
throw new SystemExit();
}
$pageElements['status'] = $status;
$pageElements['no_visible_elements'] = 'TRUE';
$pageElements['ingame_webpath'] = $INGAME_WEBPATH;
helpers :: loadtemplate( 'register_feedback', $pageElements);
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2014-09-03 05:06:43 +00:00
}elseif (isset($_POST['page']) && $_POST['page']=="settings"){
2014-02-09 04:15:38 +00:00
// pass error and reload template accordingly
$result['prevUsername'] = $_POST["Username"];
$result['prevPassword'] = $_POST["Password"];
$result['prevConfirmPass'] = $_POST["ConfirmPass"];
$result['prevEmail'] = $_POST["Email"];
$result['no_visible_elements'] = 'TRUE';
helpers :: loadtemplate( 'settings', $result);
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2013-06-18 17:48:54 +00:00
}else{
// pass error and reload template accordingly
$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;
helpers :: loadtemplate( 'register', $result);
2014-09-03 05:23:39 +00:00
throw new SystemExit();
}
2013-06-18 17:48:54 +00:00
}
//use the valid userdata to create the new user.
function write_user($newUser){
2014-09-03 05:06:43 +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
$hashpass = crypt($newUser["pass"], WebUsers::generateSALT());
2014-09-03 05:06:43 +00:00
2013-06-26 01:26:25 +00:00
$params = array(
'Login' => $newUser["name"],
'Password' => $hashpass,
2014-09-03 05:06:43 +00:00
'Email' => $newUser["mail"]
2013-06-26 01:26:25 +00:00
);
try{
//make new webuser
$user_id = WebUsers::createWebuser($params['Login'], $params['Password'], $params['Email']);
2014-09-03 05:06:43 +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);
Users::createPermissions(array($newUser["name"]));
2014-09-03 05:06:43 +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 05:23:39 +00:00
throw new SystemExit();
2013-06-26 01:26:25 +00:00
}
2013-06-18 17:48:54 +00:00
}