<?php
-
/**
* StatusNet, the distributed open-source microblogging tool
*
// 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' => $this->code))) {
- if (!$user instanceof 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);
- }
- }
+
+ // 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);
+ }
+ }
}
/**
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
/**
* An action for registering a new user account
} else if ($password != $confirm) {
// TRANS: Form validation error displayed when trying to register with non-matching passwords.
$this->showForm(_('Passwords do not match.'));
- } else if ($user = User::register(array('nickname' => $nickname,
+ } else {
+ try {
+ $user = User::register(array('nickname' => $nickname,
'password' => $password,
'email' => $email,
'fullname' => $fullname,
'bio' => $bio,
'location' => $location,
'code' => $code))) {
- if (!($user instanceof User)) {
+ // success!
+ if (!common_set_user($user)) {
+ // TRANS: Server error displayed when saving fails during user registration.
+ $this->serverError(_('Error setting user.'));
+ }
+ // this is a real login
+ common_real_login(true);
+ if ($this->boolean('rememberme')) {
+ common_debug('Adding rememberme cookie for ' . $nickname);
+ common_rememberme($user);
+ }
+
+ // Re-init language env in case it changed (not yet, but soon)
+ common_init_language();
+
+ Event::handle('EndRegistrationTry', array($this));
+
+ $this->showSuccess();
+ } catch (Exception $e) {
// TRANS: Form validation error displayed when trying to register with an invalid username or password.
- $this->showForm(_('Invalid username or password.'));
- return;
- }
- // success!
- if (!common_set_user($user)) {
- // TRANS: Server error displayed when saving fails during user registration.
- $this->serverError(_('Error setting user.'));
- }
- // this is a real login
- common_real_login(true);
- if ($this->boolean('rememberme')) {
- common_debug('Adding rememberme cookie for ' . $nickname);
- common_rememberme($user);
+ $this->showForm($e->getMessage());
}
-
- // Re-init language env in case it changed (not yet, but soon)
- common_init_language();
-
- Event::handle('EndRegistrationTry', array($this));
-
- $this->showSuccess();
- } else {
- // TRANS: Form validation error displayed when trying to register with an invalid username or password.
- $this->showForm(_('Invalid username or password.'));
}
}
}
* string 'password' (may be missing for eg OpenID registrations)
* string 'code' invite code
* ?string 'uri' permalink to notice; defaults to local notice URL
- * @return mixed User object or false on failure
+ * @return User object
+ * @throws Exception on failure
*/
static function register(array $fields) {
$email = common_canonical_email($email);
}
- try {
- $profile->nickname = Nickname::normalize($nickname, true);
- } catch (NicknameException $e) {
- common_log(LOG_WARNING, sprintf('Bad nickname during User registration for %s: %s', $nickname, $e->getMessage()), __FILE__);
- return false;
- }
+ // Normalize _and_ check whether it is in use. Throw NicknameException on failure.
+ $profile->nickname = Nickname::normalize($nickname, true);
$profile->profileurl = common_profile_url($profile->nickname);
$id = $profile->insert();
if ($id === false) {
common_log_db_error($profile, 'INSERT', __FILE__);
- return false;
+ $profile->query('ROLLBACK');
+ // TRANS: Profile data could not be inserted for some reason.
+ throw new ServerException(_m('Could not insert profile data for new user.'));
}
$user->id = $id;
if ($result === false) {
common_log_db_error($user, 'INSERT', __FILE__);
$profile->query('ROLLBACK');
- return false;
+ // TRANS: User data could not be inserted for some reason.
+ throw new ServerException(_m('Could not insert user data for new user.'));
}
// Everyone is subscribed to themself
if (!$result) {
common_log_db_error($subscription, 'INSERT', __FILE__);
$profile->query('ROLLBACK');
- return false;
+ // TRANS: Subscription data could not be inserted for some reason.
+ throw new ServerException(_m('Could not insert subscription data for new user.'));
}
// Mark that this invite was converted
if (!$result) {
common_log_db_error($confirm, 'INSERT', __FILE__);
$profile->query('ROLLBACK');
- return false;
+ // TRANS: Email confirmation data could not be inserted for some reason.
+ throw new ServerException(_m('Could not insert email confirmation data for new user.'));
}
}
Event::handle('EndUserRegister', array($profile));
}
+ if (!$user instanceof User) {
+ throw new ServerException('User could not be registered. Probably an event hook that failed.');
+ }
+
return $user;
}
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Superclass for plugins that do authentication
//not much else we can do
}else{
$user = $this->autoRegister($nickname, $suggested_nickname);
- if($user){
+ if ($user instanceof User) {
User_username::register($user,$nickname,$this->provider_name);
return false;
}
if ($this->adminEmail) {
$data['email'] = $this->adminEmail;
}
- $user = User::register($data);
-
- if (empty($user)) {
+ try {
+ $user = User::register($data);
+ } catch (Exception $e) {
return false;
}
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
require_once dirname(__DIR__) . '/twitter.php';
$args['email'] = $email;
}
- $user = User::register($args);
-
- if (empty($user)) {
- // TRANS: Server error displayed when creating a new user has failed.
- $this->serverError(_m('Error registering user.'));
+ try {
+ $user = User::register($args);
+ } catch (Exception $e) {
+ $this->serverError($e->getMessage());
}
$result = $this->saveForeignLink($user->id,