- function createNewUser()
- {
-
- if (common_config('site', 'closed')) {
- $this->clientError(_('Registration not allowed.'));
- return;
- }
-
- $invite = null;
-
- if (common_config('site', 'inviteonly')) {
- $code = $_SESSION['invitecode'];
- if (empty($code)) {
- $this->clientError(_('Registration not allowed.'));
- return;
- }
-
- $invite = Invitation::staticGet($code);
-
- if (empty($invite)) {
- $this->clientError(_('Not a valid invitation code.'));
- return;
- }
- }
-
- $nickname = $this->trimmed('newname');
-
- if (!Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
- return;
- }
-
- if (!User::allowed_nickname($nickname)) {
- $this->showForm(_('Nickname not allowed.'));
- return;
- }
-
- if (User::staticGet('nickname', $nickname)) {
- $this->showForm(_('Nickname already in use. Try another one.'));
- return;
- }
-
- $fullname = trim($this->fb_fields['firstname'] .
- ' ' . $this->fb_fields['lastname']);
-
- $args = array('nickname' => $nickname, 'fullname' => $fullname);
-
- if (!empty($invite)) {
- $args['code'] = $invite->code;
- }
-
- $user = User::register($args);
-
- $result = $this->flinkUser($user->id, $this->fbuid);
-
- if (!$result) {
- $this->serverError(_('Error connecting user to Facebook.'));
- return;
- }
-
- common_set_user($user);
- common_real_login(true);
-
- common_debug("Registered new user $user->id from Facebook user $this->fbuid");
-
- common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)),
- 303);
- }
-
- function connectUser()
- {
- $nickname = $this->trimmed('nickname');
- $password = $this->trimmed('password');
-
- if (!common_check_user($nickname, $password)) {
- $this->showForm(_('Invalid username or password.'));
- return;
- }
-
- $user = User::staticGet('nickname', $nickname);
-
- if ($user) {
- common_debug("Legit user to connect to Facebook: $nickname");
- }
-
- $result = $this->flinkUser($user->id, $this->fbuid);
-
- if (!$result) {
- $this->serverError(_('Error connecting user to Facebook.'));
- return;
- }
-
- common_debug("Connected Facebook user $this->fbuid to local user $user->id");
-
- common_set_user($user);
- common_real_login(true);
-
- $this->goHome($user->nickname);
- }
-
- function tryLogin()
- {
- $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
-
- if ($flink) {
- $user = $flink->getUser();
-
- if ($user) {
-
- common_debug("Logged in Facebook user $flink->foreign_id as user $user->id");
-
- common_set_user($user);
- common_real_login(true);
- $this->goHome($user->nickname);
- }
-
- } else {
- $this->showForm(null, $this->bestNewNickname());
- }
- }
-
- function goHome($nickname)