This is how I forced my users to use their email address as their username. It allows the user to make changes to their email address after registering but the username will never change.
Use PHPmySQL to set the email field to "Unique" (in the xcart_customers table)
Add the following code at the top of
include/register.php
(this will force all email addresses and usernames to be lowercase)
Quote:
$email = strtolower($email);
$uname = strtolower($email);
|
Add the following code to the bottom of /check_email_script.tpl
Quote:
{* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *}
{* COPY E-MAIL AS USERNAME MOD *}
{literal}
<script language="JavaScript1.2">
var uname = "";
function InitSaveVariables(form) {
uname = form.uname.value;
}
function copyemail(form) {
InitSaveVariables(form);
form.uname.value = form.email.value;
}
</script>
{/literal}
{* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *}
|
Find the code below in
/main/register_account.tpl and
add the below bolded javascript property to code below:
(whenever the user clicks on the "username" or "password" fields (when registering or updating info) the "username" field and "uname" variable get set to equal whatever is in the "email" field. This works pretty well. There is one small catch though, after registering if the user changes their email and clicks in the "password" field(s) the script will change the hidden "uname" variable to equal the new email address and will cause an access denied error upon submit because the script is trying to reset the username as well which is not allowed. If you're lazy you could just use the OnFocusOut javascript control only on the "uname" text fields.)
Quote:
{* Anonymous account *}
<tr>
<td align="right">{$lng.lbl_username}</td>
<td> </td>
<td nowrap="nowrap">
<input type="text" id="uname" name="uname" onFocusOut=javascript:copyemail(this.form); size="32" maxlength="32" value="{if $userinfo.uname}{$userinfo.uname}{else}{$userinfo. login}{/if}" />
{if ($reg_error ne "" and $userinfo.uname eq "" and $userinfo.login eq "") or $reg_error eq "U"}<font class="Star"><<</font>{/if}
</td>
</tr>
<tr>
<td align="right">{$lng.lbl_password}</td>
<td> </td>
<td nowrap="nowrap"><input type="password" name="passwd1" onFocus=javascript:copyemail(this.form); size="32" maxlength="64" value="{$userinfo.passwd1}" />
</td>
</tr>
<tr>
<td align="right">{$lng.lbl_confirm_password}</td>
<td> </td>
<td nowrap="nowrap"><input type="password" name="passwd2" onFocus=javascript:copyemail(this.form); size="32" maxlength="64" value="{$userinfo.passwd2}" />
</td>
</tr>
{* /Anonymous account *}
{* NOT anonymous account *}
<tr>
<td align="right">{$lng.lbl_username}</td>
<td class="Star">*</td>
<td nowrap="nowrap">
{if $userinfo.login ne "" || ($login eq $userinfo.uname && $login ne '')}
<b>{$userinfo.login|default:$userinfo.uname}</b>
<input type="hidden" name="uname" value="{$userinfo.login|default:$userinfo.uname}" />
{else}
<input type="text" id="uname" name="uname" onFocus=javascript:copyemail(this.form); size="32" maxlength="32" value="{if $userinfo.uname}{$userinfo.uname}{else}{$userinfo. login}{/if}" />
{if ($reg_error ne "" and $userinfo.uname eq "" and $userinfo.login eq "") or $reg_error eq "U"}<font class="Star"><<</font>{/if}
{/if}
</td>
</tr>
<tr>
<td align="right">{$lng.lbl_password}</td>
<td><font class="Star">*</font></td>
<td nowrap="nowrap"><input type="password" id="passwd1" name="passwd1" onFocus=javascript:copyemail(this.form); size="32" maxlength="64" value="{$userinfo.passwd1}" />
{if $reg_error ne "" and $userinfo.passwd1 eq ""}<font class="Star"><<</font>{/if}
</td>
</tr>
<tr>
<td align="right">{$lng.lbl_confirm_password}</td>
<td class="Star">*</td>
<td nowrap="nowrap"><input type="password" id="passwd2" name="passwd2" onFocus=javascript:copyemail(this.form); size="32" maxlength="64" value="{$userinfo.passwd2}" />
{if $reg_error ne "" and $userinfo.passwd2 eq ""}<font class="Star"><<</font>{/if}
</td>
</tr>
|