function reset_password() { $username = get_post_var("username"); $password = get_post_var("password"); $a_retval = user_funcs::reset_password($username, "", $password, TRUE); if ($a_retval[0]) { return json_encode(array(new command("print success", $a_retval[1]))); } return json_encode(array(new command("print failure", $a_retval[1]))); }
function initializeUserData() { global $maindb; global $o_project_installer; // check if users already exist if ($o_project_installer->check_create_users(FALSE)) { echo "users already exist"; return; } // form for requesting data $s_username = get_post_var("username", ""); $s_pass1 = get_post_var("password", ""); $s_pass2 = get_post_var("password2", ""); $s_email = get_post_var("email", ""); $s_request_form = "<form action='' method='POST'>\n\t\tPrimary account username: <input type='text' name='username' placeholder='username' value='{$s_username}' /><br />\n\t\tPrimary account password: <input type='password' name='password' /> verify: <input type='password' name='password2' /><br />\n\t\tPrimary account email: <input type='text' name='email' placeholder='email' value='{$s_email}' />\n\t\t<input type='submit' />\n\t</form>"; // do we have user name and password data? if (!isset($_POST["username"]) || !isset($_POST["password"]) || !isset($_POST["password2"]) || !isset($_POST["email"])) { echo $s_request_form; return; } // verify that the data is valid if ($s_pass1 == "" || $s_pass1 != $s_pass2) { echo "<div style='color:red;'>Passwords do not match</div><br /><br />"; echo $s_request_form; return; } if ($s_username == "" || !ctype_alnum($s_username)) { echo "<div style='color:red;'>Primary username must include only alphanumeric characters</div><br /><br />"; echo $s_request_form; return; } if ($s_email == "") { echo "<div style='color:red;'>Must include an email address</div><br /><br />"; echo $s_request_form; return; } // get all level-1 accesses $a_accesses = db_query("SELECT GROUP_CONCAT(`name` SEPARATOR '|') AS 'accesses' FROM `[maindb]`.`accesses` WHERE `level`='1'", array("maindb" => $maindb)); $s_accesses = $a_accesses[0]["accesses"]; // create the users $s_feedback = ""; if (!user_funcs::create_user($s_username, $s_pass1, $s_email, array("access" => $s_accesses), $s_feedback)) { echo "<div style='color:red;'>{$s_feedback}</div><br /><br />"; echo $s_request_form; return; } db_query("INSERT INTO `[maindb]`.`students` (`username`,`pass`,`accesses`,`email`) VALUES ('guest',AES_ENCRYPT('guest','guest'),'','')", array("maindb" => $maindb)); $a_guest_id = db_query("SELECT `id` FROM `[maindb]`.`students` WHERE `username`='guest'", array("maindb" => $maindb)); $s_guest_id = $a_guest_id[0]["id"]; db_query("INSERT INTO `[maindb]`.`generated_settings` (`user_id`,`private_icalendar_key`) VALUES ('[guestid]','guest')", array("maindb" => $maindb, "guestid" => $s_guest_id)); echo "created users {$s_username} and guest."; }