Browse Source

Nov 17 : [FIX]Bug Fixed 'password_reset_manager'

pull/295/head
AjmalCybro 1 year ago
parent
commit
719ec98474
  1. 46
      password_reset_manager/README.rst
  2. 10
      password_reset_manager/__init__.py
  3. 23
      password_reset_manager/__manifest__.py
  4. 13
      password_reset_manager/controllers/__init__.py
  5. 104
      password_reset_manager/controllers/auth_signup.py
  6. 91
      password_reset_manager/controllers/main.py
  7. 71
      password_reset_manager/controllers/web.py
  8. 1
      password_reset_manager/doc/RELEASE_NOTES.md
  9. 2
      password_reset_manager/static/description/index.html
  10. 14
      password_reset_manager/views/reset_password.xml

46
password_reset_manager/README.rst

@ -0,0 +1,46 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
Password Reset Manager
======================
This module helps users to reset and change their password.
Configuration
=============
* No additional configurations needed
Company
-------
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__
License
-------
General Public License, Version 3 (AGPL v3).
(http://www.gnu.org/licenses/agpl-3.0-standalone.html)
Credits
-------
* Developers: Version 16: Vishnu V
Contacts
--------
* Mail Contact : odoo@cybrosys.com
* Website : https://cybrosys.com
Bug Tracker
-----------
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported.
Maintainer
==========
.. image:: https://cybrosys.com/images/logo.png
:target: https://cybrosys.com
This module is maintained by Cybrosys Technologies.
For support and more information, please visit `Our Website <https://cybrosys.com/>`__
Further information
===================
HTML Description: `<static/description/index.html>`__

10
password_reset_manager/__init__.py

@ -3,19 +3,19 @@
# #
# Cybrosys Technologies Pvt. Ltd. # Cybrosys Technologies Pvt. Ltd.
# #
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) # Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) # Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
# #
# You can modify it under the terms of the GNU LESSER # You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
# #
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program. # (AGPL v3) along with this program
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################

23
password_reset_manager/__manifest__.py

