示例#1
0
文件: auth.php 项目: JP-Git/moodle
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     $user->id = $DB->insert_record('user', $user);
     /// Save any custom profile field information
     profile_save_data($user);
     $user = $DB->get_record('user', array('id' => $user->id));
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth_email');
     }
     if ($notify) {
         global $CFG, $PAGE, $OUTPUT;
         $emailconfirm = get_string('emailconfirm');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($PAGE->course->fullname);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#2
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object (with system magic quotes)
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     $user = get_record('user', 'id', $user->id);
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         $navlinks = array();
         $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header($emailconfirm, $emailconfirm, $navigation);
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#3
0
function send_confirm_email_again($cust_email)
{
    global $connection;
    $max_mail_limit = 5;
    $confirmEmailQuery = 'SELECT * ';
    $confirmEmailQuery .= 'FROM customers ';
    $confirmEmailQuery .= 'WHERE `customers`.`email` = "' . $cust_email . '";';
    $confirmEmailResult = mysqli_query($connection, $confirmEmailQuery);
    checkQuery($confirmEmailResult);
    while ($result = mysqli_fetch_assoc($confirmEmailResult)) {
        $confirmation_email_sent = $result["confirmation_email_sent"];
        $name_first = $result["name_first"];
        $name_last = $result["name_last"];
        $hashed_con_number = $result["hashed_con_number"];
    }
    if ($confirmation_email_sent < $max_mail_limit) {
        // incrementing the confirmation email sent number
        $confirmation_email_sent++;
        $customerQuery = 'UPDATE customers SET ';
        $customerQuery .= 'confirmation_email_sent = ' . $confirmation_email_sent . ' ';
        $customerQuery .= 'WHERE `customers`.`email` = "' . $cust_email . '" ';
        $customerQuery .= 'LIMIT 1;';
        $customerResult = mysqli_query($connection, $customerQuery);
        checkQuery($customerResult);
        send_confirmation_email($name_first, $name_last, $cust_email, $hashed_con_number);
        return true;
    } else {
        return false;
    }
}
示例#4
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object (with system magic quotes)
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         print_header($emailconfirm, $emailconfirm, $emailconfirm);
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#5
0
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $password_clear = $user->password;
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = $DB->insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     $conditions = array('id' => $user->id);
     $user = $DB->get_record('user', $conditions);
     /* Create user in Joomla */
     $userinfo['username'] = $user->username;
     $userinfo['password'] = $password_clear;
     $userinfo['password2'] = $password_clear;
     $userinfo['name'] = $user->firstname . " " . $user->lastname;
     $userinfo['email'] = $user->email;
     $userinfo['block'] = 1;
     $this->call_method("createUser", $userinfo);
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         $navlinks = array();
         $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header($emailconfirm, $emailconfirm, $navigation);
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#6
0
    $error = null;
    $sent = null;
    $attemptedToSendEmail = false;
    if (!$email && ($password_request || $confirmation_request)) {
        $error = 'invalidemail';
    } else {
        if ($email) {
            $data = user_having_email($email);
            $username = $data['uname'];
            if (!$data['uname']) {
                $error = 'nouser';
            } elseif ($password_request && $data['active']) {
                $sent = send_account_email($email, $data);
                $attemptedToSendEmail = true;
            } else {
                // Confirmation request.
                if ($data['confirmed']) {
                    $error = 'alreadyconfirmed';
                } else {
                    $attemptedToSendEmail = true;
                    $sent = send_confirmation_email($email, $data);
                }
            }
        }
    }
    if ($attemptedToSendEmail && !$sent) {
        $error = 'emailfail';
    }
    $body_classes = 'account-issues';
    display_page('account_issues.tpl', 'Account Problems', get_certain_vars(get_defined_vars(), array('data')), array('quickstat' => false));
}
示例#7
0
文件: auth.php 项目: nottmoo/moodle
    /**
     * Sign up a new user ready for confirmation.
     * Password is passed in plaintext.
     *
     * @param object $user new user object
     * @param boolean $notify print notice with link and terminate
     */
    function user_signup($user, $notify=true) {
        global $CFG, $DB, $PAGE, $OUTPUT;

        require_once($CFG->dirroot.'/user/profile/lib.php');

        if ($this->user_exists($user->username)) {
            print_error('auth_ldap_user_exists', 'auth_ldap');
        }

        $plainslashedpassword = $user->password;
        unset($user->password);

        if (! $this->user_create($user, $plainslashedpassword)) {
            print_error('auth_ldap_create_error', 'auth_ldap');
        }

        $user->id = $DB->insert_record('user', $user);

        // Save any custom profile field information
        profile_save_data($user);

        $this->update_user_record($user->username);
        update_internal_user_password($user, $plainslashedpassword);

        $user = $DB->get_record('user', array('id'=>$user->id));
        events_trigger('user_created', $user);

        if (! send_confirmation_email($user)) {
            print_error('noemail', 'auth_ldap');
        }

        if ($notify) {
            $emailconfirm = get_string('emailconfirm');
            $PAGE->set_url('/auth/ldap/auth.php');
            $PAGE->navbar->add($emailconfirm);
            $PAGE->set_title($emailconfirm);
            $PAGE->set_heading($emailconfirm);
            echo $OUTPUT->header();
            notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
        } else {
            return true;
        }
    }
