Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Redirect to a specific URL after successful login

Subscribe

Get notified when there's activity on this post

This question has been flagged
actionLoginredirection
1 Reply
4230 Views
Avatar
Prajwal

How to redirect to custom url after portal user successful login. Currently the portal user redirect to /my url of odoo. I have created custom module to redirect user to specific url after login, but the odoo does not invoke the custom controller it still used the odoo default login functionality. Following is my code please give me solution to achieve the functionality.

import logging

from odoo import http

from odoo.http import request

from odoo.exceptions import AccessDenied


_logger = logging.getLogger(__name__)


class CustomLoginRedirectController(http.Controller):


    # Override the default login route

    @http.route('/web/login', type='http', auth='none', website=True, csrf=False)

    def custom_web_login(self, redirect=None, **kw):

        """

        Override the default login behavior to redirect users to a custom URL after login.

        """

        _logger.info("Custom login controller invoked")


        # Ensure we have a valid database selected

        http.ensure_db()


        # If the user is already logged in, redirect to a custom URL

        if request.session.uid:

            _logger.info("User already logged in, redirecting to /buyer_search")

            # Custom redirect URL after login

            return request.redirect('/buyer_search')  # Replace with your custom URL


        # Values for the login page template

        values = request.params.copy()

        values['login_success'] = False


        try:

            values['databases'] = http.db_list()

        except AccessDenied:

            values['databases'] = None


        if request.httprequest.method == 'POST':

            login = request.params.get('login')

            password = request.params.get('password')


            _logger.info("POST request received. Attempting to authenticate user %s", login)


            try:

                # Authenticate the user using the credentials provided in the POST request

                if request.session.authenticate(request.db, login, password):

                    values['login_success'] = True

                    _logger.info("User %s authenticated successfully. Redirecting to /buyer_search", login)

                    # Redirect to the custom URL after successful login

                    return request.redirect('/buyer_search')  # Replace with your custom URL

                else:

                    # Invalid login credentials

                    values['error'] = 'Invalid username or password'

                    _logger.warning("Invalid login attempt for user %s", login)

            except AccessDenied as e:

                values['error'] = str(e)

                _logger.error("Access denied during login attempt for user %s: %s", login, str(e))


        # Handle GET requests and display the original login page

        _logger.info("Rendering the login page")

        response = request.render('web.login', values)

        response.headers['X-Frame-Options'] = 'DENY'

        return response




0
Avatar
Discard
Avatar
Sylvain Michel Ratsarafahatra
Best Answer

Hello,

By default, for a portal user, the redirection is to /my, so if you want to redirect a user according to your conditions, you can redirect the user to another URL like the code below, adjusting it according to your needs.

from odoo.addons.web.controllers.home import Home as WebHome
from odoo.addons.web.controllers.utils import is_user_internal

class Home(WebHome):

def _login_redirect(self, uid, redirect=None):
if not redirect and not is_user_internal(uid):
redirect = '/buyer_search' # Replace with your custom URL
return super()._login_redirect(uid, redirect=redirect)

Best regards!

1
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Enhanced Pricelist Discount Reporting and Accounting in Odoo 17
action
Avatar
0
Dec 25
7
How to Book Flights on Ex-pedia? ✈️ (Complete 2025 Guide)
action
Avatar
0
Dec 25
2
No error or warning message during import/export in Odoo Body:
action
Avatar
0
Dec 25
88
{~!@!IBeria52MX} ¿Cómo puedo reservar mi vuelo en Iberia?
action
Avatar
0
Dec 25
5
odoo 19, Social Marketing module
action
Avatar
Avatar
1
Dec 25
374
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now