FIx open id
authorclebeaupin
Thu, 06 May 2010 23:49:04 +0200
changeset 128 2c81a2ebea39
parent 127 53fc6b77c676
child 129 ae0c67ef08e1
FIx open id
web/thdProject/apps/frontend/lib/myUser.class.php
web/thdProject/apps/frontend/modules/account/actions/loginUserAction.class.php
web/thdProject/apps/frontend/modules/account/actions/openidLoginAction.class.php
web/thdProject/apps/frontend/modules/account/templates/_loginUserFormHeader.php
web/thdProject/apps/frontend/modules/account/templates/loginUserForm.php
web/thdProject/apps/frontend/modules/partials/templates/_userPanel.php
web/thdProject/lib/actions/openidAction.class.php
web/thdProject/lib/core/ThdUtil.php
web/thdProject/plugins/sfPHPOpenIdPlugin/lib/sfPHPOpenID.class.php
web/thdProject/web/css/base.css
web/thdProject/web/css/layout.css
--- a/web/thdProject/apps/frontend/lib/myUser.class.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/apps/frontend/lib/myUser.class.php	Thu May 06 23:49:04 2010 +0200
@@ -14,8 +14,7 @@
   public function getUid() {
     if (!$this->isAuthenticated()) return false;
 
-    // FIXME
-    return "thd.fake";
+    return $this->getIdentity();
   }
 
   public function logout() {
--- a/web/thdProject/apps/frontend/modules/account/actions/loginUserAction.class.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/apps/frontend/modules/account/actions/loginUserAction.class.php	Thu May 06 23:49:04 2010 +0200
@@ -1,23 +1,64 @@
 <?php
 
-class loginUserAction extends openidAction {
+class loginUserAction extends sfAction {
 
   public function execute($request) {
-    if ($request->isMethod('post')) {
-      if (sfConfig::get('app_openid_fake') === true) {
-        $user = $this->getUser();
-        $user->login(null);
-        return $this->redirect('@homepage');
+    if (!$request->isMethod('post')) return "Form";
+    $login = $request->getParameter('login', null);
+
+    if (sfConfig::get('app_openid_fake') === true) {
+
+      $user = $this->getUser();
+      $user->login($login);
+      return $this->redirect('@homepage');
+    } else {
+      if (!is_null($login)) {
+        $identity = sfConfig::get('app_openid_service_uri').$login.'/';
       } else {
-        // Get openid object
-        $openid = $this->getOpenIdObject();
+        $identity = $request->getParameter('oid', null);
+      }
+
+      if (is_null($identity)) return "Form";
+
+      $openid = ThdUtil::getOpenIdObject($identity);
+      // Redirect to open id provider
+      $redirectUrl = $openid->getRedirectURL(false);
+      $nextStep = $openid->getRedirectURL($immediate, $submitLabel);
+
+      if (($nextStep['type'] == 'url') && (!empty($nextStep['content']))) {
+        // Using OpenID 1 => redirection using URL
+        $result['success'] = true;
+
+        $result['htmlCode'] = "<script type=\"text/javascript\">var transiting = true;document.location.href = \"".$nextStep['content']."\"</script>"; // auto redirect if js on
+        $result['htmlCode'] .= "<a href=\"".$nextStep['content']."\" ";
+        unset($linkAttrs['href']);
+        $linkAttrs['id'] = 'openid_message';
 
-        // Redirect to open id provider
-        $redirectUrl = $openid->getRedirectURL(false);
-        return $this->redirect($redirectUrl['content']);
+        foreach ($linkAttrs as $name => $attr) {
+            $result['htmlCode'] .= sprintf(" %s=\"%s\"", $name, $attr);
+        }
+        $result['htmlCode'] .= ">$linkLabel</a>";
+        $result['htmlCode'] .= "<script type=\"text/javascript\">document.getElementById('".$linkAttrs['id']."').style.display = 'none';</script>"; // Hide the link if js on (=auto redirect)
       }
-    }
+      else if (($nextStep['type'] == 'form') && (!empty($nextStep['content']))) {
+        // Using OpenID 2 => redirection using a form
+        $result['success'] = true;
 
-  	return "Form";
+        $result['htmlCode'] = $nextStep['content'];
+        $result['htmlCode'] .= "<script type=\"text/javascript\">document.getElementById('openid_message').style.display = 'none';</script>"; // Auto submit if js on
+        $result['htmlCode'] .= "<script type=\"text/javascript\">var transiting = true;document.getElementById('openid_message').submit();</script>"; // hide form if js on
+      }
+      else {
+        // Show an error message
+        if (empty($nextStep['content']))
+          $result['error'] = "Unexpected error.";
+        else
+          $result['error'] = $nextStep['content'];
+      }
+
+      if (!isset($result['success'])) return "Form";
+
+      return $this->renderText($result['htmlCode']);
+    }
   }
 }
\ No newline at end of file
--- a/web/thdProject/apps/frontend/modules/account/actions/openidLoginAction.class.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/apps/frontend/modules/account/actions/openidLoginAction.class.php	Thu May 06 23:49:04 2010 +0200
@@ -1,10 +1,11 @@
 <?php
 
-class openidLoginAction extends openidAction {
+class openidLoginAction extends sfAction {
 
   public function execute($request) {
     // Get openid object
-    $openid = $this->getOpenIdObject();
+    $identity = $request->getParameter('openid.identity');
+    $openid = ThdUtil::getOpenIdObject($identity);
 
     // Check authentication validity
     $authResult = $openid->getAuthResult();
@@ -12,7 +13,10 @@
 
     if ($authResult['result'] == sfPHPOpenID::AUTH_SUCCESS) {
       // User is authenticated by open id provider
-      $user->login($authResult['identity']);
+      $serviceUri = sfConfig::get('app_openid_service_uri');
+      $login = substr($authResult['identity'], strlen($serviceUri));
+      $login = str_replace('/', '', $login);
+      $user->login($login);
     } else {
       $user->setFlash('login_error', 'Authentification échoué');
     }
--- a/web/thdProject/apps/frontend/modules/account/templates/loginUserForm.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/apps/frontend/modules/account/templates/loginUserForm.php	Thu May 06 23:49:04 2010 +0200
@@ -2,7 +2,11 @@
   <div class="head"><h3>Pas encore inscrit ?</h3></div>
   <div class="infos">Bienvenue dans le projet UniversCiné THD.<br/><br/>Ce site entre dans le cadre d'un projet de recherche sur le très haut débit réunissant trois acteurs autour de ce site :<br/><a href="http://www.universcine.com">UniversCiné</a>, <a href="http://ww.iri.centrepompidou.com">l'iri</a>, <a href="http://www.csl.sony.fr">Sony CSL</a> et <a href="http://www.capdigital.com">Cap digital</a></div>
   <div class="access">
-    <form action="<?php echo url_for('@loginUser'); ?>" method="post">
+    <form class="table-form" action="<?php echo url_for('@loginUser'); ?>" method="post">
+      <div class="field">
+        <label for="field-login">Login</label>
+        <input type="text" id="field-login" name="login" value="" />
+      </div>
       <div class="buttons">
         <?php echo uc_render_submit_button('Accéder au service'); ?>
       </div>
--- a/web/thdProject/apps/frontend/modules/partials/templates/_userPanel.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/apps/frontend/modules/partials/templates/_userPanel.php	Thu May 06 23:49:04 2010 +0200
@@ -1,7 +1,7 @@
 <div id="header-user">
   <div class="login">
-    <form class="table-form<?php if (isset($classes)) echo ' '.$classes; ?>" method="post" action="<?php echo url_for('@logoutUser')?>">
-      <span class="head">Bienvenue sur UniversCine THD</span>
+    <form method="post" action="<?php echo url_for('@logoutUser')?>">
+      <span class="head">Bienvenue <?php echo $user->getUid(); ?></span>
       <ul class="item-list">
         <li><a href="<?php echo url_for('@viewMyTagList'); ?>"class ="link-action">Voir mes tags</a></li>
       </ul>
--- a/web/thdProject/lib/actions/openidAction.class.php	Wed May 05 16:33:19 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<?php
-
-class openidAction extends sfAction {
-  public function execute($request) {
-
-  }
-
-  public function getOpenIdObject() {
-    // Instantiate openid
-    $identity = sfConfig::get('app_openid_service_uri');
-    $controller = $this->getController();
-    $openid = new sfPHPOpenID();
-    $openid->setIdentity($identity);
-
-    // Script which handles a response from OpenID Server
-    $processUrl = $controller->genUrl('@openidLogin', true);
-    $openid->setApprovedURL($processUrl);
-
-    // Url of website
-    $trustUrl = $controller->genUrl('@homepage', true);
-    $openid->SetTrustRoot($trustUrl);
-
-    return $openid;
-  }
-}
--- a/web/thdProject/lib/core/ThdUtil.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/lib/core/ThdUtil.php	Thu May 06 23:49:04 2010 +0200
@@ -78,15 +78,15 @@
 
     static public function getGlobalTagCloud($limit=10) {
       $tags = Array();
+      return $tags;
 
-      
       //facet=true&facet.limit=-1&facet.field=tags
       $parameters = Array('facet'=>'true', 'facet.limit'=>"$limit", 'facet.field'=>'tags_exact' );
-      
+
       $solr = uvmcSolrServicesManager::getInstance()->getService();
       $response = $solr->search("*:*", 0, 0, $parameters);
       $result = unserialize($response->getRawResponse());
-      
+
       foreach ($result["facet_counts"]["facet_fields"]["tags_exact"] as $tag_name => $count) {
         $tags[] = Array('tag' => $tag_name, 'count' => (int) $count);
       }
@@ -94,4 +94,20 @@
       return $tags;
 
     }
+
+    static public function getOpenIdObject($identity) {
+      $controller = sfContext::getInstance()->getController();
+      $openid = new sfPHPOpenID();
+      $openid->setIdentity($identity);
+
+      // Script which handles a response from OpenID Server
+      $processUrl = $controller->genUrl('@openidLogin', true);
+      $openid->setApprovedURL($processUrl);
+
+      // Url of website
+      $trustUrl = $controller->genUrl('@homepage', true);
+      $openid->SetTrustRoot($trustUrl);
+
+      return $openid;
+    }
 }
--- a/web/thdProject/plugins/sfPHPOpenIdPlugin/lib/sfPHPOpenID.class.php	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/plugins/sfPHPOpenIdPlugin/lib/sfPHPOpenID.class.php	Thu May 06 23:49:04 2010 +0200
@@ -3,11 +3,11 @@
 /*
  * This file is part of sfPHPOpenIDPlugin.
  * (c) 2009 GenOuest Platform <support@genouest.org>
- * 
+ *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
- 
+
 /**
  * sfPHPOpenID class.
  *
@@ -19,7 +19,7 @@
 /**
  * This class is a wrapper around PHP OpenID library.
  */
- 
+
 $libIncludePath = sfConfig::get('app_sf_phpopenid_plugin_lib_path');
 if (empty($libIncludePath))
   $libIncludePath = sfConfig::get('sf_root_dir') . '/lib/php-openid';
@@ -38,7 +38,7 @@
   const AUTH_CANCEL         = 1;
   const AUTH_FAILURE        = 2;
   const AUTH_SETUP_NEEDED   = 3;
-  
+
   private $openid_url_identity;
   private $trust_root;
   private $approved_url;
@@ -50,7 +50,7 @@
                                      'email' =>'http://axschema.org/contact/email');
   private $required_AX_fields = array('fullname', 'email', 'firstname', 'lastname'); // List of required fields from $request_fields_AX. Default (= not specified) is not required.
   private $count_AX_fields = array(); // The number of values requested for the corresponding AX field. Default (= not specified) is unlimited.
-  
+
   private $available_sreg_values =  array('dob',
                                           'gender',
                                           'postcode',
@@ -77,14 +77,14 @@
   /**
    * getRedirectURL
    * Prepare an http request to send to the openid provider.
-   * 
+   *
    * @returns An array: 'type' => 'url|form|error', 'content' => 'the Url or the form content or error message'
    */
   public function getRedirectURL($immediate = false, $submitLabel = '')
   {
     if (empty($submitLabel))
       $submitLabel = 'Continue';
-      
+
     $consumer = $this->getConsumer();
 
     // Begin the OpenID authentication process.
@@ -142,7 +142,7 @@
     } else {
         // Generate form markup and render it.
         $form_id = 'openid_message';
-        
+
         $form_html = $this->formMarkupWithLabel($auth_request, $this->getTrustRoot(), $this->getApprovedURL(),
                                                $immediate, array('id' => $form_id), $submitLabel);
 
@@ -194,7 +194,7 @@
     }
     $this->openid_url_identity = $identity;
   }
-  
+
   /**
    * getIdentity
    * Returns the url given by the user as his identity
@@ -290,7 +290,7 @@
 			  );
     return $pape_policy_uris;
   }
-  
+
   /**
    * setRequestFields
    * Sets the fields that should be retrieved from the user openid account.
@@ -316,7 +316,7 @@
       }
     }
   }
-  
+
   /**
    * getRequestFieldsSREG
    * Gets the SREG fields that should be retrieved from the user openid account
@@ -327,7 +327,7 @@
   {
     return $this->request_fields_sreg;
   }
-  
+
   /**
    * getRequestFieldsAX
    * Gets the AX fields that should be retrieved from the user openid account
@@ -338,7 +338,7 @@
   {
     return $this->request_fields_AX;
   }
-  
+
  /**
   * setRequiredAXFields
   * Set the given AX fields as required.
@@ -348,7 +348,7 @@
   public function setRequiredAXFields($required) {
     $this->required_AX_fields = array_merge($this->required_AX_fields, $required);
   }
-  
+
  /**
   * getRequiredAXFields
   * Get the required AX fields.
@@ -358,7 +358,7 @@
   public function getRequiredAXFields() {
     return $this->required_AX_fields;
   }
-  
+
  /**
   * isRequiredAXField
   * Returns wether the given AX field alias is required or not.
@@ -369,7 +369,7 @@
   public function isRequiredAXField($alias) {
     return in_array($alias, $this->required_AX_fields);
   }
-  
+
  /**
   * setCountAXFields
   * Set the number of values to ask for the given AX fields.
@@ -379,7 +379,7 @@
   public function setCountAXFields($count) {
     $this->count_AX_fields = array_merge($this->count_AX_fields, $count);
   }
-  
+
  /**
   * getCountAXFields
   * Get the number of values to ask for each AX field (If not specified, count is unlimited).
@@ -389,7 +389,7 @@
   public function getCountAXFields() {
     return $this->count_AX_fields;
   }
-  
+
  /**
   * getCountForAXField
   * Get the number of values to ask for the given AX field alias.
@@ -400,14 +400,14 @@
   public function getCountForAXField($alias) {
     if (array_key_exists($alias, $this->count_AX_fields))
       return $this->count_AX_fields[$alias];
-      
+
     return Auth_OpenID_AX_UNLIMITED_VALUES;
   }
 
  /**
   * getAuthResult
   * Returns the result of the authentification and the data retrieved from the user profile.
-  * 
+  *
   * @returns An array containing result and user data (in case of success):
   *  {'result' => 'result code',
   *   'message' => 'an optional message',
@@ -423,7 +423,7 @@
     $res['identity'] = '';
     $res['userData'] = array();
     $res['PAPEResp'] = '';
-    
+
     $consumer = $this->getConsumer();
 
     // Complete the authentication process using the server's
@@ -463,9 +463,9 @@
         foreach ($sregData as $field => $value) {
           $res['userData'][$field] = array($value);
         }
-        
+
         // Get AX data (use AX instead of SREG data if both are returned by the provider (or no SREG data))
-        $ax_resp = new Auth_OpenID_AX_FetchResponse();
+        /*$ax_resp = new Auth_OpenID_AX_FetchResponse();
         $ax_resp = $ax_resp->fromSuccessResponse($response);
         if ($ax_resp) {
           foreach ($this->request_fields_AX as $alias => $url) {
@@ -476,14 +476,14 @@
               else
                 $res['userData'][$alias] = array_filter(array_merge($res['userData'][$alias], $get_ax));
           }
-        }
-        
+        }*/
+
         $res['PAPEResp'] = Auth_OpenID_PAPE_Response::fromSuccessResponse($response);
     }
-    
+
     return $res;
   }
-  
+
   private function getStore() {
       /**
        * This is where the app will store its OpenID information.
--- a/web/thdProject/web/css/base.css	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/web/css/base.css	Thu May 06 23:49:04 2010 +0200
@@ -248,210 +248,6 @@
   color: #FFFFFF;
 }
 
-
-
-.table-form .form-description {
-  color: #777777;
-  margin-left: 7px;
-  font-size: 11px;
-  font-weight: bold;
-}
-
-.table-form .form-description .required {
-  color: #990000;
-}
-
-.table-form .form-error {
-  padding: 10px 10px 10px 40px;
-  margin: 5px 0;
-  color: #ffffff;
-  background: #990000 url("/images/pictos/error.png") no-repeat 5px 10px;
-}
-
-.table-form li {
-  display:block;
-}
-.table-form ul {
-  margin: 0 20px;
-}
-
-.table-form a.link-action {
-  font-family: arial, verdana, sans-serif;
-  font-size: 10px;
-  color: #FFFFFF;
-  font-weight: bold;
-  text-transform: uppercase;
-  text-decoration: none;
-  padding: 0 0 0 8px;
-  background: transparent url('../images/pictos/link_action.png') no-repeat 0 3px;
-}
-
-.table-form fieldset {
-  display: block;
-  padding: 10px 0;
-  border: none;
-}
-
-.table-form .field {
-  clear: both;
-  width: 100%;
-  float: left;
-  padding: 2px 0px;
-}
-
-.table-form .field label {
-  display: block;
-  float: left;
-  margin-left: 7px;
-  margin-right: 7px;
-  color: #777777;
-  font-weight: bold;
-  padding-top: 4px;
-}
-
-.table-form .field input,
-.table-form .field select,
-.table-form .field .input-date,
-.table-form .field ul.radio_list {
-  display: block;
-  float: right;
-  margin-right: 7px;
-}
-
-.table-form .field .input-date select {
-  display: inline-block;
-  float: none;
-  width: auto;
-  margin: 0px;
-}
-
-.table-form .field ul.radio_list {
-  list-style: none;
-}
-
-.table-form .field ul.radio_list label,
-.table-form .field ul.radio_list input,
-.table-form .field ul.radio_list li {
-  display: inline;
-  padding: 0px;
-  margin: 0px;
-  float: none;
-  text-align: right;
-  line-height: 23px;
-  width: auto;
-}
-
-.table-form .field ul.radio_list li {
-  padding-left: 10px;
-}
-
-.table-form .field ul.radio_list input {
-  vertical-align: middle;
-}
-
-.table-form .field label .required {
-  color: #990000;
-  vertical-align: middle;
-  padding-left: 5px;
-}
-
-.table-form .field-type-file input {
-  height: 22px;
-}
-
-.table-form .field-type-file ul {
-  list-style: none;
-  float: right;
-  margin-right: 7px;
-}
-
-.table-form .field-type-file li {
-  display: block;
-  padding-bottom: 5px;
-  clear: both;
-}
-
-.table-form .field-type-file li label,
-.table-form .field-type-file li input {
-  display: inline;
-  float: none;
-  padding-top: 2px;
-  margin-left: 2px;
-  vertical-align: middle;
-}
-
-.table-form .field-type-file input {
-  clear: right;
-}
-
-.table-form .field-type-checkbox label {
-  float: left;
-  margin: 0 7px 0 7px;
-}
-
-.table-form .field-type-checkbox input {
-  float: left;
-  border: none;
-  padding: 0;
-  margin: 4px 0 0 8px;
-  background: transparent !important;
-}
-
-.table-form .field-type-captcha div {
-  clear: right;
-  float: right;
-}
-
-.table-form .field-type-captcha div a {
-  padding-right: 10px;
-}
-
-.table-form .field-type-captcha div input {
-  margin-top: 10px;
-}
-
-.table-form .buttons {
-  clear: both;
-  padding: 6px 0 0 0;
-  text-align: center;
-}
-
-.table-form .field-error {
-  background: #990000;
-  margin: 5px 0;
-  padding: 5px 0;
-}
-
-.table-form .field-error label,
-.table-form .field-error label .required {
-  color: #ffffff;
-}
-
-
-.table-form .field-error input {
-  background: #ffcccc;
-}
-
-.table-form ul.error-list {
-  clear: both;
-  display: block;
-  list-style: none;
-  margin: 0;
-  padding: 5px 0;
-  width: 100%;
-  color: #ffffff;
-}
-
-.table-form ul.error-list li {
-  display: block;
-  padding: 5px 10px 5px 50px;
-}
-
-#register .access {
-text-align:center;
-  padding: 20px;
-}
-
 a.link-button {
   padding: 4px;
   font-size: 10px;
--- a/web/thdProject/web/css/layout.css	Wed May 05 16:33:19 2010 +0200
+++ b/web/thdProject/web/css/layout.css	Thu May 06 23:49:04 2010 +0200
@@ -69,7 +69,8 @@
 #header-user .login {
 	clear: both;
   height: 113px;
-  padding: 0 20px;
+  width: 250px;
+  padding: 0 10px;
 }
 
 #header-user .register a {
@@ -83,6 +84,10 @@
 	background: transparent url("../images/layout/bg_login.png") repeat-x;
 }
 
+#header-user .login a.link-action {
+	color: #ffffff;
+}
+
 #header-user .login .head {
 	display: block;
   font-family: Georgia,"Times New Roman",Times,serif;
@@ -271,4 +276,16 @@
 }
 
 
+#register .access {
+  text-align:center;
+  padding: 20px;
+}
 
+#register form label {
+	display: block;
+	margin-bottom: 10px;
+}
+
+#register form .buttons {
+	padding: 20px 0 0 0;
+}
\ No newline at end of file