示例#8
0
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $password_clear = $user->password;
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = $DB->insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     $conditions = array('id' => $user->id);
     $user = $DB->get_record('user', $conditions);
     /* Create user in Joomla */
     $userinfo['username'] = $user->username;
     $userinfo['password'] = $password_clear;
     $userinfo['password2'] = $password_clear;
     $userinfo['name'] = $user->firstname . " " . $user->lastname;
     $userinfo['firstname'] = $user->firstname;
     $userinfo['lastname'] = $user->lastname;
     $userinfo['email'] = $user->email;
     $userinfo['block'] = 1;
     \core\event\user_created::create_from_userid($user->id)->trigger();
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         $emailconfirm = get_string('emailconfirm');
         $PAGE->set_url('/auth/joomdle/auth.php');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($emailconfirm);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
 /**
  * Test generate_confirmation_link with custom admin link
  */
 public function test_generate_confirmation_link_with_custom_admin()
 {
     global $CFG;
     $this->resetAfterTest();
     $sink = $this->redirectEmails();
     $admin = $CFG->admin;
     $CFG->admin = 'custom/admin/path';
     $user = $this->getDataGenerator()->create_user(["username" => "many_-.@characters@_@-..-..", "confirmed" => false, "email" => '*****@*****.**']);
     $confirmationurl = "/admin/test.php?with=params";
     $expected = $CFG->wwwroot . "/" . $CFG->admin . "/test.php?with=params&data=/many_-%2E%40characters%40_%40-%2E%2E-%2E%2E";
     send_confirmation_email($user, $confirmationurl);
     $sink->close();
     $messages = $sink->get_messages();
     $message = array_shift($messages);
     $messagebody = quoted_printable_decode($message->body);
     $sink->close();
     $this->assertContains($expected, $messagebody);
     $CFG->admin = $admin;
 }
