Using old data for tokens

Crell - May 4, 2008 - 02:36
Project:Auto username
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

So I'm still not entirely certain about this one. It appears that when auto_username runs, its token module implementation for the profile module ends up pulling data before changes to the profile are saved. That results in a problem, not just because the data is stale but if the previous data would result in an empty or invalid username, then it becomes impossible to save a user account. Oopsies. :-)

I may just need to increase the module weight so that it runs after profile.module, but I'm not sure. It needs a bit of testing before I confirm that. (Anyone who wants to test it for me and submit a patch is welcome to do so! :-) )

#1

matt@antinomia - May 10, 2008 - 03:47

Hey Larry, I'm puzzled by this as well. I attempted increasing the module's weight (placing it before and after token) and the error persists in both cases. I took a quick look at the code but nothing struck me immediately...

#2

liquidcms - May 16, 2008 - 14:52

one of my clients needs this exact functionality - so i will likely fix this bug in the next couple days (or maybe even late today).

#3

liquidcms - May 16, 2008 - 22:41

i just tested this with my replacement pattern being:

[profile_contact_firstname-raw].[profile_contact_lastname-raw]

and the module seems to work fine :)

#4

Crell - May 16, 2008 - 23:57

The period makes it a valid username. Try a pattern of [profile_contact_firstname-raw][profile_contact_lastname-raw] when both of those fields WERE empty but are in the process of being set to something non-empty.

#5

liquidcms - May 19, 2008 - 16:53

i changed my rules to : [profile_contact_firstname-raw][profile_contact_lastname-raw]

and it still seems to work ok, except there are a few issues with this module (which i'll try to fix and perhaps raise sep issues for each).

- after creating user Peter3 Smith, i get user name of Peter3Smith (from above pattern)
- first time i log in as Peter3 and go to MyAccount, i get duplicate entry error; but can't seem to get it after that

- also, as admin if i resubmit edit page for this user (with now edits), i get url_alias changed from users/peter3smith to users/cfxyiqjaur
- maybe this is something we screw up with one of our modules??

#6

liquidcms - May 19, 2008 - 17:19

nope, oddly enough it is this module that causes user name aliases (pathauto/token) to get screwed up ONLY when the admin is editing the user.

#7

Crell - May 19, 2008 - 18:22

Ugh. pathauto is apparently hooking in before auto_username, and so is using the fake username that is created to make the form validate. damn damn damn. I'm not sure how to handle that properly. I think we need someone who knows both the user and form systems better than I do.

#8

liquidcms - May 19, 2008 - 19:43

the odd user alias was occuring because the AUN module (when admin) sets the user name to user_password() - i assume simply so that it will pass validation and, as it says, this will get corrected later - which it does.

but, i had pathatuo value set to: users/[user-raw] which occurs before the "fix" occurs and therefore ends up looking like user/password.

simply changing pathauto pattern for users to: users/[profile_contact_firstname-raw][profile_contact_lastname-raw] fixes this.

I'll try to see if i can find why duplicate entry warning shows up - although seems to not really impact anything.

#9

liquidcms - May 19, 2008 - 20:36

the reason i was getting duplicate key sql error is because i have the auto timezone module installed which resets the users TZ the first time they go to their account.

basically the reason is because they do a user_save() which then causes AUN's after_update op to run which at that point doesn't have a $new_name.

the attached patch fixes this.

re: #7; my solution is likely not the best - i simply modded pathauto user replacement to be:

users/[profile_contact_firstname-raw][profile_contact_lastname-raw]

rather than users/[user-raw] (should really be user not users but bug in pathauto .install setting that as default case)

best solution is to fix AUN so that the token isn't = password; i can take a quick look at this; but my work around is ok for my use.

AttachmentSize
auto_username-fix_after_update.patch 645 bytes

#10

liquidcms - May 21, 2008 - 21:36

even though we should be able to use user/[user] as a pattern for user aliases in pathauto - and aun breaks this; the workaround is simple; simply use same pattern as used in auto naming: user/[profile_contact_firstname-raw][profile_contact_lastname-raw]

BUT now that i added feature to exclude roles from aun; this workaround is somewhat useless - since they will still have path to profile changed even though their usenames won't be.

in other words; i will likely still end up seeing if i can fix this original bug even though i suggested i didnt really care since there was a workaround.

#11

Crell - May 21, 2008 - 21:39

OK, so, uh... What do you recommend to fix this? :-) It sounds like we're dealing with 2 separate issues here. Stale data and pathauto. They should probably be split into separate issues.