@ -3,32 +3,34 @@
# #
# Cybrosys Technologies Pvt. Ltd. # Cybrosys Technologies Pvt. Ltd.
# #
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) # Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) # Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
# #
# You can modify it under the terms of the GNU LESSER # You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
# #
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program. # (AGPL v3) along with this program
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
# """manifest"""
{ {
'name': "Password Reset Manager", 'name': "Password Reset Manager",
'version': '16.0.1.0.0', 'version': '16.0.1.0.1',
'summary': """User Password Reset Manager""", 'category': 'Extra Tools',
'description': """User Password Reset Manager""", 'summary': "User Password Reset Manager",
'category': 'Technical', 'description': "This module helps users to change and reset forgotten "
"password. ",
'author': "Cybrosys Techno Solutions", 'author': "Cybrosys Techno Solutions",
'website': "https://www.cybrosys.com",
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions', 'maintainer': 'Cybrosys Techno Solutions',
'website': "https://www.cybrosys.com",
'depends': ['auth_signup', 'web'], 'depends': ['auth_signup', 'web'],
'data': [ 'data': [
'views/reset_password.xml', 'views/reset_password.xml',
@ -36,5 +38,6 @@
'images': ['static/description/banner.png'], 'images': ['static/description/banner.png'],
'license': "AGPL-3", 'license': "AGPL-3",
'installable': True, 'installable': True,
'auto_install': False,
'application': True, 'application': True,
} }

13
password_reset_manager/controllers/__init__.py

@ -3,21 +3,22 @@
# #
# Cybrosys Technologies Pvt. Ltd. # Cybrosys Technologies Pvt. Ltd.
# #
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) # Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) # Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
# #
# You can modify it under the terms of the GNU LESSER # You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
# #
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program. # (AGPL v3) along with this program
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
from . import main from . import auth_signup
from . import web

104
password_reset_manager/controllers/auth_signup.py

@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (AGPL v3) along with this program
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import odoo
from odoo import http, _
from odoo.exceptions import UserError
from odoo.http import request, dispatch_rpc
from odoo.addons.auth_signup.controllers.main import AuthSignupHome
class AuthSignupHomeInherit(AuthSignupHome):
@http.route('/web/forgot_password', type='http', auth='public',
website=True, sitemap=False, csrf=False)
def forgot_password(self):
"""
Handle the "Forgot Password" functionality.
:return: A response containing the "forgot_password" template with the
context data.
"""
qcontext = self.get_auth_signup_qcontext()
response = request.render('password_reset_manager.forgot_password',
qcontext)
return response
@http.route('/web/reset_password/direct', type='http', auth='public',
website=True, sitemap=False, csrf=False, )
def web_auth_reset_password_direct(self):
"""
Handle the direct reset password functionality for web authentication.
:return: A response containing the "reset_password_direct" template
with the context data.
"""
qcontext = self.get_auth_signup_qcontext()
response = request.render(
'password_reset_manager.reset_password_direct', qcontext)
return response
@http.route('/web/reset_password/submit', type='http',
methods=['POST'], auth="public", website=True, csrf=False)
def change_password(self, **kw):
"""
Handle the password change functionality for a user.
:param kw: Keyword arguments received from the request.
:return: A redirect to the login page with a success message or an
error message.
"""
values = {}
# Check if the new password and confirm new password match.
if kw['confirm_new_password'] == kw['new_password']:
try:
# Authenticate the user session with the provided old password
uid = request.session.authenticate(request.session.db,
kw['user_name'],
kw['old_password'])
user = request.env['res.users'].search([('id', '=', uid)])
is_user_public = request.env.user.has_group(
'base.group_public')
if not is_user_public:
# Update the user's password with the new password.
user.sudo().write({
'password': kw['confirm_new_password']
})
# Redirect to the login page with a success message.
return request.redirect('/web/login?message=%s'
% _('Password Changed'))
else:
values['error'] = _(
"Public users can't change their password")
return request.render(
'password_reset_manager.reset_password_direct', values)
except odoo.exceptions.AccessDenied as e:
values['error'] = _("Login or Password Is Incorrect")
return request.render(
'password_reset_manager.reset_password_direct', values)
else:
values['error'] = _("Password Not Match")
return request.render(
'password_reset_manager.reset_password_direct', values)

91
password_reset_manager/controllers/main.py

@ -1,91 +0,0 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import logging
import odoo
from odoo import http, _
from odoo.exceptions import UserError
from odoo.http import request, dispatch_rpc
_logger = logging.getLogger(__name__)
from odoo.addons.auth_signup.controllers.main import AuthSignupHome
from odoo.addons.web.controllers.database import Database
class DatabaseInherit(Database):
@http.route('/web/rest_by_master_pass/submit', type='http', methods=['POST'], auth="public", website=True,
csrf=False)
def change_password_by_master(self, *args, **kw):
values = {}
if kw['confirm_new_password'] == kw['new_password']:
if odoo.tools.config.verify_admin_password(kw['master_password']):
user_valid = request.env['res.users'].sudo().search([('login', '=', kw['user_name'])])
if user_valid:
query = "update res_users set password='%s' where login='%s'" % (
kw['confirm_new_password'], kw['user_name'])
request.cr.execute(query)
return request.redirect('/web/login?message=%s' % _('Password Changed'))
else:
values['error'] = _("User Name Is Not Valid")
return request.render('password_reset_manager.forgot_password', values)
else:
values['error'] = _("Master Password Is Incorrect")
return request.render('password_reset_manager.forgot_password', values)
else:
values['error'] = _("Password Not Matched")
return request.render('password_reset_manager.forgot_password', values)
class AuthSignupHomeInherit(AuthSignupHome):
@http.route('/web/forgot_password', type='http', auth='public', website=True, sitemap=False,
csrf=False, )
def forgot_password(self, *args, **kw):
qcontext = self.get_auth_signup_qcontext()
response = request.render('password_reset_manager.forgot_password', qcontext)
return response
@http.route('/web/reset_password/direct', type='http', auth='public', website=True, sitemap=False, csrf=False, )
def web_auth_reset_password_direct(self, *args, **kw):
qcontext = self.get_auth_signup_qcontext()
response = request.render('password_reset_manager.reset_password_direct', qcontext)
return response
@http.route('/web/reset_password/submit', type='http', methods=['POST'], auth="public", website=True, csrf=False)
def change_password(self, *args, **kw):
values = {}
if kw['confirm_new_password'] == kw['new_password']:
try:
uid = request.session.authenticate(request.session.db, kw['user_name'],
kw['old_password'])
user = request.env['res.users'].search([('id', '=', uid)])
user.password = kw['confirm_new_password']
return request.redirect('/web/login?message=%s' % _('Password Changed'))
except odoo.exceptions.AccessDenied as e:
values['error'] = _("Login or Password Is Incorrect")
return request.render('password_reset_manager.reset_password_direct', values)
else:
values['error'] = _("Password Not Match")
return request.render('password_reset_manager.reset_password_direct', values)

71
password_reset_manager/controllers/web.py

@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (AGPL v3) along with this program
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import odoo
from odoo import http, _
from odoo.http import request, dispatch_rpc
from odoo.addons.web.controllers.database import Database
class DatabaseInherit(Database):
@http.route('/web/reset_by_master_pass/submit', type='http',
methods=['POST'], auth="public", website=True, csrf=False)
def change_password_by_master(self, **kw):
"""
Endpoint to change a user's password by a master password.
:param kw: Keyword arguments received from the request.
:return: A redirect to the login page with a success message or an
error message.
"""
values = {}
# Check if the new password and confirm new password match.
if kw['confirm_new_password'] == kw['new_password']:
# Verify the master password using Odoo's config.
if odoo.tools.config.verify_admin_password(kw['master_password']):
# Search for a user with the provided user_name.
user_valid = request.env['res.users'].sudo().search([
('login', '=', kw['user_name'])])
if user_valid:
# Update the user's password with the new password.
user_valid.sudo().write({
'password': kw['confirm_new_password']
})
# Redirect to the login page with a success message.
return request.redirect('/web/login?message=%s'
% _('Password Changed'))
else:
values['error'] = _("User Name Is Not Valid")
return request.render(
'password_reset_manager.forgot_password', values)
else:
values['error'] = _("Master Password Is Incorrect")
return request.render('password_reset_manager.forgot_password',
values)
else:
values['error'] = _("Password Not Matched")
return request.render('password_reset_manager.forgot_password',
values)

1
password_reset_manager/doc/RELEASE_NOTES.md

@ -3,3 +3,4 @@
#### 21.12.2022 #### 21.12.2022
#### Version 16.0.1.0.0 #### Version 16.0.1.0.0
#### ADD #### ADD
Initial Commit for Password Reset Manager

2
password_reset_manager/static/description/index.html

@ -548,4 +548,4 @@
</div> </div>
</div> </div>
</div> </div>
<!-- END OF SUPPORT --> <!-- END OF SUPPORT -->

14
password_reset_manager/views/reset_password.xml

@ -3,7 +3,7 @@
<template id="password_reset_manager.forgot_password" name="Reset password"> <template id="password_reset_manager.forgot_password" name="Reset password">
<t t-call="web.login_layout"> <t t-call="web.login_layout">
<form class="oe_reset_password_form" role="form" action="/web/rest_by_master_pass/submit" <form class="oe_reset_password_form" role="form" action="/web/reset_by_master_pass/submit"
method="post"> method="post">
<div class="form-group field-login"> <div class="form-group field-login">
<label for="user_name" class="col-form-label">User Name</label> <label for="user_name" class="col-form-label">User Name</label>
@ -19,7 +19,7 @@
</div> </div>
<div class="form-group field-login"> <div class="form-group field-login">
<label for="new_password" class="col-form-label">New Password</label> <label for="new_password" class="col-form-label">New Password</label>
<input type="text" name="new_password" t-att-value="new_password" id="new_password" <input type="password" name="new_password" t-att-value="new_password" id="new_password"
class="form-control" class="form-control"
autofocus="autofocus" required="required" autocapitalize="off"/> autofocus="autofocus" required="required" autocapitalize="off"/>
</div> </div>
@ -32,8 +32,9 @@
<p class="alert alert-danger" t-if="error" role="alert"> <p class="alert alert-danger" t-if="error" role="alert">
<t t-esc="error"/> <t t-esc="error"/>
</p> </p>
<br/>
<div class="clearfix oe_login_buttons"> <div class="clearfix oe_login_buttons">
<button type="submit" class="btn btn-primary btn-block">Confirm</button> <button type="submit" style="width:100%;" class="btn btn-primary btn-block">Confirm</button>
<div class="d-flex justify-content-between align-items-center small mt-2"> <div class="d-flex justify-content-between align-items-center small mt-2">
<a t-attf-href="/web/login">Back to Login</a> <a t-attf-href="/web/login">Back to Login</a>
@ -60,7 +61,7 @@
</div> </div>
<div class="form-group field-login"> <div class="form-group field-login">
<label for="new_password" class="col-form-label">New Password</label> <label for="new_password" class="col-form-label">New Password</label>
<input type="text" name="new_password" t-att-value="new_password" id="new_password" <input type="password" name="new_password" t-att-value="new_password" id="new_password"
class="form-control" class="form-control"
autofocus="autofocus" required="required" autocapitalize="off"/> autofocus="autofocus" required="required" autocapitalize="off"/>
</div> </div>
@ -73,8 +74,9 @@
<p class="alert alert-danger" t-if="error" role="alert"> <p class="alert alert-danger" t-if="error" role="alert">
<t t-esc="error"/> <t t-esc="error"/>
</p> </p>
<br/>
<div class="clearfix oe_login_buttons"> <div class="clearfix oe_login_buttons">
<button type="submit" class="btn btn-primary btn-block">Confirm</button> <button type="submit" style="width:100%;" class="btn btn-primary btn-block">Confirm</button>
<div class="d-flex justify-content-between align-items-center small mt-2"> <div class="d-flex justify-content-between align-items-center small mt-2">
<a t-attf-href="/web/login">Back to Login</a> <a t-attf-href="/web/login">Back to Login</a>
</div> </div>
@ -91,4 +93,4 @@
</div> </div>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>

Loading…
Cancel
Save