User can choose to always trust websites
authorAymeric Augustin <aymeric.augustin@m4x.org>
Fri, 31 Oct 2008 22:52:30 +0000 (23:52 +0100)
committerAymeric Augustin <aymeric.augustin@m4x.org>
Fri, 31 Oct 2008 22:52:30 +0000 (23:52 +0100)
TODO implement a way to remove websites from the whitelist

modules/openid.php
modules/openid/openid.inc.php
templates/openid/trust.tpl

index e3ac3bc..7c66b8c 100644 (file)
  * Reading the source of the server can also help understanding the code below.
  */
 
-/* **checkid_immediate is not supported (yet)**, which means that we will
- * always ask for confirmation before redirecting to a third-party.
- * A sensible way to implement it would be to add a "Always trust this site"
- * checkbox to the form, and to store trusted websites per user. This still
- * raises the question of removing websites from that list.
- * Another possibility is to maintain a global whitelist.
- */
 
 class OpenidModule extends PLModule
 {
@@ -170,7 +163,7 @@ class OpenidModule extends PLModule
         $sreg_response = Auth_OpenID_SRegResponse::extractResponse($sreg_request, get_sreg_data($user));
 
         // Check the whitelist
-        $whitelisted = is_trusted_site($user, $request->trust_root);
+        $whitelisted = false;//is_trusted_site($user, $request->trust_root);
 
         // Ask the user for confirmation
         if (!$whitelisted && $_SERVER['REQUEST_METHOD'] != 'POST') {
@@ -181,6 +174,12 @@ class OpenidModule extends PLModule
         }
 
         // At this point $_SERVER['REQUEST_METHOD'] == 'POST'
+
+        // Add 'always trusted' sites to whitelist
+        if (isset($_POST['trust']) && @$_POST['always']) {
+            add_trusted_site($user, $request->trust_root);
+        }
+
         // Answer to the Relying Party
         if ($whitelisted || isset($_POST['trust'])) {
             S::kill('openid_request');
index 6a749ab..4a55439 100644 (file)
@@ -119,5 +119,12 @@ function is_trusted_site($user, $url)
     return $res->fetchOneCell() > 0;
 }
 
+function add_trusted_site($user, $url)
+{
+    XDB::execute("INSERT IGNORE INTO openid_trusted
+                      SET user_id={?}, url={?}",
+                  $user->id(), $url);
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
\ No newline at end of file
index 0ac66e4..fa5f68e 100644 (file)
 </ul>
 {/if}
 
-<p><strong>Souhaitez-vous confirmer votre identité ?<strong></p>
+
+<p><strong>Souhaitez-vous confirmer votre identité ?</strong></p>
 
 <div class="form">
   <form method="post" action="openid/trust">
+    <input type="checkbox" name="always" /> Toujours faire confiance à ce site<br />
     <input type="submit" name="trust" value="Confirmer" />
     <input type="submit" value="Annuler" />
   </form>