<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,7 +6,7 @@
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     This version by Fran&#231;ois Hodierne (http://h6e.net/)
  * @author     Original by Andreas Gohr &lt;andi@splitbrain.org&gt;
- * @version    2.0 beta 2
+ * @version    2.0 beta 3
  */
 
 /**
@@ -46,7 +46,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 		return array(
 			'author' =&gt; 'h6e.net',
 			'email'  =&gt; 'contact@h6e.net',
-			'date'   =&gt; '2009-03-23',
+			'date'   =&gt; '2009-04-07',
 			'name'   =&gt; 'OpenID plugin',
 			'desc'   =&gt; 'Authenticate on a DokuWiki with OpenID',
 			'url'    =&gt; 'http://h6e.net/dokuwiki/plugins/openid',
@@ -125,7 +125,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 	 */
 	function handle_act_preprocess(&amp;$event, $param)
 	{
-		global $conf;
+		global $ID, $conf, $auth;
 
 		$user = $_SERVER['REMOTE_USER'];
         
@@ -139,9 +139,12 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 
 		if ($event-&gt;data != 'openid' &amp;&amp; $event-&gt;data != 'logout') {
 			// Warn the user to register an account if he's using a not registered OpenID
+			// and if registration is possible
 			if (preg_match('!^https?://!', $user)) {
-				$message = sprintf($this-&gt;getLang('complete_registration_notice'), $this-&gt;_self('openid'));
-				msg($message, 2);
+				if ($auth &amp;&amp; $auth-&gt;canDo('addUser') &amp;&amp; actionOK('register')) {
+					$message = sprintf($this-&gt;getLang('complete_registration_notice'), $this-&gt;_self('openid'));
+					msg($message, 2);
+				}
 			}
 		}
 
@@ -155,7 +158,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 
 				// we try to login with the OpenID submited
 				$consumer = $this-&gt;getConsumer();
-				$auth = $consumer-&gt;begin($_POST['openid_url']);
+				$auth = $consumer-&gt;begin($_POST['openid_identifier']);
 				if (!$auth) {
 					msg($this-&gt;getLang('enter_valid_openid_error'), -1);
 					return;
@@ -172,8 +175,8 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 				// redirect to OpenID provider for authentication
 
 				// this fix an issue with mod_rewrite with JainRain library
-				// when a parameter seems to be non existing in the query 
-				$return_to = $this-&gt;_self('openid') . '&amp;id=' . $_GET['id'];
+				// when a parameter seems to be non existing in the query
+				$return_to = $this-&gt;_self('openid') . '&amp;id=' . $ID;
 
 				$url = $auth-&gt;redirectURL(DOKU_URL, $return_to);
 				$this-&gt;_redirect($url);
@@ -207,13 +210,13 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 					} else {
 						$authenticate = $this-&gt;login_user($openid);
 						if ($authenticate) {
-							// redirect to restricted application page
-							$this-&gt;_redirect(DOKU_URL);
+							// redirect to the page itself (without do=openid)
+							$this-&gt;_redirect(wl($ID));
 						}
 					}
 
 				} else {
-					msg($this-&gt;getLang('openid_authentication_failed'), -1);
+					msg($this-&gt;getLang('openid_authentication_failed') . ': ' . $response-&gt;message, -1);
 					return;
 				}
 
