khanat-opennel-code/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php

97 lines
3.2 KiB
PHP
Raw Normal View History

2013-06-06 06:04:46 +00:00
<?php
function add_user(){
$result = Users :: check_Register();
//print_r($result);
// 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']
);
//header( 'Location: email_sent.php' );
write_user( $edit );
exit;
2013-06-18 17:48:54 +00:00
}else{
// pass error
$result['prevUsername'] = $_POST["Username"];
$result['prevPassword'] = $_POST["Password"];
$result['prevConfirmPass'] = $_POST["ConfirmPass"];
$result['prevEmail'] = $_POST["Email"];
$result['no_visible_elements'] = 'TRUE';
helpers :: loadtemplate( 'register', $result);
exit;
}
2013-06-18 17:48:54 +00:00
}
2013-06-06 06:04:46 +00:00
function write_user($newUser){
2013-06-26 01:26:25 +00:00
//get the db specifics out of the config file
global $WEBDBHOST;
global $WEBDBPORT;
global $WEBDBNAME;
global $WEBDBUSERNAME;
global $WEBDBPASSWORD;
2013-06-26 01:26:25 +00:00
global $LIBDBHOST;
global $LIBDBPORT;
global $LIBDBNAME;
global $LIBDBUSERNAME;
global $LIBDBPASSWORD;
global $SHARDDBHOST;
global $SHARDDBPORT;
global $SHARDDBNAME;
global $SHARDDBUSERNAME;
global $SHARDDBPASSWORD;
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"], Users::generateSALT());
2013-06-26 01:26:25 +00:00
$params = array(
'name' => $newUser["name"],
'pass' => $hashpass,
'mail' => $newUser["mail"]
);
//print_r($params);
//make a $values array for passing all data to the Users::createUser() function.
$values["params"] = $params;
$values["libhost"] = $LIBDBHOST;
$values["libport"] = $LIBDBPORT;
$values["libdbname"] = $LIBDBNAME;
$values["libusername"] = $LIBDBUSERNAME;
$values["libpassword"] = $LIBDBPASSWORD ;
$values["shardhost"] = $SHARDDBHOST;
$values["shardport"] = $SHARDDBPORT;
$values["sharddbname"] = $SHARDDBNAME;
$values["shardusername"] = $SHARDDBUSERNAME;
$values["shardpassword"] = $SHARDDBPASSWORD;
2013-06-26 01:26:25 +00:00
//Create the user on the shard + in case shard is offline put copy of query in query db
$result = Users :: createUser($values);
2013-06-26 01:26:25 +00:00
try{
//make connection with web db and put it in there
$dbw = new PDO("mysql:host=$WEBDBHOST;port=$WEBDBPORT;dbname=$WEBDBNAME", $WEBDBUSERNAME, $WEBDBPASSWORD);
$dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $dbw->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)");
$statement->execute($params);
}catch (PDOException $e) {
//go to error page or something, because can't access website db
print_r($e);
exit;
}
print('Awesome');
}
2013-06-18 17:48:54 +00:00