X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapiaccountregister.php;h=0d018007cdd5f1aec35d38bc58f241b3483ce759;hb=5d91c9a820ba6097b7763a4b7c20fba51b470943;hp=15a62d39716e936f2aa84c60d772181d5be4b01e;hpb=1d8b19fe545e62370dc7c1810478021473d5357f;p=quix0rs-gnu-social.git diff --git a/actions/apiaccountregister.php b/actions/apiaccountregister.php index 15a62d3971..0d018007cd 100644 --- a/actions/apiaccountregister.php +++ b/actions/apiaccountregister.php @@ -1,5 +1,4 @@ . * * @category API - * @package GNUSocial + * @package GNUsocial * @author Hannes Mannerheim * @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/ @@ -54,7 +53,7 @@ class ApiAccountRegisterAction extends ApiAction * * @return boolean success flag */ - protected function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -102,7 +101,7 @@ class ApiAccountRegisterAction extends ApiAction } 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); @@ -114,22 +113,17 @@ class ApiAccountRegisterAction extends ApiAction // 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); @@ -157,50 +151,29 @@ class ApiAccountRegisterAction extends ApiAction // 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); + } + } } /** @@ -218,7 +191,7 @@ class ApiAccountRegisterAction extends ApiAction if (!$email || strlen($email) == 0) { return false; } - $user = User::staticGet('email', $email); + $user = User::getKV('email', $email); return is_object($user); }