Location: PHPKode > projects > Scriptorium > scriptorium1.6/user_management/create_account.php
<?php


include ('../includes/scriptorium_inc.php');

if (ALLOW_REGISTRATION == false) {
  header('Location: ' . WEB_PATH . 'create_account.php');
  exit();
}

if ($_POST['submit'] != '') {
  // validate input
  if ($_POST['name'] == '' ||
      $_POST['username'] == '' ||
      $_POST['email'] == '' ||
      $_POST['password'] == '' ||
      $_POST['password'] != $_POST['password2']) {
    header('Location: ../create_account.php');
    exit();
  }

  $quoted_name = $db->quoteSmart($_POST['name']);
  $quoted_username = $db->quoteSmart($_POST['username']);
  $quoted_email = $db->quoteSmart(strtolower($_POST['email']));
  $quoted_password = $db->quoteSmart($_POST['password']);
//  $quoted_locale = ($_POST['locale'] == '')? $LOCALES[0] : $_POST['locale'];
  $quoted_locale = $_SESSION['locale'];
  $quoted_locale = $db->quoteSmart($quoted_locale);

  //does this email address already exist in the database?
  $sql = "SELECT email, password FROM scriptorium_users WHERE email=$quoted_email";

  $row = $db->getRow($sql);

  if (is_array($row) && $row[0] != '') {
    // email address is already in database
    print lib("email_already_exists");
    exit();
  } else {
    // insert new account
    $sql = <<<SQL

      INSERT INTO scriptorium_users
      SET email=$quoted_email,
      password=PASSWORD($quoted_password),
      locale=$quoted_locale,
      name=$quoted_name,
      username=$quoted_username,
      account_state={$ACCOUNT_STATES['unconfirmed']}
SQL;
      
    $result = $db->query($sql);
    
    if ($db->isError($result)) {
      $_SESSION['message'] = lib('unable_add_user') . ' ' . lib('please_try_again');
      header('Location: ../create_account.php');
      exit();
    }
     
    // send the confirmation email

    $email_welcome = lib('account_welcome', NAME);
    $email_recipient = "{$_POST['name']} <{$_POST['email']}>";
    $email_token = generateAccountToken($_POST['email'],$_POST['password']);
    $confirm_link = WEB_PATH . "/confirm_account.php?$email_token";
    
    $application_name = NAME;
    
    $email_body = <<<TEXT
            
$email_welcome 

{$libs['account_confirm_link']}

$confirm_link

{$libs['account_disregard']}

TEXT;

    mail($email_recipient,$email_welcome,$email_body);

    header('Location: ../confirmation_sent.php');
    exit();  

  }
  
 }


Return current item: Scriptorium