Way to find out if a user is logged in the system

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Is there a property that can be used to find out if a user is authenticated in the catalog controller?
11 years ago
Use Customer.IsRegistered() extension method.
11 years ago
Thanks for replying back. The way you are suggesting is to see if a user is registered with the system. I want to know if there is a way to find a way a user is logged in or not.
11 years ago
I was looking at the _authenticationService for my problem. In that service there is a method GetAuthenticationCustomer(). Which customer does it return because at any moment a number of users can be logged in so which customer will be returned by that method.
11 years ago
Use IsRegistered on the logged customer, you'll know if its a guest or registered.
11 years ago
Isn't that just going to give me if a user has an account in the system and not if a user is logged in because I want to know if a user is logged in the system???
11 years ago
IAuthenticationService.GetAuthenticatedCustomer gets a customer using the forms authentication ticket (if it exists) data - email or username - and returns it. There's one instance of the service per http request, so for each request, it references the current person navigating.

IWorkContext.CurrentCustomer returns the current customer (guest, authenticated user or impersonated user). If you call IsRegistered on this customer, you ensure you're not dealing with a guest customer. You either have an authenticated customer or an impersonated customer. So depending on your scenario you can choose which method to use.
11 years ago
Thanks asoares for your replies. In the common controller the isAuthenticated property of the header links model is being set by checking isRegistered property. So I guess you are right about the isRegistered property. Before I realized that you were right I found another way to solve my problem. If a user logs in then the _workContext.CurrentCustomer property is set to the customer who is logging in and when the customer logs out the _workContext.CurrentCustomer is set to null. So by checking the  _workContext.CurrentCustomer property it can be found out if a user is logged in the system or not.
11 years ago
I think the current implementation of IWorkContext.CurrentCustomer returns a guest account when no customer is logged in.
11 years ago
Yeah you are right but you can check if the username is null or not because for the guest account the username is null which can be used to get a customer from the customer service.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.