Пример #1
0
function register_user()
{
    $username = $_POST["username"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $captcha = trim($_POST["captcha"]);
    //if not valid captcha()
    include_once "/var/www/includes/captch_code.php";
    if (check_code($captcha)) {
        //sanitize input fields;
        $cr = new crypto();
        $password_hash = $cr->one_way_crypt($password);
        //add new user to database
        $u = new user();
        try {
            if ($u->create_user($username, $password_hash, $email)) {
                $uid = $u->get_user_id($email);
                $token = base64_encode($cr->encrypt($uid));
                //send activation email
                $link = "http://punbt090pc/activate.php?u=" . urlencode($token);
                include_once "/var/www/includes/email.php";
                send_activation_email($email, $link);
                set_registration_error("An activation email has been sent to your inbox (Please check your junkbox in case you have not received it).");
            } else {
                //send back to registration page
                header("Location: /register.php");
            }
        } catch (Exception $e) {
            set_registration_error("UserName Or Email is already registered");
        }
    } else {
        set_registration_error("Invalid Captcha");
    }
}
Пример #2
0
function content()
{
    $errors = array();
    if (array_key_exists('register', $_POST)) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $password2 = $_POST['password2'];
        if (!$name || !$email || !$password || !$password2) {
            $errors[] = "Please fill in all the fields";
        }
        if ($password && $password2 && $password != $password2) {
            $errors[] = "Passwords do not match";
            $_POST['password'] = '';
            $_POST['password2'] = '';
        }
        if ($email && !validate_email_address($email)) {
            error_log("Invalid email address <{$email}> while registering");
            $errors[] = "Invalid email address";
        }
        if (count($errors) == 0 && count(fetch_all('users', 'email_address', $email))) {
            $errors[] = "A user with this email address already exists";
        }
        if (count($errors) == 0) {
            $token = make_random_token();
            $data = array('name' => $name, 'email_address' => $email, 'password_crypt' => crypt($password), 'date_registered' => date('Y-m-d H:i:s'), 'activation_token' => $token);
            insert_array_contents('users', $data);
            send_activation_email($email, $name, $token);
            ?>

      <h2>Account registered</h2>

      <p>An email has just been sent to the email address you supplied.  This
        contains a link which you should follow to activate your account.</p>
      
      <?php 
            return;
        }
    }
    page_header('Register for an account');
    show_error_list($errors);
    ?>

    <form method="post" action="" accept-charset="UTF-8">
      <div class="fieldrow">
        <?php 
    text_field($_POST, 'name', 'Name', 'publicly visible');
    ?>
      </div>

      <div class="fieldrow">
        <?php 
    text_field($_POST, 'email', 'Email address');
    ?>
      </div>

      <div class="fieldrow">
        <div>
          <label for="password">Password</label>
          <input type="password" id="password" name="password" 
            value="<?php 
    esc($_POST['password']);
    ?>
" />
        </div>
        <div>
          <label for="password2">Confirm password</label>
          <input type="password" id="password2" name="password2" 
            value="<?php 
    esc($_POST['password2']);
    ?>
" />
        </div>
      </div>

      <div class="fieldrow">
        <input type="submit" name="register" value="Register" />
      </div>
    </form>
  <?php 
}