Page 1 of 1

Registered user ?

Posted: Mon Apr 05, 2010 4:31 am
by robgrigg
Hi,

I am using Anonymous checkout where a user can elect to enter a password or not.

After the onepage checkout, I am redirecting to a confirmation page rather than the receipt page.

On this page I want to be able to see if a user has or has not entered a password and will therefore be able to login again.

I have checked the following user parameters.

Order.User.IsAnonymous
Order.User.LastLoginDate
Order.User.Passwords.Count

in both scenarios the details are the same; the Order.User.IsAnonymous = false (?), Order.User.LastLoginDate = DateTime.Min and interestingly Order.User.Passwords.Count both = 1.

Please can you tell me how I distinguish between a user who has supplied a password and is therefore is registered and a user who is not.

Thanks.

Rob.

Re: Registered user ?

Posted: Mon Apr 05, 2010 6:48 am
by mazhar
Make sure that you redirected the user to confirmation page once every thing was done and order was placed. When user is not logged in and try to place order anonymously by providing password. In this case application creates order and then migrates the anonymous user with registered information after creating account. So make sure you are redirecting user to confirmation page after all this work. Finally instead of using order.User make use of Token.Instance.User.IsAnonymous and it will return you the current status of user who made recent checkout.

Re: Registered user ?

Posted: Wed Apr 07, 2010 6:56 am
by robgrigg
Thanks.

I redirect at the end of the on page checkout. I basically changes the Utility method to redirect to my page instead of the Receipt page.

You say Token.Instance..... Ho can I get hold of the Token class from within the code behind page?

Cheers.

Rob.

Re: Registered user ?

Posted: Wed Apr 07, 2010 7:09 am
by robgrigg
Hey,

I have tried this with this code in my confirmation page.

Code: Select all

            Label1.Text = "Order.User.IsAnonymous = " + Order.User.IsAnonymous.ToString();
            Label1.Text += "<br/>Token.Instance.User.IsAnonymous = " + Token.Instance.User.IsAnonymous.ToString();
The result is;
Order.User.IsAnonymous = False
Token.Instance.User.IsAnonymous = False

It looks to me that you pretend that the use is not anonymous in order to be directed to the receipt page, etc.

I could really do with some good advice here. If in this situation it does say isAnonymous = false then is there another way to find out is the user has actually supplied a password?

Cheers,

Rob.

Re: Registered user ?

Posted: Wed Apr 07, 2010 7:54 am
by mazhar
As you mentioned Token.Instance.User.IsAnonymous returns false. Its OK because if its returning false then it means that user is no more anonymous in other words an account is been created for user. The account creations requires to customer to fill the password field on checkout page. So this is a valid assumption that if IsAnoymous is false then customer has a valid user-name and password provided to application and has a account in system. So code on you custom page that will decide whether user has provided the password or not will be

Code: Select all

if(Token.Instance.User.IsAnonymous)
{
//USER DIDN'T PROVIDED THE PASSWORD FOR CHECKOUT 
}
else
{
//USER PROVIDED THE PASSWORD
}

Re: Registered user ?

Posted: Wed Apr 07, 2010 1:26 pm
by robgrigg
Mazhar

I am sorry, but this is not true.

In this instance I was not logged on, I click to say that i did not want to supply a password and this is the result I got.

Please can you help me. I am not stupid and I am definitly getting these result for a user which has not supplied a password.

Thanks.

Rob.

Re: Registered user ?

Posted: Wed Apr 07, 2010 2:39 pm
by robgrigg
Looking at the code in the one page check out, it creates a user with a dummy password and sets the forms authentication.
There is nothing in here that I can see to indicate that the user would be anonymous.

Code: Select all

            bool anonCheckout = false;
            if (trAccount.Visible)
            {
                //MIGRATE THE USER
                User oldUser = Token.Instance.User;
                string newUserName = oldUser.PrimaryAddress.Email;
                string newEmail = oldUser.PrimaryAddress.Email;
                string newPassword = NewUserPassword.Text;
                if (!CreateAccountPanel.Visible)
                {
                    anonCheckout = true;
                    newUserName = "zz_anonymous_" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                    newPassword = Guid.NewGuid().ToString("N");
                }
                MembershipCreateStatus createStatus;
                User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, Token.Instance.User.AffiliateId, out createStatus);
                //IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                if (createStatus == MembershipCreateStatus.Success)
                {
                    if (anonCheckout)
                    {
                        // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                        newUser.UserName = "zz_anonymous_" + newUser.UserId.ToString() + "@domain.xyz";
                        newUser.Save();
                    }
                    User.Migrate(oldUser, newUser, true);
                    Token.Instance.InitUserContext(newUser);
                    FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                }
            }
Please can you explan how this code would create an anonymous user or if the code is wrong, then how best to fix it.

Thanks

Re: Registered user ?

Posted: Thu Apr 08, 2010 8:32 am
by robgrigg
Please can you help.

This is the second thread I have created on this subject an I get the same response, it goes dead. This is a problem for me and if I am not told otherwise I must assume it is a bug in the system.

Please can you help.

Thanks

Rob.

Re: Registered user ?

Posted: Thu Apr 08, 2010 9:36 am
by mazhar
Hello Rob, just looked into more details. You seems to be right that it returns false in both cases. Actually we are creating a a user even with an anonymous checkout in order to support certain things. For example immediately after checkout we need to send the user to his/her order page and its only possible if they have an account. The only difference between a user created and automatically created user account is the user name. For anonymous users it has a user name started with zz_anonymous_. So try following code to determine either user is anonymous or has provide password to create account.

Code: Select all

if (!Token.Instance.User.IsAnonymous)
        {
            if (Token.Instance.User.LoweredUserName.StartsWith("zz_anonymous_"))
            {
                //IS ANONYMOUS USER AND DIDN'T PROVIDED THE PASSWORD UPON CHECKOUT
                Response.Write("Anonymous User");
            }
            else
            {
                //REGISTERED AND PROVIDED THE PASSWORD UPON CHECKOUT
                Response.Write("Registered User");
            }
        }
        else
        {
            //IS ANONYMOUS USER AND DIDN'T PROVIDED THE PASSWORD UPON CHECKOUT
            Response.Write("Anonymous User");
        }

Re: Registered user ?

Posted: Thu Apr 08, 2010 12:36 pm
by robgrigg
Thanks Mazhar, this makes sense.

As a feature request, would it be possible in the future to distinguish this in your code and maybe offer a user.IsRegistered boolean?

Cheers,

Rob.