Allow changing of the users password without leaving the app. Fixes #2891

This commit is contained in:
Murtuza Zabuawala
2017-11-28 10:55:54 +00:00
committed by Dave Page
parent 035c134fed
commit 9ae4a03784
7 changed files with 134 additions and 11 deletions

View File

@@ -281,6 +281,12 @@ def create_app(app_name=None):
# TODO: Figure out how to disable /logout and /login
app.config['SECURITY_RECOVERABLE'] = True
app.config['SECURITY_CHANGEABLE'] = True
# Now we'll open change password page in alertify dialog
# we don't want it to redirect to main page after password
# change operation so we will open the same password change page again.
app.config.update(
dict(SECURITY_POST_CHANGE_VIEW='security.change_password')
)
# Create database connection object and mailer
db.init_app(app)

View File

@@ -170,7 +170,13 @@ window.onload = function(e){
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"></a>
<ul class="dropdown-menu navbar-inverse">
<li><a href="{{ url_for('security.change_password') }}">{{ _('Change Password') }}</a></li>
<li>
<a href="#" onclick="pgAdmin.Browser.UserManagement.change_password(
'{{ url_for('security.change_password') }}'
)">
{{ _('Change Password') }}
</a>
</li>
<li class="divider"></li>
{% if is_admin %}
<li><a href="#" onclick="pgAdmin.Browser.UserManagement.show_users()">{{ _('Users') }}</a></li>

View File

@@ -1,7 +1,7 @@
{% macro render_field_with_errors(field, type) %}
<div class="form-group{% if field.errors %} has-error{% endif %}">
<input class="form-control" placeholder="{{ field.label.text }}" name="{{ field.name }}"
type="{% if type %}{{ type }}{% else %}{{ field.type }}{% endif %}">
type="{% if type %}{{ type }}{% else %}{{ field.type }}{% endif %}" autofocus>
</div>
{% if field.errors %}
{% for error in field.errors %}

View File

@@ -37,6 +37,91 @@ define([
return this;
},
// Callback to draw change password Dialog.
change_password: function(url) {
var title = gettext('Change Password');
if(!alertify.ChangePassword) {
alertify.dialog('ChangePassword' ,function factory() {
return {
main: function(title, url) {
this.set({
'title': title,
'url': url
});
},
build: function() {
alertify.pgDialogBuild.apply(this)
},
settings:{
url: undefined
},
setup:function() {
return {
buttons: [{
text: '', key: 112,
className: 'btn btn-default pull-left fa fa-lg fa-question',
attrs:{
name:'dialog_help', type:'button', label: gettext('Change Password'),
url: url_for(
'help.static', {
'filename': 'change_user_password.html'
})
}
},{
text: gettext('Close'), key: 27,
className: 'btn btn-danger fa fa-lg fa-times pg-alertify-button',
attrs:{name:'close', type:'button'}
}],
// Set options for dialog
options: {
//disable both padding and overflow control.
padding : !1,
overflow: !1,
modal: false,
resizable: true,
maximizable: true,
pinnable: false,
closableByDimmer: false,
closable: false
}
};
},
hooks: {
// Triggered when the dialog is closed
onclose: function() {
// Clear the view
return setTimeout((function() {
return alertify.ChangePassword().destroy();
}), 500);
}
},
prepare: function() {
// create the iframe element
var iframe = document.createElement('iframe');
iframe.frameBorder = "no";
iframe.width = "100%";
iframe.height = "100%";
iframe.src = this.setting('url');
// add it to the dialog
this.elements.content.appendChild(iframe);
},
callback: function(e) {
if (e.button.element.name == "dialog_help") {
e.cancel = true;
pgBrowser.showHelp(e.button.element.name, e.button.element.getAttribute('url'),
null, null, e.button.element.getAttribute('label'));
return;
}
}
};
});
}
alertify.ChangePassword(title, url).resizeTo('75%','70%');
},
// Callback to draw User Management Dialog.
show_users: function(action, item, params) {
if (!userInfo['is_admin']) return;