Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
23018 Tampilan

how i can customize login page and add a field contact_no (already inherited res.users and added contact_no), when user press [Log in] button, this will authenticate the user using contact_no first if exist otherwise use email.

please help.

screenshot for login page: ( here are only 2 fields email and password )


Avatar
Buang
Jawaban Terbai

You can use these apps (search apps in odoo apps by names provided below) to change the whole login page style.

Moreover, these apps provide the ability to define your own favicon and logo as you wish.

Apps Name:

Minimalist Login Form

Creative Login Form

Advanced Login Form


Avatar
Buang
Jawaban Terbai

Hi.

In your case, I think, you could go the following way:

To change the method "_get_login_domain" from the file "odoo/addons/base/models/res_users.py":

    @api.model
    def _get_login_domain(self, login):
        return [('login', '=', login)]

This domain is used in the method "_login" in the same model to get a user by a login. If you inherit the method and change the domain adding your condition like ('contact_no', '=', login) you could get the necessary result. My solution was not tested and may be used as a possible case, so please test it before on your system.


P.S. If you will want to add your parameter to the login page you can do it in the following way:

    <template id="login" inherit_id="web.login" name="Custom Login" >
         <xpath expr="//div[hasclass('field-login')]" position="before">
<div class="form-group field-contact-no">
<label for="contact_no">Contact No</label>
<input type="text" placeholder="Contact No" name="contact_no" t-att-value="contact_no" id="contact_no" t-attf-class="form-control #{'form-control-sm' if form_small else ''}" required="required" autofocus="autofocus" autocapitalize="off"/>
</div>
</xpath>
    </template>

After that, you also need to add the logic for the "contact_no" parameter to the controller method "web_login" in the "web" module.

Avatar
Buang
Penulis

thanks for detailed guide & help, will check it and confirm.

Penulis

first i implemented view part as you have created here, its looking fine Contact No is on top of Email.

to change the method _get_login_domain i failed to find the 'base' folder, may be in odoo 14 it changed. the file res_users.py exist in /addons/base_setup/ but it also inheritting ' res.users ' to modify. i searched for _get_ligin_domain within files, it present in /addons/website/models but it not looks like what you have posted here. please advise.

Penulis

also checked /addons/web/controllers/main.py , web_login method is there but (as per my knowledge as beginner) i failed to figure it out, how to add the logic for the "contact_no" parameter? plesae help.

Hi.

The implementation of the logic that you need is quite complicated and will take time. If you are a beginner and it's your education task I propose to read the book "Odoo Development Essentials" https://www.packtpub.com/product/odoo-development-essentials/9781784392796 or "Odoo 14 Development Cookbook - Fourth Edition" https://www.packtpub.com/product/odoo-14-development-cookbook-fourth-edition/9781800200319.

If it's a business task you could hire our team to solve it by emailing support@garazd.biz.

Best Regards, Yurii Razumovskyi.

Company "Garazd Creation"

https://garazd.biz

Penulis

thanks for books links. regards

Post Terkait Replies Tampilan Aktivitas
0
Mar 21
3154
0
Jun 16
9974
2
Mei 23
2671
0
Feb 23
2410
1
Jul 22
5881