Espai dels administradors: Diferència entre les revisions

De Gwiki
Dreceres ràpides: navegació, cerca
(Retocs en el programa)
Línia 98: Línia 98:
 
       </td>
 
       </td>
 
     </tr>
 
     </tr>
 +
</pre>
 +
 +
* Retocar home.php
 +
** Després de la funció sortir afegir la funció següent
 +
<pre>
 +
  function sortirg(idprofessors) {
 +
  var url = './ctrl_prof/ctrl_prof_reg_out_home.php';
 +
 +
  if (idprofessors == 0) {
 +
location.href = './logout.php?google=1';
 +
}
 +
  else {
 +
$.messager.confirm('Confirmar','VOLS SORTIR DE GASSIST I GOOGLE?',function(r){ 
 +
if (r){
 +
      location.href = './logout.php?google=1';
 +
}
 +
});
 +
}
 +
      }
 +
</pre>
 +
 +
Després de la línia td amb l'icon_key.png substituir
 +
 +
<pre>
 +
    <td valign="top" align="right" width="40">
 +
    <a href="javascript:void(0)" title="Sortir del sistema" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
 +
    <img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a>
 +
    &nbsp;
 +
    </td>
 +
</pre>
 +
 +
per
 +
 +
<pre>
 +
  <?php
 +
  if (isset($_SESSION['access_token']) && $_SESSION['access_token'])
 +
{
 +
        ?>
 +
<td valign="top" align="right" width="40">
 +
<a href="javascript:void(0)" title="Sortir de Gassist" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
 +
<img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a>&nbsp;
 +
</td>
 +
<td valign="top" align="right" width="40"> 
 +
<a href="javascript:void(0)" title="Sortir de Gassist i Google" onClick="sortirg(<?=$idprofessors?>)" class="easyui-tooltip">
 +
<img src="./images/icons/icon_exit_red_G.png" width="35" height="35" border="0"></a>&nbsp;
 +
</td>
 +
<?php
 +
}
 +
  else
 +
{
 +
?>
 +
<td valign="top" align="right" width="40">
 +
        <a href="javascript:void(0)" title="Sortir del sistema" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
 +
<img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a>
 +
&nbsp;
 +
</td>
 +
<?php } ?>
 
</pre>
 
</pre>

Revisió de 10:35, 30 abr 2016

Login amb Google a Gassist

Per poder habilitar el login amb google a Gassist hem hagut de seguir els següents passos

Alta a la console developers

Hem de tenir un compte de google per poder-hi accedir

  • Hem de donar d'alta un projecte. En podem crear múltiples.
  • Durant el procés s'haurà de demostrar que som l'administrador del domini vinculat. Planteja diferents formes de demostrar-ho en funció dels diferents nivells d'accés que tinguem al hosting/servidor/domini
  • Una vegada donat d'alta crear unes credencials. Una vegada creades les credencials, clicant a sobre ens dóna una informació que ens farà falta en la gestió de login via google: un id de client, una password secreta, i haurem de completar la URI de redireccionament autoritzat que ha de contenir el fitxer al que cridarà goolgle quan ja hagi validat , o no, l'usuari.

Retocs en el programa

  • Afegir mod_login_google a la base de dades. Per defecte, 0
  • Afegir la carpeta google
  • Afegir login_google.php.
    • Recordar de treure la informació de l'id, secret key i URI de retorn
    • Personalitzar l'adreça de retorn
  • Traspassar la imatge amb el logo de logout amb la "G" de google
  • retocar index.php
    • Afegir a partir de la línia 12
        require_once ('./google/libraries/Google/autoload.php');

	//Insert your cient ID and secret 
	//You can get it from : https://console.developers.google.com/
	$client_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; 
	$client_secret = 'XXXXXXXXXXXXXXXXXXXXXXX';
	$redirect_uri = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
        $hosting        = XXXXXX; 

	//incase of logout request, just unset the session var
	if (isset($_GET['logout'])) {
	  unset($_SESSION['access_token']);
	}

	/************************************************
	  Make an API request on behalf of a user. In
	  this case we need to have a valid OAuth 2.0
	  token for the user, so we need to send them
	  through a login flow. To do this we need some
	  information from our API console project.
	 ************************************************/
	$client = new Google_Client();
	$client->setClientId($client_id);
	$client->setClientSecret($client_secret);
	$client->setRedirectUri($redirect_uri);
	$client->addScope("email");
	$client->addScope("profile");

	/************************************************
	  When we create the service here, we pass the
	  client to it. The client then queries the service
	  for the required scopes, and uses that when
	  generating the authentication URL later.
	 ************************************************/
	$service = new Google_Service_Oauth2($client);

	/************************************************
	  If we have a code back from the OAuth 2.0 flow,
	  we need to exchange that with the authenticate()
	  function. We store the resultant access token
	  bundle in the session, and redirect to ourself.
	*/
	  
	if (isset($_GET['code'])) {
	  $client->authenticate($_GET['code']);
	  $_SESSION['access_token'] = $client->getAccessToken();
	  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
	  exit;
	}

	/************************************************
	  If we have an access token, we can make
	  requests, else we generate an authentication URL.
	 ************************************************/
	if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
	  $client->setAccessToken($_SESSION['access_token']);
	  
	} else {
	  $authUrl = $client->createAuthUrl();
	 }

    • Abans de la tr de captcha afegir aquestes línies
   <tr>
      <td> </td> 
      <td align="left">
      <?php	
      $modul_login_google = getModulsActius()->mod_login_google;
      if ($modul_login_google)
          {						
	  if (isset($authUrl)){ echo '<a class="login" href="' . $authUrl . '"><img src="./google/images/google-login-button.png" /></a>';}                
	  }
      else
	  {
	  print( '<img src="./google/images/google-login-button.png" />');
	  }
       ?>
       </td>
    </tr>
  • Retocar home.php
    • Després de la funció sortir afegir la funció següent
   function sortirg(idprofessors) {
   var url = './ctrl_prof/ctrl_prof_reg_out_home.php';
			
   if (idprofessors == 0) {
	location.href = './logout.php?google=1'; 
	}
   else {
	$.messager.confirm('Confirmar','VOLS SORTIR DE GASSIST I GOOGLE?',function(r){  
	if (r){
   	     location.href = './logout.php?google=1';
	}
	});
	}
       }

Després de la línia td amb l'icon_key.png substituir

    <td valign="top" align="right" width="40">
    <a href="javascript:void(0)" title="Sortir del sistema" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
    <img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a>
     
    </td>

per

   <?php
   if (isset($_SESSION['access_token']) && $_SESSION['access_token']) 
	{
        ?>	
	<td valign="top" align="right" width="40">
	<a href="javascript:void(0)" title="Sortir de Gassist" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
	<img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a> 
	</td>
	<td valign="top" align="right" width="40">   
	<a href="javascript:void(0)" title="Sortir de Gassist i Google" onClick="sortirg(<?=$idprofessors?>)" class="easyui-tooltip">
	<img src="./images/icons/icon_exit_red_G.png" width="35" height="35" border="0"></a> 
	</td>
	<?php
	}
   else
	{
	?>			
	<td valign="top" align="right" width="40">
        <a href="javascript:void(0)" title="Sortir del sistema" onClick="sortir(<?=$idprofessors?>)" class="easyui-tooltip">
	<img src="./images/icons/icon_exit_red.png" width="35" height="35" border="0"></a>
	 
	</td>				
	<?php	} ?>