Ejemplo n.º 1
0
$notice = UserNotices::get_instance();
$mysqli = DBUtils::get_mysqli_link($configObject->get('cfg_db_host'), $configObject->get('cfg_db_username'), $configObject->get('cfg_db_passwd'), $configObject->get('cfg_db_database'), $configObject->get('cfg_db_charset'), $notice, $configObject->get('dbclass'));
$email = isset($_GET['email']) ? $_GET['email'] : '';
$message = '';
$errors = array();
$form_util = new FormUtils();
if (isset($_POST['submit']) and $_POST['submit'] == $string['send']) {
    $email = $_POST['email'];
    // Process the form submission
    $errors = $form_util->check_required(array('email' => $string['emailaddress']));
    if (count($errors) == 0) {
        // Check if the supplied value is an email address (avoid an unnecessary DB call)
        if (!$form_util->is_email($email)) {
            $errors[] = $string['emailaddressinvalid'];
        } else {
            if ($form_util->is_email_in_cfg_institutional_domains($email)) {
                $errors[] = $string['emailaddressininstitutionaldomains'];
            } else {
                // If it is, look for the user in the database
                $stmt = $mysqli->prepare("SELECT id, title, surname FROM users WHERE email = ? ORDER BY id DESC LIMIT 1");
                $stmt->bind_param('s', $email);
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($user_id, $title, $surname);
                $stmt->fetch();
                if ($stmt->num_rows == 0) {
                    $errors[] = $string['emailaddressnotfound'];
                } else {
                    // If they do exist, create a token and send it to them in an email
                    $token = substr(md5(rand(10000000, 99999999)), 0, 15);
                    // Check if there is already a token for the user and update reather than continually adding new ones