function process_signup_form($target_page = 'index.php')
{
    global $label;
    $FirstName = $_POST['FirstName'];
    $LastName = $_POST['LastName'];
    $CompName = $_POST['CompName'];
    $Username = $_POST['Username'];
    $Password = md5($_POST['Password']);
    $Password2 = md5($_POST['Password2']);
    $Email = $_POST['Email'];
    $Newsletter = $_POST['Newsletter'];
    $Notification1 = $_POST['Notification1'];
    $Notification2 = $_POST['Notification2'];
    $Aboutme = $_POST['Aboutme'];
    $lang = $_POST['lang'];
    if ($_REQUEST['lang'] == '') {
        $lang = 'EN';
    }
    $error = validate_signup_form();
    if ($error != '') {
        echo "<span class='error_msg_label'>" . $label["advertiser_signup_error"] . "</span><P>";
        echo "<span ><b>" . $error . "</b></span>";
        $password = $_REQUEST['password'];
        $password2 = $_REQUEST['password2'];
        return false;
        // error processing signup/
    } else {
        //$target_page="index.php";
        $success = create_new_account($_SERVER['REMOTE_ADDR'], $FirstName, $LastName, $CompName, $Username, $_REQUEST['Password'], $Email, $Newsletter, $Notification1, $Notification2, $lang);
        if (EM_NEEDS_ACTIVATION == "AUTO") {
            $label["advertiser_signup_success_1"] = stripslashes(str_replace("%FirstName%", $FirstName, $label["advertiser_signup_success_1"]));
            $label["advertiser_signup_success_1"] = stripslashes(str_replace("%LastName%", $LastName, $label["advertiser_signup_success_1"]));
            $label["advertiser_signup_success_1"] = stripslashes(str_replace("%SITE_NAME%", SITE_NAME, $label["advertiser_signup_success_1"]));
            $label["advertiser_signup_success_1"] = stripslashes(str_replace("%SITE_CONTACT_EMAIL%", SITE_CONTACT_EMAIL, $label["advertiser_signup_success_1"]));
            echo $label["advertiser_signup_success_1"];
        } else {
            $label["advertiser_signup_success_2"] = stripslashes(str_replace("%FirstName%", $FirstName, $label["advertiser_signup_success_2"]));
            $label["advertiser_signup_success_2"] = stripslashes(str_replace("%LastName%", $LastName, $label["advertiser_signup_success_2"]));
            $label["advertiser_signup_success_2"] = stripslashes(str_replace("%SITE_NAME%", SITE_NAME, $label["advertiser_signup_success_2"]));
            $label["advertiser_signup_success_2"] = stripslashes(str_replace("%SITE_CONTACT_EMAIL%", SITE_CONTACT_EMAIL, $label["advertiser_signup_success_2"]));
            echo $label["advertiser_signup_success_2"];
            //echo "<center>".$label["advertiser_signup_goback"]."</center>";
            send_confirmation_email($Email);
        }
        echo "<center><form method='post' action='login.php?target_page=" . $target_page . "'><input type='hidden' name='Username' value='" . $_REQUEST['Username'] . "' > <input type='hidden' name='Password' value='" . $_REQUEST['Password'] . "'><input type='submit' value='" . $label["advertiser_signup_continue"] . "'></form></center>";
        return true;
    }
    // end everything ok..
}
示例#11
0
        // --------------------------------------------
    }
}
// ----------
session_start();
// Connect to a authenticated session
sessionAuthenticate(S_SHOWCART);
// Check the correct parameters have been passed
if (!isset($_GET["cust_id"]) || !isset($_GET["order_id"])) {
    $_SESSION["message"] = "Incorrect parameters to order-step4.php";
    header("Location: " . S_SHOWCART);
    exit;
}
// Check this customer matches the $cust_id
$connection = DB::connect($dsn, true);
if (DB::isError($connection)) {
    trigger_error($connection->getMessage(), E_USER_ERROR);
}
$cust_id = pearclean($_GET, "cust_id", 5, $connection);
$order_id = pearclean($_GET, "order_id", 5, $connection);
$real_cust_id = getCust_id($_SESSION["loginUsername"]);
if ($cust_id != $real_cust_id) {
    $_SESSION["message"] = "You can only view your own receipts!";
    header("Location: " . S_HOME);
    exit;
}
// Send the user a confirmation email
send_confirmation_email($cust_id, $order_id, $connection);
// Redirect to a receipt page (this can't be the receipt page,
// since the reload problem would cause extra emails).
header("Location: " . S_ORDERRECEIPT . "?cust_id={$cust_id}&order_id={$order_id}");
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  */
 public function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     $plainpassword = $user->password;
     $user->password = hash_internal_user_password($user->password);
     $user->mnethostid = $CFG->mnet_localhost_id;
     if (empty($user->secret)) {
         $user->secret = '';
     }
     if (empty($user->calendartype)) {
         $user->calendartype = $CFG->calendartype;
     }
     $firstname = strtolower($user->firstname);
     $lastname = strtolower($user->lastname);
     $initials = $firstname[0] . $lastname[0];
     try {
         $transaction = $DB->start_delegated_transaction();
         do {
             $username = sprintf($initials . "%04d", rand(1, 9999));
         } while ($DB->get_record('user', array("username" => $username), 'id', IGNORE_MISSING));
         $user->username = $username;
         $userdetailstext = "Username: {$username}<br />Password: {$plainpassword}";
         $user->id = user_create_user($user, false, false);
         user_add_password_history($user->id, $plainpassword);
         // Save any custom profile field information.
         $user->profile_field_typeofaccount = empty($user->profile_field_typeofaccount) ? 'student' : $user->profile_field_typeofaccount;
         $user->profile_field_yearlevel = empty($user->profile_field_yearlevel) ? 'N/A' : $user->profile_field_yearlevel;
         $user->profile_field_yearofbirth = empty($user->profile_field_yearofbirth) ? 'N/A' : $user->profile_field_yearofbirth;
         $user->profile_field_whereareyoufrom = empty($user->profile_field_whereareyoufrom) ? 'Perth' : $user->profile_field_whereareyoufrom;
         profile_save_data($user);
         $record = new stdClass();
         $record->studentuserid = $user->id;
         $record->teacheruserid = $user->id;
         switch ($user->profile_field_typeofaccount) {
             case 'wceteacher':
                 $this->add_teacher($user->id);
                 break;
             case 'adult':
             case 'student':
             default:
                 $this->add_student($user->id);
                 break;
         }
         // Trigger event.
         \core\event\user_created::create_from_userid($user->id)->trigger();
         // Assuming the both inserts work, we get to the following line.
         $transaction->allow_commit();
     } catch (Exception $e) {
         $transaction->rollback($e);
         return false;
     }
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail, auth_email');
     }
     if ($notify) {
         global $CFG, $PAGE, $OUTPUT;
         $emailconfirm = get_string('emailconfirm');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($PAGE->course->fullname);
         echo $OUTPUT->header();
         notice(get_string('signup:emailconfirmsent:text', 'auth_watercorped', $userdetailstext), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#13
0
            }
        } else {
            $subscribe_checkbox_ok = 0;
        }
        // Evaluate all oks
        if ($submission_valid == 1 && $name_first_ok == 1 && $name_last_ok == 1 && $birth_day_ok === true && $birth_month_ok === true && $birth_year_ok === true && $phone_ok == 1 && $email_ok == 1 && $password1_ok == 1 && $password2_ok == 1 && $captcha_ok === true && $agree_checkbox_ok == 1) {
            // Prep for database using mysqli_real_escape_string()
            $name_first = database_prep($name_first);
            $name_last = database_prep($name_last);
            $phone = database_prep($phone);
            $email = database_prep($email);
            $hashed_password = password_hash($password1, PASSWORD_BCRYPT);
            $hashed_con_number = password_hash(mt_rand(), PASSWORD_BCRYPT);
            $hashed_con_number = substr($hashed_con_number, 7);
            create_new_customer($name_first, $name_last, 0, 0, 0, $phone, $hashed_password, $email, $hashed_con_number, $subscribe_checkbox_ok);
            send_confirmation_email($name_first, $name_last, $email, $hashed_con_number);
            if (isset($_POST)) {
                unset($_POST);
            }
            include "_connections/connection_close.php";
            $location = 'confirm_email.php?action=new&email=' . $email;
            redirect($location);
        }
    } else {
        echo "Submission error!";
        exit;
    }
}
// end if $_POST submit is set
if (isset($_POST)) {
    unset($_POST);
示例#14
0
/**
 * @param string $edit
 * @param PDO $link
 * @return bool
 */
function change_email($edit, $link)
{
    $error = 0;
    if (isset($_POST[$edit])) {
        $_POST[$edit] = trim($_POST[$edit]);
    }
    $change = isset($_POST['edit']) ? $_POST['edit'] == $edit && ($error = parse_email($_POST[$edit])) === 0 ? true : false : false;
    if ($change) {
        if ($_POST[$edit] === $_SESSION['user_array']['email']) {
            change($edit, $link);
            return true;
        }
    }
    if ($change) {
        if ($_POST[$edit] === "") {
            change($edit, $link);
            $_SESSION['user_array']['confirmed_email'] = chr(0);
            return true;
        }
        if (captcha_verify_word()) {
            $sql = "SELECT user, email FROM confirmed_emails where email = :email";
            $stmt = $link->prepare($sql);
            $stmt->bindValue(':email', $_POST[$edit], PDO::PARAM_STR);
            if ($stmt->execute() !== false && ($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
                if ($row['user'] !== $_SESSION['user_array']['user']) {
                    $error = 3;
                }
            }
            if (!$error) {
                if (change($edit, $link)) {
                    send_confirmation_email($_POST[$edit], $link);
                    $_SESSION['user_array']['email'] = $_POST[$edit];
                    echo PR_EMAIL . ': ' . $_SESSION['user_array']['email'] . " ";
                    echo (ord($_SESSION['user_array']['hemail']) ? PR_HIDDEN : PR_VISIBLE) . " [<a href=\"profile.phtml?user="******"&edit=email\">" . PR_EDIT . "</a>] <span style=color:red>" . PR_SENT_1_A . "</span><script type='text/javascript'>alert(\"" . PR_SENT_1 . "\\n" . PR_SENT_2 . "\")</script><br />" . PHP_EOL;
                    return false;
                }
            }
        } else {
            $error = 4;
        }
    }
    echo "<form id=\"editForm\" method=\"POST\">" . PR_EMAIL . ": <input type=\"text\" id=\"" . $edit . "\" name=\"" . $edit . "\" value=\"" . $_SESSION['user_array'][$edit] . "\" onfocus=\"javascript:document.getElementById('focusId').value='" . $edit . "';\" />";
    echo "<input type=\"hidden\" id=\"focusId\" name=\"focusId\" value=\"" . $edit . "\">" . PHP_EOL;
    echo "<input type=\"hidden\" name=\"edit\" value=\"" . $edit . "\">" . PHP_EOL;
    echo "<input type=\"hidden\" name=\"user\" value=\"" . $_SESSION['user_array']['user'] . "\">" . PHP_EOL;
    echo "<input type=\"checkbox\" name=\"h" . $edit . "\" value=\"true\"";
    if (ord($_SESSION['user_array']['h' . $edit])) {
        echo " checked=\"checked\" ";
    }
    echo '/>' . PR_HIDE;
    switch ($error) {
        case 1:
            echo "<span style=\"color:red\"> " . PR_ERR_MAIL_LONG . "</span><script type='text/javascript'>focusId='" . $edit . "'</script>";
            break;
        case 2:
            echo "<span style=\"color:red\"> " . PR_ERR_MAIL_INVALID . "</span><script type='text/javascript'>focusId='" . $edit . "'</script>";
            break;
        case 3:
            echo "<span style=\"color:red\"> " . PR_ERR_MAIL_ALREADY_ASSOC . "</span><script type='text/javascript'>focusId='" . $edit . "';document.getElementById('" . $edit . "').value='" . $_POST[$edit] . "';</script>";
            break;
    }
    echo "<br /><span id=\"captchaImage\" style=\"border:0;width:140px;\"><img src=\"." . SYNAPP_CAPTCHA_PATH . "/captcha.image.php?nocache=" . hash("sha256", time() . mt_rand()) . "\" alt=\"captcha\"/></span><a \nhref=\"#\" onclick=\"updateCaptcha(null, '." . SYNAPP_CAPTCHA_PATH . "' );return false;\"><img src=\"." . SYNAPP_UI_RESOURCES_PATH . "/images/refresh.png\" style=\"border:0\" alt=\"" . PR_REFRESH . "\" title=\"" . PR_REFRESH . "\"/></a>";
    echo "<br />" . PR_CAPT . "<input type=\"text\" id=\"magicword\" " . "onfocus=\"javascript:document.getElementById('focusId').value='magicword';\" name=\"magicword\" autocomplete=\"off\" />";
    if ($error == 4) {
        echo "<span style=\"color:red\"> " . PR_ERR_CAPT . "</span><script type='text/javascript'>" . "focusId='magicword';document.getElementById('" . $edit . "').value='" . $_POST[$edit] . "';</script>";
    }
    echo '<br /></form>' . PHP_EOL;
    if (isset($_GET['alert']) && !count($_POST)) {
        if ($_GET['alert'] === "true") {
            echo "<script type='text/javascript'>alert(\"" . PR_VALIDATE_MAIL . "\")</script>";
        }
    }
    return false;
}
示例#15
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  * @return boolean success
  */
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB, $PAGE, $OUTPUT;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     if ($this->user_exists($user->username)) {
         print_error('auth_ldap_user_exists', 'auth_ldap');
     }
     $plainslashedpassword = $user->password;
     unset($user->password);
     if (!$this->user_create($user, $plainslashedpassword)) {
         print_error('auth_ldap_create_error', 'auth_ldap');
     }
     $user->id = user_create_user($user, false, false);
     user_add_password_history($user->id, $plainslashedpassword);
     // Save any custom profile field information
     profile_save_data($user);
     $this->update_user_record($user->username);
     // This will also update the stored hash to the latest algorithm
     // if the existing hash is using an out-of-date algorithm (or the
     // legacy md5 algorithm).
     update_internal_user_password($user, $plainslashedpassword);
     $user = $DB->get_record('user', array('id' => $user->id));
     \core\event\user_created::create_from_userid($user->id)->trigger();
     if (!send_confirmation_email($user)) {
         print_error('noemail', 'auth_ldap');
     }
     if ($notify) {
         $emailconfirm = get_string('emailconfirm');
         $PAGE->set_url('/auth/ldap/auth.php');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($emailconfirm);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#16
0
/**
 * @author John T. Macklin (viperf117a@yahoo.com)
 * @version $Id: lib_ldapsso.php,v 1.0 2009/11/11 19:23:07 viperf117a Exp $
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package moodleauth  -   Custom LDAP URL SSO PHP Functions
*/
function confirm_user($user)
{
    // Complete the login process
    global $CFG, $SESSION;
    if ($user) {
        // language setup
        update_login_count();
        if ($user->username == 'guest') {
            // no predefined language for guests - use existing session or default site lang
            unset($user->lang);
        } else {
            if (!empty($user->lang)) {
                // unset previous session language - use user preference instead
                unset($SESSION->lang);
            }
        }
        if (empty($user->confirmed)) {
            // This account was never confirmed
            $CFG->registerauth = 'ldapsso';
            // User ldapsso to verify registration
            $user->secret = md5(rand(1, 9876543));
            // Set secret for confirmation
            send_confirmation_email($user);
            // Genetrate Confirmation Email!
            print_heading(get_string("mustconfirm"));
            print_box_start('generalbox centerpara boxwidthnormal boxaligncenter');
            echo "<h2>" . get_string('confirmednot') . "</h2>\n";
            echo "<p>" . get_string('auth_ldap_sso_confirmednot', 'auth_ldapsso') . "</p>\n";
            print_single_button("{$CFG->wwwroot}/login/", null, get_string('continue'));
            print_box_end();
            print_footer();
            exit;
        }
        $USER = complete_user_login($user);
        /// Let's set them up.
        add_to_log(SITEID, 'user', 'login', "view.php?id={$USER->id}&course=" . SITEID, $user->id, 0, $user->id);
        /// Prepare redirection
        if (user_not_fully_set_up($USER)) {
            $urltogo = $CFG->wwwroot . '/user/edit.php';
            // We don't delete $SESSION->wantsurl yet, so we get there later
        } else {
            if (isset($SESSION->wantsurl) and strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) {
                $urltogo = $SESSION->wantsurl;
                /// Because it's an address in this site
                unset($SESSION->wantsurl);
            } else {
                // no wantsurl stored or external - go to homepage
                $urltogo = $CFG->wwwroot . '/';
                unset($SESSION->wantsurl);
            }
        }
        /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
        if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->mymoodleredirect) and !isguest()) {
            if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot . '/' or $urltogo == $CFG->wwwroot . '/index.php') {
                $urltogo = $CFG->wwwroot . '/my/';
            }
        }
        /// check if user password has expired
        /// Currently supported only for ldap-authentication module
        $userauth = get_auth_plugin($USER->auth);
        if (!empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
            if ($userauth->can_change_password()) {
                $passwordchangeurl = $userauth->change_password_url();
            } else {
                $passwordchangeurl = $CFG->httpswwwroot . '/login/change_password.php';
            }
            $days2expire = $userauth->password_expire($USER->username);
            if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
                print_header("{$site->fullname}: {$loginsite}", "{$site->fullname}", $navigation, '', '', true, "<div class=\"langmenu\">{$langmenu}</div>");
                notice_yesno(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
                print_footer();
                exit;
            } elseif (intval($days2expire) < 0) {
                print_header("{$site->fullname}: {$loginsite}", "{$site->fullname}", $navigation, '', '', true, "<div class=\"langmenu\">{$langmenu}</div>");
                notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
                print_footer();
                exit;
            }
        }
        // Do necessary user updates for 'onlogin' Data Mappings
        // narrow down what fields we need to update
        $all_keys = array_keys(get_object_vars($userauth->config));
        $updatekeys = array();
        // $updatekeys = array('firstname','lastname','idnumber','city','country','description');
        foreach ($all_keys as $key) {
            if (preg_match('/^field_updatelocal_(.+)$/', $key, $match)) {
                // if we have a field to update and it is set as 'onlogin'
                if (!empty($userauth->config->{'field_map_' . $match[1]}) and $userauth->config->{$match[0]} === 'onlogin') {
                    array_push($updatekeys, $match[1]);
                    // the actual key name
                }
            }
        }
        // print_r($all_keys); print_r($updatekeys);
        unset($all_keys);
        unset($key);
        if (!empty($updatekeys)) {
            $userauth->update_user_record(addslashes($user->username), $updatekeys);
        }
        reset_login_count();
        // Return to original debugging level
        $CFG->debug = $origdebug;
        error_reporting($CFG->debug);
        redirect($urltogo, 'Redirecting login request!', 0);
    }
}
示例#17
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  */
 public function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     $plainpassword = $user->password;
     $user->password = hash_internal_user_password($user->password);
     if (empty($user->calendartype)) {
         $user->calendartype = $CFG->calendartype;
     }
     $user->id = user_create_user($user, false, false);
     user_add_password_history($user->id, $plainpassword);
     // Save any custom profile field information.
     profile_save_data($user);
     // Trigger event.
     \core\event\user_created::create_from_userid($user->id)->trigger();
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail, auth_email');
     }
     if ($notify) {
         global $CFG, $PAGE, $OUTPUT;
         $emailconfirm = get_string('emailconfirm');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($PAGE->course->fullname);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#18
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object (with system magic quotes)
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     //Added by JAM: 12.02.2010 - Call the set user time-zone for WS, cannot set time-zone until, user is created
     setWSUserDefaultTimeZone($user->username, $user);
     $user = get_record('user', 'id', $user->id);
     events_trigger('user_created', $user);
     //Added by JAM: 01.06.2011 - this is where the user id exists
     if (!addQSUser($user)) {
         admin_signuperror_email($user);
         // Added: JAM - 01.06.2011
         //error('An error has occured, please try again shortly.');
     }
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         $navlinks = array();
         $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header($emailconfirm, $emailconfirm, $navigation);
         // Added by SMS: 7/28/2011
         $data = new object();
         $data->useremail = $user->email;
         $supportuser = generate_email_supportuser();
         $data->adminemail = $supportuser->email;
         // Edited by SMS: 7/28/2011
         // notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
         notice(get_string('emailconfirmsent', '', $data), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }