Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / ams / func / add_user.php
blobf2425ae717dcf04d466552c7ed6cfa7605902d7a
1 <?php
2 /**
3 * This function is beign used to add a new user to the www database.
4 * 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
5 * 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
6 * 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,
7 * waiting for the sync cron job to update it.
8 * @author Daan Janssens, mentored by Matthew Lagoe
9 */
10 function add_user(){
11 global $INGAME_WEBPATH;
12 $params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'ConfirmPass' => $_POST["ConfirmPass"], 'Email' => $_POST["Email"]);
13 $webUser = new WebUsers();
15 //check if the POST variables are valid, before actual registering
16 $result = $webUser->check_Register($params);
18 global $SITEBASE;
19 require_once($SITEBASE . '/inc/settings.php');
20 // if all are good then create user
21 if ( $result == "success"){
22 $edit = array(
23 'name' => $_POST["Username"],
24 'pass' => $_POST["Password"],
25 'mail' => $_POST["Email"],
26 'init' => $_POST["Email"],
27 'unhashpass' => $_POST["Password"],
28 'status' => 1,
29 'access' => $_SERVER['REQUEST_TIME']
31 $status = write_user( $edit );
32 if(Helpers::check_if_game_client()){
33 //if registering ingame then we have to set the header and dont need to reload the template.
34 header('Location: email_sent.php');
35 throw new SystemExit();
37 $pageElements = settings();
38 $pageElements['ingame_webpath'] = $INGAME_WEBPATH;
39 $pageElements['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
40 $pageElements['SUCCESS_ADD'] = $status;
41 if (isset($_GET['page']) && $_GET['page']=="settings"){
42 helpers :: loadtemplate( 'settings', $pageElements);
43 }else{
44 $pageElements['no_visible_elements'] = 'TRUE';
45 helpers :: loadtemplate( 'register_feedback', $pageElements);
47 throw new SystemExit();
48 }elseif (isset($_GET['page']) && $_GET['page']=="settings"){
49 $pageElements = array_merge(settings(), $result);
50 // pass error and reload template accordingly
51 $pageElements['prevUsername'] = $_POST["Username"];
52 $pageElements['prevPassword'] = $_POST["Password"];
53 $pageElements['prevConfirmPass'] = $_POST["ConfirmPass"];
54 $pageElements['prevEmail'] = $_POST["Email"];
55 $pageElements['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
56 $pageElements['do'] = "add_user";
57 helpers :: loadtemplate( 'settings', $pageElements);
58 throw new SystemExit();
59 }else{
60 // pass error and reload template accordingly
61 $result['prevUsername'] = $_POST["Username"];
62 $result['prevPassword'] = $_POST["Password"];
63 $result['prevConfirmPass'] = $_POST["ConfirmPass"];
64 $result['prevEmail'] = $_POST["Email"];
65 $result['no_visible_elements'] = 'TRUE';
66 $pageElements['ingame_webpath'] = $INGAME_WEBPATH;
67 helpers :: loadtemplate( 'register', $result);
68 throw new SystemExit();
72 //use the valid userdata to create the new user.
73 function write_user($newUser){
75 //create salt here, because we want it to be the same on the web/server
76 $hashpass = crypt($newUser["pass"], WebUsers::generateSALT());
78 $params = array(
79 'Login' => $newUser["name"],
80 'Password' => $hashpass,
81 'Email' => $newUser["mail"]
83 try{
84 //make new webuser
85 $user_id = WebUsers::createWebuser($params['Login'], $params['Password'], $params['Email']);
87 //Create the user on the shard + in case shard is offline put copy of query in query db
88 //returns: ok, shardoffline or liboffline
89 $result = WebUsers::createUser($params, $user_id);
90 Users::createPermissions(array($newUser["name"]));
93 }catch (PDOException $e) {
94 //go to error page or something, because can't access website db
95 print_r($e);
96 throw new SystemExit();
99 return $result;