@@ -1,3 +1,4 @@
|
||||
* Allow resetting forgotten password
|
||||
|
||||
Version 7.0.0 - 2023-10-30
|
||||
--------------------------
|
||||
|
||||
+48
-1
@@ -87,6 +87,23 @@
|
||||
}
|
||||
return prm;
|
||||
},
|
||||
do_reset_password: function() {
|
||||
if (!this.login) {
|
||||
return jQuery.when();
|
||||
}
|
||||
const args = {
|
||||
'id': 0,
|
||||
'method': 'common.db.reset_password',
|
||||
'params': [this.login, Sao.i18n.getlang()],
|
||||
};
|
||||
return jQuery.ajax({
|
||||
'contentType': 'application/json',
|
||||
'data': JSON.stringify(args),
|
||||
'dataType': 'json',
|
||||
'url': '/' + this.database + '/',
|
||||
'type': 'post',
|
||||
});
|
||||
},
|
||||
reload_context: function() {
|
||||
var args = {
|
||||
'method': 'model.res.user.get_preferences',
|
||||
@@ -518,7 +535,37 @@
|
||||
return Sao.common.ask.run(message, name);
|
||||
},
|
||||
get_password: function(message, name) {
|
||||
return Sao.common.ask.run(message, name, false);
|
||||
const session = this.session;
|
||||
const AskPasswordDialog = Sao.class_(Sao.common.AskDialog, {
|
||||
build_dialog: function(question, name, visibility, prm) {
|
||||
const dialog = AskPasswordDialog._super.build_dialog.call(
|
||||
this, question, name, visibility, prm);
|
||||
jQuery('<button/>', {
|
||||
'class': 'btn btn-link btn-sm pull-left',
|
||||
'type': 'button',
|
||||
'title': Sao.i18n.gettext(
|
||||
"Send you an email to reset your password."),
|
||||
}).text("Reset forgotten password").click(() => {
|
||||
session.do_reset_password().then(() => {
|
||||
return Sao.common.message.run(Sao.i18n.gettext(
|
||||
"A request to reset your password has been sent.\n" +
|
||||
"Please check your mailbox."));
|
||||
}).then(() => {
|
||||
dialog.modal.find('input,select')
|
||||
.filter(':visible').first().focus();
|
||||
});
|
||||
}).prependTo(dialog.footer);
|
||||
dialog.modal.find('.modal-dialog').removeClass('modal-sm');
|
||||
return dialog;
|
||||
},
|
||||
});
|
||||
var ask;
|
||||
if (name == 'password') {
|
||||
ask = new AskPasswordDialog();
|
||||
} else {
|
||||
ask = Sao.common.ask;
|
||||
}
|
||||
return ask.run(message, name, false);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Allow resetting forgotten password
|
||||
* Clean temporary files and directories at exit
|
||||
|
||||
Version 7.0.0 - 2023-10-30
|
||||
|
||||
@@ -1103,7 +1103,7 @@ class Login(object):
|
||||
if exception.faultCode != 'LoginException':
|
||||
raise
|
||||
name, msg, type = exception.args
|
||||
value = getattr(self, 'get_%s' % type)(msg)
|
||||
value = getattr(self, 'get_%s' % type)(msg, name)
|
||||
if value is None:
|
||||
raise TrytonError('QueryCanceled')
|
||||
parameters[name] = value
|
||||
@@ -1112,12 +1112,35 @@ class Login(object):
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def get_char(cls, message):
|
||||
def get_char(cls, message, name):
|
||||
return ask(message)
|
||||
|
||||
@classmethod
|
||||
def get_password(cls, message):
|
||||
return ask(message, visibility=False)
|
||||
def get_password(cls, message_, name):
|
||||
class AskPasswordDialog(AskDialog):
|
||||
def build_dialog(self, *args, **kwargs):
|
||||
tooltips = Tooltips()
|
||||
dialog = super().build_dialog(*args, **kwargs)
|
||||
box = dialog.get_message_area()
|
||||
button = Gtk.Button.new_with_label(
|
||||
_("Reset forgotten password"))
|
||||
button.set_alignment(0, 0.5)
|
||||
button.set_relief(Gtk.ReliefStyle.NONE)
|
||||
tooltips.set_tip(
|
||||
button, _("Send you an email to reset your password."))
|
||||
button.connect('clicked', self.reset_password)
|
||||
box.pack_start(button, False, False, 0)
|
||||
return dialog
|
||||
|
||||
def reset_password(self, button):
|
||||
rpc.reset_password()
|
||||
message(
|
||||
_("A request to reset your password has been sent.\n"
|
||||
"Please check your mailbox."))
|
||||
self.entry.grab_focus()
|
||||
if name == 'password':
|
||||
ask = AskPasswordDialog()
|
||||
return ask(message_, visibility=False)
|
||||
|
||||
|
||||
class Logout:
|
||||
|
||||
@@ -145,6 +145,24 @@ def logout():
|
||||
_USER = None
|
||||
|
||||
|
||||
def reset_password():
|
||||
from tryton import common
|
||||
host = CONFIG['login.host']
|
||||
hostname = common.get_hostname(host)
|
||||
port = common.get_port(host)
|
||||
database = CONFIG['login.db']
|
||||
username = CONFIG['login.login']
|
||||
language = CONFIG['client.lang']
|
||||
if not all([host, database, username]):
|
||||
return
|
||||
try:
|
||||
connection = ServerProxy(hostname, port)
|
||||
logger.info('common.db.reset_password(%s, %s)', (username, language))
|
||||
connection.common.db.reset_password(username, language)
|
||||
except Fault as exception:
|
||||
logger.debug(exception.faultCode)
|
||||
|
||||
|
||||
def execute(*args):
|
||||
global CONNECTION, _USER
|
||||
if CONNECTION is None:
|
||||
|
||||
Reference in New Issue
Block a user