summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-06-19 09:47:10 -0400
committerEvan Prodromou <evan@prodromou.name>2008-06-19 09:47:10 -0400
commit171b4f72ee5a84d2a67b99aca7df9406e68f60c1 (patch)
tree89d7a8cffb534fad758df3812a197801d54783d6 /actions
parent7258969cd48d9e11e500db56665e190d05d1e4c0 (diff)
immediate mode for openid
darcs-hash:20080619134710-84dde-6086a4ac7bbd72a251fe5ce6fe3156e3270ebd74.gz
Diffstat (limited to 'actions')
-rw-r--r--actions/finishaddopenid.php2
-rw-r--r--actions/finishimmediate.php64
-rw-r--r--actions/finishopenidlogin.php16
-rw-r--r--actions/logout.php3
-rw-r--r--actions/openidlogin.php14
5 files changed, 83 insertions, 16 deletions
diff --git a/actions/finishaddopenid.php b/actions/finishaddopenid.php
index 237f0454f..78aa67d89 100644
--- a/actions/finishaddopenid.php
+++ b/actions/finishaddopenid.php
@@ -88,6 +88,8 @@ class FinishaddopenidAction extends Action {
# success!
$cur->query('COMMIT');
+
+ oid_set_last($display);
common_redirect(common_local_url('openidsettings'));
}
diff --git a/actions/finishimmediate.php b/actions/finishimmediate.php
new file mode 100644
index 000000000..af55f166e
--- /dev/null
+++ b/actions/finishimmediate.php
@@ -0,0 +1,64 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once(INSTALLDIR.'/lib/openid.php');
+
+class FinishimmediateAction extends Action {
+
+ function handle($args) {
+ parent::handle($args);
+
+ $consumer = oid_consumer();
+
+ $response = $consumer->complete(common_local_url('finishimmediate'));
+
+ if ($response->status == Auth_OpenID_SUCCESS) {
+ $display = $response->getDisplayIdentifier();
+ $canonical = ($response->endpoint->canonicalID) ?
+ $response->endpoint->canonicalID : $response->getDisplayIdentifier();
+
+ $user = $this->get_user($canonical);
+
+ if ($user) {
+ $this->update_user($user, $sreg);
+ common_set_user($user->nickname);
+ $this->go_backto();
+ return;
+ }
+ }
+
+ # Failure! Clear openid so we don't try it again
+
+ oid_clear_last();
+ $this->go_backto();
+ return;
+ }
+
+ function go_backto() {
+ common_ensure_session();
+ $backto = $_SESSION['openid_immediate_backto'];
+ if (!$backto) {
+ # gar. Well, push them to the public page
+ $backto = common_local_url('public');
+ }
+ common_redirect($backto);
+ }
+}
diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php
index 2b3616ffa..3a7f9f250 100644
--- a/actions/finishopenidlogin.php
+++ b/actions/finishopenidlogin.php
@@ -104,9 +104,10 @@ class FinishopenidloginAction extends Action {
$sreg = $sreg_resp->contents();
}
- $user = $this->get_user($canonical);
+ $user = oid_get_user($canonical);
if ($user) {
+ oid_set_last($display);
$this->update_user($user, $sreg);
common_set_user($user->nickname);
$this->go_home($user->nickname);
@@ -123,15 +124,6 @@ class FinishopenidloginAction extends Action {
common_show_footer();
}
- function get_user($canonical) {
- $user = NULL;
- $oid = User_openid::staticGet('canonical', $canonical);
- if ($oid) {
- $user = User::staticGet('id', $oid->user_id);
- }
- return $user;
- }
-
function update_user($user, $sreg) {
$profile = $user->getProfile();
@@ -210,7 +202,7 @@ class FinishopenidloginAction extends Action {
# Possible race condition... let's be paranoid
- $other = $this->get_user($canonical);
+ $other = oid_get_user($canonical);
if ($other) {
common_server_error(_t('Creating new account for OpenID that already has a user.'));
@@ -272,6 +264,7 @@ class FinishopenidloginAction extends Action {
$profile->delete();
}
+ oid_set_last($display);
common_set_user($user->nickname);
common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)));
}
@@ -305,6 +298,7 @@ class FinishopenidloginAction extends Action {
}
$this->update_user($user, $sreg);
+ oid_set_last($display);
common_set_user($user->nickname);
$this->go_home($user->nickname);
}
diff --git a/actions/logout.php b/actions/logout.php
index 4df69c3b3..9cdda52d8 100644
--- a/actions/logout.php
+++ b/actions/logout.php
@@ -19,6 +19,8 @@
if (!defined('LACONICA')) { exit(1); }
+require_once(INSTALLDIR.'/lib/openid.php');
+
class LogoutAction extends Action {
function handle($args) {
parent::handle($args);
@@ -26,6 +28,7 @@ class LogoutAction extends Action {
common_user_error(_t('Not logged in.'));
} else {
common_set_user(NULL);
+ oid_clear_last();
common_redirect(common_local_url('public'));
}
}
diff --git a/actions/openidlogin.php b/actions/openidlogin.php
index ecc4e6bff..f00c17181 100644
--- a/actions/openidlogin.php
+++ b/actions/openidlogin.php
@@ -28,13 +28,15 @@ class OpenidloginAction extends Action {
if (common_logged_in()) {
common_user_error(_t('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $result = oid_authenticate($this->trimmed('openid_url'),
+ $openid_url = $this->trimmed('openid_url');
+ $result = oid_authenticate($openid_url,
'finishopenidlogin');
if (is_string($result)) { # error message
- $this->show_form($result);
+ $this->show_form($result, $openid_url);
}
} else {
- $this->show_form();
+ $openid_url = oid_get_last();
+ $this->show_form(NULL, $openid_url);
}
}
@@ -47,13 +49,15 @@ class OpenidloginAction extends Action {
}
}
- function show_form($error=NULL) {
+ function show_form($error=NULL, $openid_url) {
common_show_header(_t('OpenID Login'), NULL, $error, array($this, 'show_top'));
$formaction = common_local_url('openidlogin');
common_element_start('form', array('method' => 'POST',
'id' => 'openidlogin',
'action' => $formaction));
- common_input('openid_url', _t('OpenID URL'));
+ common_input('openid_url', _t('OpenID URL'),
+ $openid_url,
+ _t('Your OpenID URL'));
common_submit('submit', _t('Login'));
common_element_end('form');
common_show_footer();