mirror of https://github.com/BOINC/boinc.git
135 lines
3.4 KiB
PHP
135 lines
3.4 KiB
PHP
<?php
|
|
|
|
include_once("../inc/db.inc");
|
|
include_once("../inc/util.inc");
|
|
include_once("../inc/email.inc");
|
|
include_once("../inc/user.inc");
|
|
|
|
function show_error($str) {
|
|
page_head("Can't create account");
|
|
echo "$str<br>\n";
|
|
echo mysql_error();
|
|
echo "<p>Click your browser's <b>Back</b> button to try again.\n<p>\n";
|
|
page_tail();
|
|
exit();
|
|
}
|
|
|
|
$config = get_config();
|
|
if (parse_bool($config, "disable_account_creation")) {
|
|
page_head("Account creation is disabled");
|
|
echo "
|
|
<h3>Account creation is disabled</h3>
|
|
Sorry, this project has disabled the creation of new accounts.
|
|
Please try again later.
|
|
";
|
|
exit();
|
|
}
|
|
|
|
db_init();
|
|
init_session();
|
|
|
|
$teamid = post_int("teamid", true);
|
|
if ($teamid) {
|
|
$team = lookup_team($teamid);
|
|
$clone_user = lookup_user_id($team->userid);
|
|
if (!$clone_user) {
|
|
echo "User $userid not found";
|
|
exit();
|
|
}
|
|
$project_prefs = $clone_user->project_prefs;
|
|
} else {
|
|
$teamid = 0;
|
|
$project_prefs = "";
|
|
}
|
|
|
|
if(defined('INVITE_CODES')) {
|
|
$invite_code = process_user_text($_POST["invite_code"]);
|
|
if (strlen($invite_code)==0) {
|
|
show_error( tr(AC_INVITE_REQUIRED) );
|
|
}
|
|
if (!preg_match(INVITE_CODES, $invite_code)) {
|
|
show_error( tr(AC_INVITE_INVALID) );
|
|
}
|
|
}
|
|
|
|
$new_name = process_user_text($_POST["new_name"]);
|
|
if (strlen($new_name)==0) {
|
|
show_error("You must supply a name for your account");
|
|
}
|
|
if ($new_name != strip_tags($new_name)) {
|
|
show_error("HTML tags not allowed in name");
|
|
}
|
|
|
|
$new_email_addr = process_user_text($_POST["new_email_addr"]);
|
|
$new_email_addr = strtolower($new_email_addr);
|
|
if (!is_valid_email_addr($new_email_addr)) {
|
|
show_error("Invalid email address:
|
|
you must enter a valid address of the form
|
|
name@domain"
|
|
);
|
|
}
|
|
$user = lookup_user_email_addr($new_email_addr);
|
|
if ($user) {
|
|
show_error("There's already an account with that email address.");
|
|
}
|
|
|
|
$passwd = stripslashes(post_str("passwd"));
|
|
$passwd2 = stripslashes(post_str("passwd2"));
|
|
if ($passwd != $passwd2) {
|
|
show_error("New passwords are different");
|
|
}
|
|
|
|
$min_passwd_length = parse_config($config, "<min_passwd_length>");
|
|
if (!$min_passwd_length) $min_passwd_length = 6;
|
|
|
|
if (!is_ascii($passwd)) {
|
|
show_error("Passwords may only include ASCII characters.");
|
|
}
|
|
|
|
if (strlen($passwd)<$min_passwd_length) {
|
|
show_error(
|
|
"New password is too short:
|
|
minimum password length is $min_passwd_length characters."
|
|
);
|
|
}
|
|
|
|
$passwd_hash = md5($passwd.$new_email_addr);
|
|
|
|
$country = post_str("country");
|
|
if ($country == "") {
|
|
$country = "International";
|
|
}
|
|
if (!is_valid_country($country)) {
|
|
echo "bad country";
|
|
exit();
|
|
}
|
|
|
|
$postal_code = $_POST["postal_code"];
|
|
|
|
$user = make_user(
|
|
$new_email_addr, $new_name, $passwd_hash,
|
|
$country, $postal_code, $project_prefs, $teamid
|
|
);
|
|
if (!$user) {
|
|
show_error("Couldn't create account");
|
|
}
|
|
|
|
// In success case, redirect to a fixed page so that user can
|
|
// return to it without getting "Repost form data" stuff
|
|
|
|
send_auth_email($user, true, false);
|
|
|
|
if(defined('INVITE_CODES')) {
|
|
error_log("Account '$new_email_addr' created using invitation code '$invite_code'");
|
|
}
|
|
|
|
session_start();
|
|
$_SESSION["authenticator"] = $user->authenticator;
|
|
Header("Location: home.php");
|
|
setcookie('auth', $user->authenticator, time()+3600*24*365);
|
|
setcookie('init', "1", time()+3600*24*365);
|
|
setcookie('via_web', "1", time()+3600*24*365);
|
|
|
|
|
|
?>
|