コード例 #1
0
 /**
  * Try to log in using OpenID
  *
  * Check the OpenID for validity; potentially store it.
  *
  * @return void
  */
 function tryLogin()
 {
     $consumer = oid_consumer();
     $response = $consumer->complete(common_local_url('finishaddopenid'));
     if ($response->status == Auth_OpenID_CANCEL) {
         $this->message(_m('OpenID authentication cancelled.'));
         return;
     } else {
         if ($response->status == Auth_OpenID_FAILURE) {
             // Authentication failed; display the error message.
             $this->message(sprintf(_m('OpenID authentication failed: %s'), $response->message));
         } else {
             if ($response->status == Auth_OpenID_SUCCESS) {
                 $display = $response->getDisplayIdentifier();
                 $canonical = $response->endpoint && $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $display;
                 $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
                 if ($sreg_resp) {
                     $sreg = $sreg_resp->contents();
                 }
                 $cur = common_current_user();
                 $other = oid_get_user($canonical);
                 if ($other) {
                     if ($other->id == $cur->id) {
                         $this->message(_m('You already have this OpenID!'));
                     } else {
                         $this->message(_m('Someone else already has this OpenID.'));
                     }
                     return;
                 }
                 // start a transaction
                 $cur->query('BEGIN');
                 $result = oid_link_user($cur->id, $canonical, $display);
                 if (!$result) {
                     $this->message(_m('Error connecting user.'));
                     return;
                 }
                 if ($sreg) {
                     if (!oid_update_user($cur, $sreg)) {
                         $this->message(_m('Error updating profile'));
                         return;
                     }
                 }
                 // success!
                 $cur->query('COMMIT');
                 oid_set_last($display);
                 common_redirect(common_local_url('openidsettings'), 303);
             }
         }
     }
 }
コード例 #2
0
 /**
  * Try to log in using OpenID
  *
  * Check the OpenID for validity; potentially store it.
  *
  * @return void
  */
 function tryLogin()
 {
     $consumer = oid_consumer();
     $response = $consumer->complete(common_local_url('finishaddopenid'));
     if ($response->status == Auth_OpenID_CANCEL) {
         // TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled.
         $this->message(_m('OpenID authentication cancelled.'));
         return;
     } else {
         if ($response->status == Auth_OpenID_FAILURE) {
             // TRANS: OpenID authentication failed; display the error message.
             // TRANS: %s is the error message.
             $this->message(sprintf(_m('OpenID authentication failed: %s.'), $response->message));
         } else {
             if ($response->status == Auth_OpenID_SUCCESS) {
                 $display = $response->getDisplayIdentifier();
                 $canonical = $response->endpoint && $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $display;
                 $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
                 if ($sreg_resp) {
                     $sreg = $sreg_resp->contents();
                 }
                 // Launchpad teams extension
                 if (!oid_check_teams($response)) {
                     // TRANS: OpenID authentication error.
                     $this->message(_m('OpenID authentication aborted: You are not allowed to login to this site.'));
                     return;
                 }
                 $cur = common_current_user();
                 $other = oid_get_user($canonical);
                 if ($other) {
                     if ($other->id == $cur->id) {
                         // TRANS: Message in case a user tries to add an OpenID that is already connected to them.
                         $this->message(_m('You already have this OpenID!'));
                     } else {
                         // TRANS: Message in case a user tries to add an OpenID that is already used by another user.
                         $this->message(_m('Someone else already has this OpenID.'));
                     }
                     return;
                 }
                 // start a transaction
                 $cur->query('BEGIN');
                 $result = oid_link_user($cur->id, $canonical, $display);
                 if (!$result) {
                     // TRANS: Message in case the OpenID object cannot be connected to the user.
                     $this->message(_m('Error connecting user.'));
                     return;
                 }
                 if (Event::handle('StartOpenIDUpdateUser', array($cur, $canonical, &$sreg))) {
                     if ($sreg) {
                         if (!oid_update_user($cur, $sreg)) {
                             // TRANS: Message in case the user or the user profile cannot be saved in StatusNet.
                             $this->message(_m('Error updating profile.'));
                             return;
                         }
                     }
                 }
                 Event::handle('EndOpenIDUpdateUser', array($cur, $canonical, $sreg));
                 // success!
                 $cur->query('COMMIT');
                 oid_set_last($display);
                 common_redirect(common_local_url('openidsettings'), 303);
             }
         }
     }
 }
コード例 #3
0
 function connectUser()
 {
     $nickname = $this->trimmed('nickname');
     $password = $this->trimmed('password');
     if (!common_check_user($nickname, $password)) {
         // TRANS: OpenID plugin message.
         $this->showForm(_m('Invalid username or password.'));
         return;
     }
     # They're legit!
     $user = User::staticGet('nickname', $nickname);
     list($display, $canonical, $sreg) = $this->getSavedValues();
     if (!$display || !$canonical) {
         // TRANS: OpenID plugin server error. A stored OpenID cannot be found.
         $this->serverError(_m('Stored OpenID not found.'));
         return;
     }
     $result = oid_link_user($user->id, $canonical, $display);
     if (!$result) {
         // TRANS: OpenID plugin server error. The user or user profile could not be saved.
         $this->serverError(_m('Error connecting user to OpenID.'));
         return;
     }
     if (Event::handle('StartOpenIDUpdateUser', array($user, $canonical, &$sreg))) {
         oid_update_user($user, $sreg);
     }
     Event::handle('EndOpenIDUpdateUser', array($user, $canonical, $sreg));
     oid_set_last($display);
     common_set_user($user);
     common_real_login(true);
     if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
         common_rememberme($user);
     }
     unset($_SESSION['openid_rememberme']);
     $this->goHome($user->nickname);
 }
コード例 #4
0
ファイル: finishopenidlogin.php プロジェクト: Br3nda/laconica
 function connectUser()
 {
     $nickname = $this->trimmed('nickname');
     $password = $this->trimmed('password');
     if (!common_check_user($nickname, $password)) {
         $this->showForm(_('Invalid username or password.'));
         return;
     }
     # They're legit!
     $user = User::staticGet('nickname', $nickname);
     list($display, $canonical, $sreg) = $this->getSavedValues();
     if (!$display || !$canonical) {
         $this->serverError(_('Stored OpenID not found.'));
         return;
     }
     $result = oid_link_user($user->id, $canonical, $display);
     if (!$result) {
         $this->serverError(_('Error connecting user to OpenID.'));
         return;
     }
     oid_update_user($user, $sreg);
     oid_set_last($display);
     common_set_user($user);
     common_real_login(true);
     if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
         common_rememberme($user);
     }
     unset($_SESSION['openid_rememberme']);
     $this->goHome($user->nickname);
 }