how to display user name or email after login: solved

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
tonz
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 48
Joined: Thu Mar 13, 2008 4:08 am

how to display user name or email after login: solved

Post by tonz » Tue Oct 14, 2008 4:20 am

Does anybody know how to display the user name or email of a logged in user? So that the customer could see that he is logged in as Mr. X?

Thanks,

Tony
shop.faxproducts.com
shop.blackice.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to display user name or email after login

Post by mazhar » Tue Oct 14, 2008 5:17 am

You can display the Email as

Code: Select all

Token.Instance.User.UserName
and the user first name as bello

Code: Select all

Token.Instance.User.PrimaryAddress.FirstName
Also note that FirstName may be empty depending that user does not specify his first name in primary address.

User avatar
tonz
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 48
Joined: Thu Mar 13, 2008 4:08 am

Re: how to display user name or email after login

Post by tonz » Tue Oct 14, 2008 6:11 am

Thanks for the tip. I think I will use the email because of the fact you mentioned that first name might not be available.

Token.Instance.User.UserName

How shall I call this, can you help with the syntax?

Thanks a lot,

Tony

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to display user name or email after login

Post by mazhar » Tue Oct 14, 2008 6:37 am

Better create a user control in ConLib. Create a file UserInfo.ascx in the ConLib folder and place the following contents in it.

Code: Select all

<%@ Control Language="C#" ClassName="UserInfo" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Token.Instance.User.IsAnonymous)
        {
            UserNameLabel.Text = Token.Instance.User.UserName;
        }
    }
</script>
<asp:Label ID="UserNameLabel" runat="server" Text="Label"></asp:Label>
and then place it where ever you want to show the Email info. For example in the header scriptlet as below.

Code: Select all

[[ConLib:UserInfo]]
Last edited by mazhar on Mon Oct 20, 2008 10:41 am, edited 1 time in total.

User avatar
tonz
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 48
Joined: Thu Mar 13, 2008 4:08 am

Re: how to display user name or email after login

Post by tonz » Tue Oct 14, 2008 9:25 am

Thanks it worked great! I added an if statement to check if the user is logged in or not, otherwise the control appeared with some cookie data instead of an email.

#if($customer.IsAnonymous)
#else
[[ConLib:Custom/UserInfo]]
#end

Thanks again,

Tony

User avatar
Road Rider
Commander (CMDR)
Commander (CMDR)
Posts: 144
Joined: Sat Jan 26, 2008 12:43 pm
Contact:

Re: how to display user name or email after login: solved

Post by Road Rider » Wed Oct 15, 2008 11:36 am

This is what I use in my header:

Logged in as: #if($User.IsAnonymous)You are not logged in #else $User.Username #end


Simple and elegant.
Doug Morrison
Director of Marketing and eCommerce
Bike Authority
http://www.bikeauthority.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to display user name or email after login: solved

Post by mazhar » Wed Oct 15, 2008 12:23 pm

Better use the current version of the above control. I have modified the control to handle the anonymous user case.

User avatar
Road Rider
Commander (CMDR)
Commander (CMDR)
Posts: 144
Joined: Sat Jan 26, 2008 12:43 pm
Contact:

Re: how to display user name or email after login: solved

Post by Road Rider » Wed Oct 15, 2008 6:58 pm

What? They both handle it.
Doug Morrison
Director of Marketing and eCommerce
Bike Authority
http://www.bikeauthority.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to display user name or email after login: solved

Post by mazhar » Thu Oct 16, 2008 4:54 am

I am taking about this newly added statement

Code: Select all

if(!Token.Instance.User.IsAnonymous)
{
//          
}
When first I posted the code i missed that line.

Post Reply