X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Use E-mail address instead of username 3.5.x & 4.0 (https://forum.x-cart.com/showthread.php?t=8809)

x-light 07-01-2005 11:48 AM

Hey,


Quote:

passing to 4.0.14 any code changes? icon_sad.gif
updated and all my custom work fly away closed to shop to fix them out icon_sad.gif

for example register.php in root is different on 4.0.14 icon_sad.gif

Sorry to hear that you are having trouble. I hoped you made a backup before applying this mod. As I indicated in your pm, this mod is only tested for 4.0.13 and NOT for 4.0.14. I guess there are some differences in the register code which may make this mod incompatible. Anyway, I will send you another pm regarding this.

Now, as promised, I will post the updated code tested with 4.0.13 below. There was a bug in the dupliate email check when doing an update in the include/register. It is fixed in the updated code. I also will post some changes to templates such as recover password, profile modified etc... to show the email address instead of the auto generated username id. Hopefully, this update should be the last one as I have tested it extensively with 4.0.13. If you find any problems, please let me know. Thanks.

--- /include/register.php v3.mod2
Code:

# mod2
# find original code snippet
        if (!(@$uerror || @$eerror || @$fillerror || @$error)) {
#
# Fields filled without errors. User registered successfully
#
                $crypted = addslashes(text_crypt($passwd1));
# end original code snippet

# replace modified code snippet
# mod.use.email.rather.username
    if(!$fillerror) {

        # check if email already exist in customers table
        $email = strtolower($email);
        $email_on_record = func_query_first_cell("select email from $sql_tbl[customers] where email='$email'");
        if( $email == $email_on_record) {
                # duplicate email not allowed
                $eerror = true;
        }

        # exception checks to this rule
        if( $mode != "update") {
            # check if this is anonymous registration during checkout
            if( $eerror && func_query_first_cell("select status from $sql_tbl[customers] where email='$email' and usertype='C'") == 'A' ) {
                # delete this record since the user is anonymous requesting the same email
                # we can't assume that the email belongs to the user, but at least this way
                # the original user can use his/her same email to register again anonymously during another checkout
                # if an anonymous user already placed an order with this email, it will not effect the order information
                # since it is a seperate record in the orders table
                # note, if the user is already registered, we will never allow to automatically delete the registered user's record
                db_query("DELETE FROM $sql_tbl[customers] WHERE login LIKE '$like_anonymous_username_prefix' AND email='$email' AND usertype='C' AND status='A'");
                # this is not an error since we have deleted this record
                $eerror = false;
            }
        }
        else {
        // update mode
            if( $email == func_query_first_cell("select email from $sql_tbl[customers] where login='$login'")) {
                # email match, user did not change email
                $eupdate = false;
                # this is not an error since the existing email belong to this user
                $eerror = false;
            }
            else {
                # email does not match, see if new requested email is taken (duplicate email check above)
                if( !$eerror )
                    $eupdate = true;
            }
        }
        } // mod.use.email.rather.username

        if (!(@$uerror || @$eerror || @$fillerror || @$error)) {
#
# Fields filled without errors. User registered successfully
#
                $crypted = addslashes(text_crypt($passwd1));

# end modified code snippet

--- /include/help.php
Code:

# find original code snippet
#
# Recover password
#
if ($REQUEST_METHOD=="POST" and $action=="recover_password") {
$accounts = func_query("select login, password, usertype from $sql_tbl[customers] where email='$email' and status='Y'");

# end original code snippet

# replace modified code snippet
#
# Recover password
#
if ($REQUEST_METHOD=="POST" and $action=="recover_password") {
# mod.use.email.rather.username, replace login with email into accounts
$accounts = func_query("select email, password, usertype from $sql_tbl[customers] where email='$email' and status='Y'");
# end modified code snippet

--- /skin1/help/contactus.tpl
Code:

{* find original code snippet *}
<TR valign="middle">
<TD class="FormButton">{$lng.lbl_username}</TD>
<TD></TD>
<TD nowrap>
<INPUT type="text" id="uname" name="uname" size="32" maxlength="32" value="{$userinfo.login}">
</TD>
</TR>
{* end original code snippet *}

{* replace modified code snippet *}
{* mod.use.email.rather.username, username not needed anymore *}
{if 0}
<TR valign="middle">
<TD class="FormButton">{$lng.lbl_username}</TD>
<TD></TD>
<TD nowrap>
<INPUT type="text" id="uname" name="uname" size="32" maxlength="32" value="{$userinfo.login}">
</TD>
</TR>
{/if}
{* end modified code snippet *}

* Note: You can delete the code inside the {if 0}{/if} block since smarty will never execute it.  It is there for reference only.

--- /skin1/mail/html
Code:

{* find original code snippet *}
<TD><TT>{$accounts[acc_num].login}</TT></TD>
{* end original code snippet *}

{* replace modified code snippet *}
{* mod.use.email.rather.username, show email instead *}
<TD><TT>{$accounts[acc_num].email}</TT></TD>
{* end modified code snippet *}

--- /skin1/mail/html/profile_data.tpl
Code:

{* find original code snippet *}
<TD width="80%"><TT>{$userinfo.login}</TT></TD>
{* end original code snippet *}

{* replace modified code snippet *}
{* mod.use.email.rather.username, show email instead *}
<TD width="80%"><TT>{$userinfo.email}</TT></TD>
{* end modified code snippet *}


------- The following changes below are completely optional. It changes the s the username to email for order export on regular csv or quickbooks. Just follow the instructions in the comment to make the change to the file.
--- /skin1/main/orders_export.tpl
{* mod.use.email.rather.username, replaced all $orders[oid].login with $orders[oid].email *}
--- /skin1/modules/QuickBooks/orders_export_qb.tpl
{* mod.use.email.rather.username, replaced all $orders[oid].login with $orders[oid].email *}

~x-light

jw 07-17-2005 08:24 AM

I'm using this with 4.0.14 and it works great! Thanks x-light.

Quote:

passing to 4.0.14 any code changes?
updated and all my custom work fly away closed to shop to fix them out

for example register.php in root is different on 4.0.14

2019, this works with 4.0.14. Just start with the changes at the beginning of this thread and work through them. If you get errors chances are you've missed something.

Quote:

--- /skin1/mail/html
Code:
should of course be --- /skin1/mail/html/password_recover.tpl.

Quote:

OK, so what happens when the user changes their email address? I think a user name is a far simpler approach. Also easier to log in with.

The Amazon way is simple. The user can change their e-mail address by logging in and supplying their old address, new address and password. A confirmation is then sent to the new address. I'm working on this and will post is as soon as I'm done.

Jeff

coeus 07-17-2005 10:02 PM

...
 
Nice mod!

xgarb 10-04-2005 04:23 AM

My simple way of doing this (appears to work so far)

In /main/register_account.tpl

change

Code:

<TR>
<TD align="right">{$lng.lbl_username}</TD>
<TD></TD>
<TD nowrap>
<INPUT type="text" name="uname" size="32" maxlength="32" value="{$userinfo.login}">
</TD>
</TR>



to

Code:

<TR>
<TD align="right">{$lng.lbl_username}</TD>
<TD></TD>
<TD nowrap>
<INPUT type="text" name="uname" size="32" maxlength="32" value="{$userinfo.login}" onchange="javascript: checkEmailAddress(this);">
{if $fillerror ne "" and $userinfo.email eq "" && $default_fields.email.required eq 'Y'}<FONT class="Star">&lt;&lt;</FONT>{/if}
</TD>
</TR>


You should also change the string for $lng.lbl_username to something like 'Email Address'. Easiest to do in webmaster mode I find.

This forces the user (using javascript) to put in an email address as their username.

HTH

xgarb

flyingsaucer 10-16-2005 08:39 PM

this is far simpler approach
 
I think this way it makes it easier as well to upgrade since not sql changes or any php changes required.

I was thinking of doing something similar too, like showing the user the email field and password field only and once they enter the email , then copy that info to the username field in a hidden way before saving to database.

And their username and email address will be identical. That way the rest of the x-cart features will still work normally. However I am not very good at making these kind of changes.

Can anyone help me on that.

Hide username field, show email field and copy email entered to hidden username field bfore writing to database.

thanks

hyratech 12-13-2005 09:38 PM

I tried x-light's MOD on 4.0.17 .. I didn't wort.. i got all sort of errors.. can someone varify? is it me? Did i make a mistake somewhere.. or this is not compatible with my version

B00MER 01-11-2006 11:08 AM

Just updating my original post for 4.0.16+:

The $user_data query is different in my original post in include/login.php, look for this code now:
Code:

$user_data = func_query_first("SELECT * FROM $sql_tbl[customers] WHERE login='$username' AND usertype='$usertype' AND status='Y'");

Replace with:

Code:

$user_data = func_query_first("SELECT * FROM $sql_tbl[customers] WHERE (login='$username' or email='$username') AND usertype='$usertype' AND status='Y'");

Since this is such a minimal php change, patch tools *SHOULD* be able to update this line without much trouble. Keep in mind Upgrade kits also upgrade template .tpl files as well. :wink:

electronics4less 02-01-2006 01:50 PM

Any successes on X-light's mod on 4.0.9?

electronics4less 02-05-2006 02:12 PM

Works great in 4.0.9, X-light VERY NICE WORK! Thanks!

mukunig 02-13-2006 12:40 PM

Does this work with 4.0.13 pro?

Thanks,
Greg
x-cart pro 4.0.13 heavily modified


All times are GMT -8. The time now is 04:11 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.