123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- defined('GNUSOCIAL') || die();
- require_once(INSTALLDIR . '/plugins/OpenID/openid.php');
- class FinishsynchopenidAction extends Action
- {
- public $msg = null;
-
- public function handle()
- {
- parent::handle();
- if (!common_logged_in()) {
-
- $this->clientError(_m('Not logged in.'));
- } else {
- $this->tryLogin();
- }
- }
-
- public function tryLogin()
- {
- $consumer = oid_consumer();
- $response = $consumer->complete(common_local_url('finishsynchopenid'));
- if ($response->status == Auth_OpenID_CANCEL) {
-
- $this->message(_m('OpenID authentication cancelled.'));
- return;
- } elseif ($response->status == Auth_OpenID_FAILURE) {
-
-
- $this->message(sprintf(
- _m('OpenID authentication failed: %s.'),
- $response->message
- ));
- } elseif ($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();
- }
-
- if (!oid_check_teams($response)) {
-
- $this->message(_m('OpenID authentication aborted: You are not allowed to login to this site.'));
- return;
- }
- $cur = common_current_user();
-
- $cur->query('BEGIN');
- if (Event::handle('StartOpenIDUpdateUser', [$cur, $canonical, &$sreg])) {
- if (!oid_update_user($cur, $sreg)) {
-
- $this->message(_m('Error updating profile.'));
- return;
- }
- }
- Event::handle('EndOpenIDUpdateUser', [$cur, $canonical, $sreg]);
-
-
- $cur->query('COMMIT');
- oid_set_last($display);
- common_redirect(common_local_url('openidsettings'), 303);
- }
- }
-
- public function message($msg)
- {
- $this->message = $msg;
- $this->showPage();
- }
-
- public function title()
- {
-
-
- return _m('OpenID Synchronization');
- }
-
- public function showPageNotice()
- {
- if ($this->message) {
- $this->element('p', 'error', $this->message);
- }
- }
- }
|