Back to Top

Admin and Customer login process in OpenCart

Updated 30 December 2019

Let’s First start with the Admin login Process

When you open the admin login page and then submit the login form than form submit on the below controller file

  • admin/controller/common/login.php

When a user submit the login form then request go to the above controller file, this file first check and call the validate function of the controller to validate the login form values, like below screenshot:-

postmethod-1

Now, we will look into the validate function of the above controller file

Here inside the if condition OpenCart check if username is empty or password is empty and after the it call the User.php library function to validate that if any user exist or not with the provided username and password value.

Now, we will look into the User.php library files.

You will get this library on the below location.

Start your headless eCommerce
now.
Find out More
  • system/library/cart/user.php (in versions above 2.1.x.x)
  • system/library/user.php (in versions below 2.2.x.x)
librarylogin

Inside this library login function OpenCart first check execute a query in the database with the provided username and password by the user.

After the execution of the above MySQL query this $user_query->num_rows check if there is any row found for the above MySQL query. IF there is any row found than first OpenCart add the user_id in the session variable.

After that, add the user details in the private variables like:- $this->user_id,$this->username etc.

So that we can directly get the current user details anywhere on admin end of OpenCart.

Now, we again go to the first image where the request came when user submit the login form

When both the if condition true then OpenCart checks if there is any redirect URL in the POST request. This is only for to redirect the user on that particular page from where he is redirected to admin login page. If there is any redirect URL than it will redirect the user to that particular page other on the admin dashboard page.

Now, we will look into the Customer login process

When you open the customer login page and then submit the login form than form submit on the below controller file

  • catalog/controller/account/login.php

When a customer submit the login form then request go to the above controller file, this file first check and call the validate function of the controller to validate the login form values, like below screenshot:-

customerlogin

Now, we will look into the validate function of the above controller file

validatecustomer

Here first the function check for the no of failed login attempts to prevent the current customer to logged In.

After that, function check if the current customer status is disabled or not with the provided email address.

After that, validate function call the customer.php library function to validate the current customer details. If the library function return false than OpenCart add a failed login attempt for the provided email or the library function return true than OpenCart delete all the failed attempts to that particular email address.

Now, we will look into the customer.php library function.

You will get this library on the below location.

  • system/library/cart/customer.php (in versions above 2.1.x.x)
  • system/library/customer.php (in versions below 2.2.x.x)
librarylogincustomer

In this function first it checks for the if a admin trying to login the customer account using the admin end, In this case we pass the override true as a third argument than OpenCart doesn’t check for the valid password for the customer account otherwise OpenCart check for the result with the provided email and password value in the MySQL query.

After the execution of the above MySQL query this $customer_query->num_rows check if there is any row found for the above MySQL query. IF there is any row found than first OpenCart add the customer_id in the session variable.

After that, add the user details in the private variables like:- $this->customer_id,$this->email etc. So that we can directly get the current customer details anywhere on front end of OpenCart.

Now, we again go to the first image where the request came when customer submit the login form

When the both the condition of if statement will be true, after that OpenCart add the customer default address in the payment_address and shipping_address session variable to get the tax rate, shipping rates etc.

After that, OpenCart manages the session when user is not logged In like:- wishlist etc. and added these wishlist products to the customer account.

In case you have any Query then feel free to ask in the comment section below. I hope It will help you. Thanks

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


6 comments

  • Terry
    • Jyotsna Gautam (Moderator)
  • Priya
    • Jawahar Lal (Moderator)
      • Priya
        • Jawahar Lal (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home