This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » login_handler not run if the user...
expandshrink

login_handler not run if the user already exists

login_handler not run if the user already exists

Tuesday 20 August 2013 12:01:09 pm - 1 reply

Hello everyone.
I use a login_handler on my site to identify users who already have an account on another site.
I board not a problem during the first connection. But if a user wants to reconnect latest login_handler is 'forgotten'.

Example:

  1. Bob want to connect.
  2. He never went to the site.
  3. It already has an account on the remote site.
  4. He entered his login / password
  5. The login_handler capture the connection
  6. The login_handler doing his job
  7. The eZ login_handler creates a new user account for
  8. The login_handler connect the new user
  9. Bob Logged Out.
  10. Bob reconnect.
  11. The login_handler is not used! Bob finds himself connected while his account may have been deleted from the remote site.

My code:

<?php
class eZExtranetUser extends eZUser 
{

static function loginUser($login, $password, $authenticationMatch = false) 

{

if (!$login || !$password) {        return false;     }    

$out = WS_CONNEXION::connect($login, $password);            

$user_data = json_decode($out); 

 

/* $user_data :  object(stdClass) {

                    ["username"]=> "bob"

                    ["email"]=> "bob@bob.bob"

                    ["id"]=> "2538"

 }                */               

 

$login = $user_data->username;               

$email = $user_data->email;               

$id = $user_data->id;                       

 

$params = array();               

$params['creator_id'] = 78213; # Le user Connexion Système [connexion] 

$params['class_identifier'] = 'user';               

$params['remote_id'] = 'user_'.$id;               

$params['parent_node_id'] = 78212; # Le dossier user               

$params['attributes'] = array(

                                'compte' => $login.'|'.$email.'|'.md5($password).'|md5_password|1',                                                );               

$currentUser = eZUser::fetchByName($login);               

if ( ! $currentUser) {                       

  $object = eZContentFunctions::createAndPublishObject($params);                       

  $currentUser = eZUser::fetch($object->ID);                   

}                

$userID = $currentUser->ContentObjectID;               

eZUser::updateLastVisit( $userID );               

eZUser::setCurrentlyLoggedInUser( $currentUser, $userID );               

return $currentUser;        

}

 

public function canLoginToSiteAccess( $siteaccess ) {        return $siteaccess === 'www';     }

 

}
?>

Modified on Tuesday 20 August 2013 12:04:39 pm by Rémy PHP

Tuesday 20 August 2013 12:56:08 pm

I got it!

The system tries to connect the user from the existing account before passing through the login_handler.
As I created the user account 100% FUNCTIONAL. (With the login and password.) ??The system logs on my user without going through the login_handler.
Out I did not need to save the password of my users.
I just need to put something like so:

 'compte' => $login.'|'.$email.'|'.md5(uniqid()).'|md5_password|1',

for login_handler work the way I want ^ ^

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from