@@ -233,6 +236,8 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 	 */
 	function handle_act_unknown(&amp;$event, $param)
 	{
+		global $auth, $ID;
+
 		if ($event-&gt;data != 'openid') {
 			return;
 		} 
@@ -249,13 +254,18 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 			html_form('register', $form);
 			print '&lt;/div&gt;'.NL;
 		} else if (preg_match('!^https?://!', $user)) {
-			print $this-&gt;plugin_locale_xhtml('complete');
-			print '&lt;div class=&quot;centeralign&quot;&gt;'.NL;
-			$form = $this-&gt;get_openid_form('extra');
-			html_form('complete', $form);
-			print '&lt;/div&gt;'.NL;
+			echo '&lt;h1&gt;', $this-&gt;getLang('openid_account_fieldset'), '&lt;/h1&gt;', NL;
+			if ($auth &amp;&amp; $auth-&gt;canDo('addUser') &amp;&amp; actionOK('register')) {
+				echo '&lt;p&gt;', $this-&gt;getLang('openid_complete_text'), '&lt;/p&gt;', NL;
+				print '&lt;div class=&quot;centeralign&quot;&gt;'.NL;
+				$form = $this-&gt;get_openid_form('extra');
+				html_form('complete', $form);
+				print '&lt;/div&gt;'.NL;
+			} else {
+				echo '&lt;p&gt;', sprintf($this-&gt;getLang('openid_complete_disabled_text'), wl($ID)), '&lt;/p&gt;', NL;
+			}
 		} else {
-			echo '&lt;h1&gt;' . $this-&gt;getLang('openid_identities_title') . '&lt;/h1&gt;';
+			echo '&lt;h1&gt;', $this-&gt;getLang('openid_identities_title'), '&lt;/h1&gt;', NL;
 			$identities = $this-&gt;get_associations($_SERVER['REMOTE_USER']);
 			if (!empty($identities)) {
 				echo '&lt;form action=&quot;' . $this-&gt;_self('openid') . '&quot; method=&quot;post&quot;&gt;&lt;div class=&quot;no&quot;&gt;';
@@ -280,7 +290,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 			$form-&gt;addHidden('mode', 'add');
 			$form-&gt;addElement(
 				form_makeTextField(
-					'openid_url', $_POST['openid_url'], $this-&gt;getLang('openid_url_label'), 'openid__url', 'block', array('size'=&gt;'50')
+					'openid_identifier', $_POST['openid_identifier'], $this-&gt;getLang('openid_url_label'), 'openid__url', 'block', array('size'=&gt;'50')
 				)
 			);
 			$form-&gt;addElement(form_makeButton('submit', '', $this-&gt;getLang('add_button')));
@@ -301,9 +311,10 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 		$p = array('size'=&gt;'50');
 
 		$form = new Doku_Form('openid__login', script());
+		$form-&gt;addHidden('id', $_GET['id']);
+		$form-&gt;addHidden('do', 'openid');
 		if ($mode == 'extra') {
 			$form-&gt;startFieldset($this-&gt;getLang('openid_account_fieldset'));
-			$form-&gt;addHidden('do', 'openid');
 			$form-&gt;addHidden('mode', 'extra');
 			$form-&gt;addElement(form_makeTextField('nickname', $_REQUEST['nickname'], $lang['user'], null, $c, $p));
 			$form-&gt;addElement(form_makeTextField('email', $_REQUEST['email'], $lang['email'], '', $c, $p));
@@ -311,9 +322,8 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 			$form-&gt;addElement(form_makeButton('submit', '', $this-&gt;getLang('complete_button')));
 		} else {
 			$form-&gt;startFieldset($this-&gt;getLang('openid_login_fieldset'));
-			$form-&gt;addHidden('do', 'openid');
 			$form-&gt;addHidden('mode', 'login');
-			$form-&gt;addElement(form_makeTextField('openid_url', $_POST['openid_url'], $this-&gt;getLang('openid_url_label'), 'openid__url', $c, $p));
+			$form-&gt;addElement(form_makeTextField('openid_identifier', $_REQUEST['openid_identifier'], $this-&gt;getLang('openid_url_label'), 'openid__url', $c, $p));
 			$form-&gt;addElement(form_makeButton('submit', '', $lang['btn_login']));
 		}
 		$form-&gt;endFieldset();
@@ -343,7 +353,21 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 	*/
 	function login_user($openid)
 	{
-		global $USERINFO, $auth;
+		global $USERINFO, $auth, $conf;
+        
+		// look for associations passed from an auth backend in user infos
+		$users = $auth-&gt;retrieveUsers();
+		foreach ($users as $id =&gt; $user) {
+			if (isset($user['openids'])) {
+				foreach ($user['openids'] as $identity) {
+					if ($identity == $openid) {
+						$USERINFO = $auth-&gt;getUserData($id);
+						$this-&gt;update_session($id);
+						return true;
+					}
+				}
+			}
+		}
 
 		$associations = $this-&gt;get_associations();
 
@@ -386,7 +410,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 	 */
 	function register_user()
 	{
-		global $USERINFO, $lang, $conf, $auth, $openid_associations;
+		global $USERINFO, $ID, $lang, $conf, $auth, $openid_associations;
 
 		if(!$auth-&gt;canDo('addUser')) return false;
 
@@ -423,7 +447,7 @@ class action_plugin_openid extends DokuWiki_Action_Plugin {
 		$this-&gt;update_session($user);
 
 		// account created, everything OK
-		$this-&gt;_redirect(DOKU_URL);
+		$this-&gt;_redirect(wl($ID));
 	}
 		
 	/**</diff>
      <filename>action.php</filename>
    </modified>
    <modified>
      <diff>@@ -24,4 +24,7 @@ $lang['openid_identity_added']          = 'OpenID identity successfully added';
 $lang['openid_authentication_failed']   = 'OpenID authentication failed';
 $lang['openid_authentication_canceled'] = 'OpenID authentication canceled.';
 
+$lang['openid_complete_text'] = 'Please now verify or complete your account informations to finish registration.';
+$lang['openid_complete_disabled_text'] = 'You\'re correctly authenticated but registration is not possible on this wiki. &lt;a href=&quot;%s&quot;&gt;Continue there.&lt;/a&gt;';
+
 $lang['none'] = 'None.';</diff>
      <filename>lang/en/lang.php</filename>
    </modified>
    <modified>
      <diff>@@ -24,4 +24,7 @@ $lang['openid_identity_added']          = 'Identit&#233; OpenID ajout&#233;e avec succ&#232;
 $lang['openid_authentication_failed']   = '&#201;chec de l\'authentification OpenID';
 $lang['openid_authentication_canceled'] = 'Authentification OpenID annul&#233;e';
 
+$lang['openid_complete_text'] = 'Veuillez v&#233;rifier ou compl&#233;ter les informations de votre compte pour finir l\'enregistrement.';
+$lang['openid_complete_disabled_text'] = 'Vous &#234;tes correctement authentifi&#233;s mais la finalisation de l\'enregistrement n\'est pas possible sur ce wiki. &lt;a href=&quot;%s&quot;&gt;Continuez ici.&lt;/a&gt;';
+
 $lang['none'] = 'Aucune.';</diff>
      <filename>lang/fr/lang.php</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lang/en/complete.txt</filename>
    </removed>
    <removed>
      <filename>lang/fr/complete.txt</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>9547dc19e4a192914fba07be0235cca5d1714229</id>
    </parent>
  </parents>
  <author>
    <name>Fran&#231;ois Hodierne</name>
    <email>francois@upian.com</email>
  </author>
  <url>http://github.com/znarf/dokuwiki-openid/commit/ec1b7a85be8764cb793d95cf512dea5abe32032d</url>
  <id>ec1b7a85be8764cb793d95cf512dea5abe32032d</id>
  <committed-date>2009-04-07T12:42:01-07:00</committed-date>
  <authored-date>2009-04-07T12:42:01-07:00</authored-date>
  <message>- don't warn to register if registration is off
- detailed error when authentication fail
- user openids can now be send by auth backend
- change input name to 'openid_identifier' following recommendation in openid spec
- don't lose current page in the authentication process</message>
  <tree>7119ad86310f07947ecf1730d516ed79ad692bc6</tree>
  <committer>
    <name>Fran&#231;ois Hodierne</name>
    <email>francois@upian.com</email>
  </committer>
</commit>
