One string solution

Jerimee - December 12, 2007 - 18:01
Project:OpenID
Version:5.x-1.0
Component:OpenID Client
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

When entering a Nickname that is already on the users table, OpenID login fails.

user warning: Duplicate entry 'Jerimee' for key 2 query: INSERT INTO users (name, mail, pass, status, uid, created) VALUES ('Jerimee', 'jrichir@ncdp.org', '56f3aaa02caa43f19253aadaf72ebb19', 1, 3, 1197482285) in /home/jerimeec/public_html/includes/database.mysql.inc on line 172.

No doubt I'm not the first person to discover this. Forgive me if I should have made this comment elsewhere.

#1

itman - March 13, 2008 - 06:38
Title:Duplicate User» Duplicate User (a comment for maintainer)

Pardon me for intruding. I almost certainly now the reason of this,'cause I was fighting this recently. In the following piece of code:

    $form = drupal_retrieve_form('user_register');
    $edit['name'] = <b>(empty($response['openid.sreg.nickname']))</b> ? $identity : $response['openid.sreg.nickname'];
    $edit['mail'] = (empty($response['openid.sreg.email'])) ? '' : $response['openid.sreg.email'];
    $edit['pass']  = user_password(

If you rely on a nickname, please, add check to see if this is free. Otherwise, I would change the line to the following:
$edit['name'] = $identity.

PS: after this error you should clean authmap table, e.g. in the following way
delete from authmap where uid = 0 and module = 'openid'
otherwise you won't be able use this openid identity anymore (with the current database)

#2

andol - April 17, 2008 - 00:35

Myself I applied this perhaps not so pretty solution.

<?php
function my_openid_nicktest($nick){

  if(!empty(
$nick)){
   
$result = db_query("SELECT uid FROM {users} WHERE name = '%s'", $nick);
    if(
db_num_rows($result)){
     
form_set_error('name', 'The nickname your OpenID provided is already in use.');
    }
  }

}
?>

The function is then used like this.

<?php
    drupal_prepare_form
('user_register', $form);
   
drupal_validate_form('user_register', $form);
   
my_openid_nicktest($edit['name']);
    if (
form_get_errors()) {
?>

#3

azerazer - May 31, 2008 - 18:54
Title:Duplicate User (a comment for maintainer)» One string solution

In
function openid_authentication($response) {
add 1 string before 'drupal_validate_form':

<?php
   drupal_prepare_form
('user_register', $form);

  
$_GET['q']=str_replace('authenticate','register',$_GET['q']);

  
drupal_validate_form('user_register', $form);



?>

 
 

Drupal is a registered trademark of Dries Buytaert.