<?php
-
/**
* StatusNet, the distributed open-source microblogging tool
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category API
- * @package GNUSocial
+ * @package GNUsocial
* @author Hannes Mannerheim <h@nnesmannerhe.im>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://www.gnu.org/software/social/
*
* @return boolean success flag
*/
- protected function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
}
if (!empty($this->code)) {
- $this->invite = Invitation::staticGet('code', $this->code);
+ $this->invite = Invitation::getKV('code', $this->code);
if (empty($this->invite)) {
// TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation.
$this->clientError(_('Sorry, invalid invitation code.'), 401);
// Input scrubbing
try {
- $nickname = Nickname::normalize($nickname);
+ $nickname = Nickname::normalize($nickname, true);
} catch (NicknameException $e) {
// clientError handles Api exceptions with various formats and stuff
- $this->clientError(_('Not a valid nickname.'), 400);
+ $this->clientError($e->getMessage(), $e->getCode());
}
+
$email = common_canonical_email($email);
if ($email && !Validate::email($email, common_config('email', 'check_domain'))) {
// TRANS: Form validation error displayed when trying to register without a valid e-mail address.
$this->clientError(_('Not a valid email address.'), 400);
- } else if ($this->nicknameExists($nickname)) {
- // TRANS: Form validation error displayed when trying to register with an existing nickname.
- $this->clientError(_('Nickname already in use. Try another one.'), 400);
- } else if (!User::allowed_nickname($nickname)) {
- // TRANS: Form validation error displayed when trying to register with an invalid nickname.
- $this->clientError(_('Not a valid nickname.'), 400);
} else if ($this->emailExists($email)) {
// TRANS: Form validation error displayed when trying to register with an already registered e-mail address.
$this->clientError(_('Email address already exists.'), 400);
// TRANS: Form validation error displayed when trying to register with non-matching passwords.
$this->clientError(_('Passwords do not match.'), 400);
} else {
-
- // annoy spammers
- sleep(7);
-
- if ($user = User::register(array('nickname' => $nickname,
- 'password' => $password,
- 'email' => $email,
- 'fullname' => $fullname,
- 'homepage' => $homepage,
- 'bio' => $bio,
- 'location' => $location,
- 'code' => $code))) {
- if (!$user) {
- // TRANS: Form validation error displayed when trying to register with an invalid username or password.
- $this->clientError(_('Invalid username or password.'), 400);
- }
-
- Event::handle('EndRegistrationTry', array($this));
-
- $this->initDocument('json');
- $this->showJsonObjects($this->twitterUserArray($user->getProfile()));
- $this->endDocument('json');
-
- } else {
- // TRANS: Form validation error displayed when trying to register with an invalid username or password.
- $this->clientError(_('Invalid username or password.'), 400);
- }
- }
- }
-
- /**
- * Does the given nickname already exist?
- *
- * Checks a canonical nickname against the database.
- *
- * @param string $nickname nickname to check
- *
- * @return boolean true if the nickname already exists
- */
- function nicknameExists($nickname)
- {
- $user = User::staticGet('nickname', $nickname);
- return is_object($user);
+ // annoy spammers
+ sleep(7);
+
+ try {
+ $user = User::register(array('nickname' => $nickname,
+ 'password' => $password,
+ 'email' => $email,
+ 'fullname' => $fullname,
+ 'homepage' => $homepage,
+ 'bio' => $bio,
+ 'location' => $location,
+ 'code' => $this->code));
+ Event::handle('EndRegistrationTry', array($this));
+
+ $this->initDocument('json');
+ $this->showJsonObjects($this->twitterUserArray($user->getProfile()));
+ $this->endDocument('json');
+
+ } catch (Exception $e) {
+ $this->clientError($e->getMessage(), 400);
+ }
+ }
}
/**
if (!$email || strlen($email) == 0) {
return false;
}
- $user = User::staticGet('email', $email);
+ $user = User::getKV('email', $email);
return is_object($user);
}