Example #1
0
 /**
  * Create a new user.
  *
  * @param string $email
  *   The user's email address.
  * @param string $pass
  *   The new password.
  *
  * @return Array
  *   When creation is successful:
  *      [Status of creation, user id]      
  *   When not:
  *      [Status of creation, Error short code]
  */
 public static function create($email, $pass)
 {
     if (Database::getInstance()->check('user', array('email' => strtolower($email), 'password' => array('!=', '')))) {
         // An account already exists with that email.
         return ['success' => false, 'error' => 'A user with that email already exists.'];
     } elseif ($user_info = Database::getInstance()->selectRow('user', array('email' => strtolower($email), 'password' => ''))) {
         // EMAIL EXISTS IN MAILING LIST ONLY
         $updates = array();
         // Set the referrer.
         if ($ref = Request::cookie('ref', 'int')) {
             $updates['referrer'] = $ref;
         }
         $user = new self($user_info);
         $user->setPass($pass, '', $user_info['user_id']);
         $updates['registered'] = Time::today();
         Database::getInstance()->update('user', $updates, array('user_id' => $user_info['user_id']));
         $user->sendConfirmationEmail();
         return ['success' => true, 'data' => $user_info['user_id']];
     } else {
         // EMAIL IS NOT IN MAILING LIST AT ALL
         $user_id = static::insertUser($email, $pass);
         $updates = array();
         if ($ref = Request::cookie('ref', 'int')) {
             $updates['referrer'] = $ref;
         }
         $updates['type'] = 1;
         Database::getInstance()->update('user', $updates, array('user_id' => $user_id));
         $user = static::loadById($user_id);
         $user->sendConfirmationEmail();
         return ['success' => true, 'data' => $user_id];
     }
 }