Topic-icon Email as a username

Active Subscriptions:

None
12 years 1 month ago #20455 by jwhelan
Email as a username was created by jwhelan
I'm a new user of jLinked and very pleased so far. So, Thanks!

I'd like the registration process for my application to use a user's email address as their username. i.e. on the user registration form, I'd like to remove the 'Username' field and just use the user's email address as a username for future login purposes. Is there an easy way to do this?

Thanks!

-John W.
The topic has been locked.
Support Specialist
12 years 1 month ago #20480 by alzander
Replied by alzander on topic Email as a username
John,
Yup, should be pretty easy. You'll need to make minor modification to 2 files:

In the /components/com_jlinked/views/loginregister/view.html.php, around line 44, you'll see:
// Setup the fields we can pre-populate
            // To do: Give option to show/hide the name on the form
            $this->form->setValue('name', null, $profile->get('first-name') . " " . $profile->get('last-name'));
Add the following line after that:
$this->form->setFieldAttribute('username', 'type', 'hidden');

Then, in the /components/com_jlinked/controllers/loginregister file, around line 54, you'll see:
$username = JRequest::getVar('username', '', 'POST', 'username');
Change that line to:
$username = JRequest::getVar('email', '', 'POST', 'string');

That should do it for you. I didn't test it, but it's pretty straightforward. Definitely test and let us know if you run into any issues!

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 1 month ago #20623 by purplechris
Replied by purplechris on topic Email as a username

alzander wrote: $username = JRequest::getVar('username', '', 'POST', 'username');

i tried this but couldnt find

$username = JRequest::getVar('username', '', 'POST', 'username');

in the second file you mention as i also want to do this
The topic has been locked.
Support Specialist
12 years 1 month ago #20624 by alzander
Replied by alzander on topic Email as a username
And you wouldn't.. because I'm a big liar :) That specific instruction is actually for the Joomla 1.5 version. For Joomla 2.5, you need to do something a little different.

Please open the /components/com_jlinked/models/loginregister.php file. At about line 39, you'll see:
$data['password'] = $data['password1'];
Add the following line directly after that:
$data['username'] = $data['email'];

Again, this is untested, but pretty straightforward. Should work without issue, but your feedback is definitely appreciated.

Sorry for the confusion, and good luck!
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 1 month ago #20636 by purplechris
Replied by purplechris on topic Email as a username
that does remove the field but then you cannot click on the register button for some reason it then doesnt work? lol
The topic has been locked.
Support Specialist
12 years 1 month ago #20671 by alzander
Replied by alzander on topic Email as a username
Thanks for pointing that out, and sorry for the trouble. The code I did above was from looking at the flow, and not actually testing. It's not always possible to test every code change (and usually not necessary for seemingly simple stuff).

I went through and developed and tested how to do this, fixing the issue you mention and finding another that you would have run into right after. Below is all the code changes that need to be done in Joomla 2.5 to make this work.

In the /components/com_jlinked/views/loginregister/view.html.php, around line 44, you'll see:
// Setup the fields we can pre-populate 
            // To do: Give option to show/hide the name on the form 
            $this->form->setValue('name', null, $profile->get('first-name') . " " . $profile->get('last-name'));
Add the following line after that the following 2 lines (above I mentioned only the first):
$this->form->setFieldAttribute('username', 'type', 'hidden');
            $this->form->setFieldAttribute('username', 'class', 'non-required');

Then, in the /components/com_jlinked/controllers/loginregister file, around line 60, you'll see:
$userModel = JModel::getInstance('Registration', 'UsersModel');
            $requestData = JRequest::getVar('jform', array(), 'post', 'array');
Add the following line directly after that:
$requestData['username'] = $requestData['email1'];


If you followed all the steps in the threads above, please undo the change I mentioned in the /com_jlinked/models/loginregister.php file. That's unnecessary.

This has been tested on our development systems, but not for every possible JLinked setting or with the profile plugins. Nothing should affect it, but obviously, do your own testing :)

Please let us know how it goes!
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 1 month ago #20674 by jwhelan
Replied by jwhelan on topic Email as a username
Thanks for this Alzander. I will try this on my application and report back...
The topic has been locked.
Active Subscriptions:

None
12 years 1 month ago #20678 by purplechris
Replied by purplechris on topic Email as a username
perfection on joomla 2.5 just need to figure it out for jfacebook now
The topic has been locked.
Support Specialist
12 years 1 month ago #20687 by alzander
Replied by alzander on topic Email as a username
purplechris,
Very glad to hear it. I'll try to get back to the JFBConnect post in the next day or so. The changes will be pretty much identical, but I understand if you don't want to go snooping :D

jwhelan,
Keep me posted if you run into issues. Hopefully you shouldn't, but we're here if you do.

Finally, if you haven't already, please consider leaving a rating and review for JLinked, or our support, on the Joomla Extension Directory:
extensions.joomla.org/extensions/access-...on-cloud-based/18957

Best of luck,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 1 month ago #20699 by jwhelan
Replied by jwhelan on topic Email as a username
Alex,

Made the changes you suggested and they seem to work great. One other question:

When a new user tries to 'login with LinkedIn' they are then prompted to either a) link an existing account, or b) register a new account. How would I disable option a) as I'd like to force all my users to login via linked in and immediately register for a Joomla account on my application. Then in the future, they would just login with jLinked as a matter of course. I suspect this is an easy tweak, but I'm not sure which file controls this part of the login/register process.

-JW
The topic has been locked.