#12

liquidcms - May 22, 2008 - 08:18

yes, you are likely right.. i should post my 1 issue as a separate issue "[user] token no longer works for pathauto"

your original "stale data" issue i have never been able to duplicate.

the sql error i think i have fixed (which should also have been a separate issue - or maybe it is??)

and the new role exclusion i added; i did add as a separate issue..

as for solution to fix the 1 outstanding issue that i know of; not to sure. I think i mentioned to my client (the NY Times) that it might not be a bad idea to fix it; so i could spend some time and take a look. Maybe tomorrow; failing that, likely not until next week.

Peter Lindstrom
LiquidCMS - Content Management Solution Experts

#13

durum - December 24, 2008 - 15:58

Guys, why are you dealing with token module on the registeration screen? Can't you just do something like below when you validate the form?

<?php
if (isset($firstname) && isset($lastname)) {
 
//controls like mysql_escape_string($firstname) etc
 
$separator=".";
 
$username=$firstname.$separator.$lastname;
 
//then isert query...
}
?>

I mean get the firstname, get the lastname and concatenate them and just insert into the user table.

I haven't check the code

#14

Crell - December 25, 2008 - 03:56

The whole point of this module is to be able to configure that via the admin, not hard-code it in code. That's what the tokens are for.

#15

durum - December 25, 2008 - 04:09

Hmm. Bad problem. Good luck then..

#16

mdowsett - February 5, 2009 - 17:59

subscribing.

Such an old issue....is there no fix?

What the suggestion in #13? If it works, I'll gladly throw it in my code somewhere....but where is it to be placed?

thx!

#17

mdowsett - February 5, 2009 - 18:05

hey...wait a second....as another 'work-around' can tokens be used in the User Settings (/admin/user/settings) to change the "!username" token to use the profile first and last name fields?

What would be the format to put in those emails? is it the same as in pathauto? (in my case "[profile_fname-raw]_[profile_lname-raw]")

It isn't a real fix since you'd have to adjust it on each site you do due to the profile fields being custom on every site...but whatever works....

I'll try it....stay tuned

#18

mdowsett - February 5, 2009 - 18:28

nope....I tried both:

[profile_fname-raw]_[profile_lname-raw]

and

!profile_fname-raw !profile_lname-raw

And neither worked (it just sent that text in the emails)

#19

durum - February 6, 2009 - 15:19

For emails, Realname may work.

#20

mdowsett - February 6, 2009 - 20:40

I think that worked like a charm.

It still showed the user name in the welcome emails (which isn't so bad since poeple actually pick them in their registration)...or can I change the !username token in the welcome emails to !realname now?

#21

mdowsett - February 6, 2009 - 20:41

I see the user variables in the user emails aren't the same as tokens....is there a way to manually add more user variables?

#22

durum - February 16, 2009 - 18:36

or can I change the !username token in the welcome emails to !realname now?

You should be. Just play with the options.

As far as I remember, you should identify the fields you create with the core Profile module as real first name and real last name in the module options. Then it goes.

#23

kenorb - February 25, 2009 - 15:22

I'm using email_registration and I've similar problem described here: #383428: Link to user homepage contain a password
Check if your problem and solution isn't similar to this one:
http://drupal.org/node/383428#comment-1290370

#24

davidlerin - March 2, 2009 - 04:27

Subscribing.

#25

pankajshr_jpr - March 29, 2009 - 16:56

Hey such an old issue and haven't fixed uptil now ? i also need it ,is there anyone who cud fix it please?.

#26

Crell - March 30, 2009 - 15:20

It hasn't been fixed because I've not figured out a fix and no one else has submitted a patch that fixes it. If you want it fixed, submit a patch to fix it. :-) I don't have the time at the moment to dig into this myself.

#27

pankajshr_jpr - April 10, 2009 - 07:19

I am a newbie to drupal, cant able to fix the issue right now. Nobody here to fix it ?

#28

Berdir - July 22, 2009 - 18:06
Status:active» needs review

The attached patch might not be perfect, but it seems to work for me.

It does the following things...

- merge $edit and $account data to use the updated + existing information to build the username.
- Only change the username if necessary (built username is not equal the current and not empty). The non-empty check is especially important when used in conjunction with user_import (http://drupal.org/project/user_import), because that does not add profile fields to the $user object before saving, so they might not be available.

AttachmentSize
old_data_fix.patch 1.73 KB
 
 

Drupal is a registered trademark of Dries Buytaert.