Jump to content

Users system name field


antpre
 Share

Recommended Posts

Hy there,

This question will certainly sound stupid. Sorry for that.

Regarding user and the name field of the user template.

I understand that we cannot have users with the same name (meaning system name field).

I am working on an e-learning site and people could have the same name. How to handle that ?

The probleme : So far I used the user the system field 'name' for the name and an other custom field for the given name.

Here the chance that 2 users have the same name is not negligeable. And the second to register will not be able to register with his name.

the solution I see :

Like in the back end in case the name already exist add an incremental digit after the name. But that's not realy cool cause the user will not see his exact name..

An other solution I see is two have two custom fiels one for family name and an other one for given name. Thereafter I can concatenate the two values to feed the system field 'name'. their I can still implement the control mentionned above but the chance that two users have the same name is much less.

These users  will only acces the site through the front end and therefore will use a custom login form.

I am sure that there is some best practice on how to handle this.

thanks in advance.

Link to comment
Share on other sites

Should it be possible for the users to register themself via front end? If so, the users could be told that the username they have selected has already been taken and they should register with another one. Then it's up to them to find something what they like.

I guess you already have found some information how to build custom login forms, but just in case you didn't: https://processwire.com/talk/topic/107-custom-login/

Link to comment
Share on other sites

When you create users (or any page) via the API, you can pass an option called 'adjustName' and set its value to true.
 

'adjustName' => boolean - Adjust page name to ensure it is unique within its parent (default=false)


For example, create a page with a name value based on their supplied full name (like others, I would store that in a title field):

$u = new User();
$u->name = $this->sanitizer->pageName($this->input->post->full_name, true);
$u->title = $this->sanitizer->text($this->input->post->full_name);
// ... and other fields
$u->save(array('adjustName' => true));

I agree with Martijn Geerts though, allowing (or forcing) users to log in with their email address is good. But user account pages still need names, and if you're not going to generate them randomly and instead use supplied information, then you will need to account for duplicates.

Link to comment
Share on other sites

Thanks to all for your answers.
I think I will follow Martin's advice of having the users log-in with their email. I won't show them their user page name.

I can create the name programmatically or I can use the adjustName option. If the users don't see the name... they won't care ;-)

Have a great day

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...