webui: remove IPA.unauthorized_dialog

https://fedorahosted.org/freeipa/ticket/3903

Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
This commit is contained in:
Petr Vobornik 2014-03-28 13:40:30 +01:00
parent 466e32f9ec
commit 6b0c6bf344
2 changed files with 0 additions and 469 deletions

View File

@ -1407,16 +1407,6 @@ form#login {
margin-top: 100px;
}
/* --- Unauthorized dialog --- */
.auth-dialog {
padding: 0 2em;
}
.auth-dialog h3 {
margin: 0.5em;
}
/* --- Action list --- */
.facet-action-list {

View File

@ -1013,465 +1013,6 @@ IPA.error_dialog = function(spec) {
return that;
};
/**
* Unauthorized dialog
*
* Notifies that user's session is expired. It supports forms-based authentication
* and password reset when password is expired.
*
* @class IPA.unauthorized_dialog
* @extends IPA.error_dialog
* @param {Object} spec
*/
IPA.unauthorized_dialog = function(spec) {
spec = spec || {};
spec.sections = [
{
name: 'login',
label: 'Login',
show_header: false,
fields: [
{
name: 'username',
label: text.get('@i18n:login.username', "Username")
},
{
name: 'password',
$type: 'password',
label: text.get('@i18n:login.password', "Password")
}
]
},
{
name: 'reset',
label: 'Reset',
show_header: false,
fields: [
{
name: 'username_r',
read_only: true,
label: text.get('@i18n:login.username', "Username")
},
{
name: 'new_password',
$type: 'password',
required: true,
label: text.get('@i18n:password.new_password)', "New Password")
},
{
name: 'verify_password',
$type: 'password',
required: true,
label: text.get('@i18n:password.verify_password', "Verify Password"),
validators: [{
$type: 'same_password',
other_field: 'new_password'
}]
}
]
}
];
spec.visible_buttons = spec.visible_buttons || ['retry'];
spec.name = spec.name || 'unauthorized_dialog';
spec.id = spec.id || spec.name;
var that = IPA.error_dialog(spec);
/** @inheritDoc */
that.title = spec.title || text.get('@i18n:login.login', "Login");
/** @property {string} message Session expired message */
that.message = text.get(spec.message || '@i18n:ajax.401.message',
"Your session has expired. Please re-login.");
/** @property {string} form_auth_msg Forms authentication message */
that.form_auth_msg = text.get(spec.form_auth_msg || '@i18n:login.form_auth',
"To login with username and password, enter them in the fields below then click Login.");
/** @property {string} krb_auth_msg Kerberos authentication message */
that.krb_auth_msg = text.get(spec.krb_auth_msg || '@i18n:login.krb_auth_msg',
" To login with Kerberos, please make sure you" +
" have valid tickets (obtainable via kinit) and " +
"<a href='http://${host}/ipa/config/unauthorized.html'>configured</a>" +
" the browser correctly, then click Login. ");
that.krb_auth_msg = that.krb_auth_msg.replace('${host}', window.location.hostname);
/** @property {string} form_auth_failed Forms authentication failure message */
that.form_auth_failed = "<p><strong>Please re-enter your username or password</strong></p>" +
"<p>The password or username you entered is incorrect. " +
"Please try again (make sure your caps lock is off).</p>" +
"<p>If the problem persists, contact your administrator.</p>";
/** @property {string} password_expired Password expired message */
that.password_expired = "Your password has expired. Please enter a new password.";
/** @property {string} denied Login denied message */
that.denied = "Sorry you are not allowed to access this service.";
/** @inheritDoc */
that.create_content = function() {
that.session_expired_form();
that.create_reset_form();
};
/**
* Create session expired form
* @protected
*/
that.session_expired_form = function() {
that.session_form = $('<div\>').appendTo(that.container);
that.login_error_box = $('<div/>', {
'class': 'error-box',
style: 'display:none',
html: that.form_auth_failed
}).appendTo(that.session_form);
$('<p/>', {
html: that.message
}).appendTo(that.session_form);
$('<p/>', {
html: that.krb_auth_msg
}).appendTo(that.session_form);
$('<p/>', {
html: that.form_auth_msg
}).appendTo(that.session_form);
$('<div>', {
'class': 'auth-dialog'
}).appendTo(that.session_form);
var section = that.widgets.get_widget('login');
var div = $('<div/>', {
name: 'login',
'class': 'dialog-section'
}).appendTo(that.session_form);
section.create(div);
that.username_widget = that.widgets.get_widget('login.username');
that.password_widget = that.widgets.get_widget('login.password');
that.username_widget.value_changed.attach(that.on_username_change);
};
/**
* Create password reset form
* @protected
*/
that.create_reset_form = function() {
that.reset_form = $('<div\>', {
style: 'display:none'
}).appendTo(that.container);
that.reset_error_box = $('<div/>', {
'class': 'error-box'
}).appendTo(that.reset_form);
$('<p/>', {
html: that.password_expired
}).appendTo(that.reset_form);
var section = that.widgets.get_widget('reset');
var div = $('<div/>', {
name: 'reset',
'class': 'dialog-section'
}).appendTo(that.reset_form);
section.create(div);
that.username_r_widget = that.widgets.get_widget('reset.username_r');
that.new_password_widget = that.widgets.get_widget('reset.new_password');
that.verify_password_widget = that.widgets.get_widget('reset.verify_password');
};
/**
* Create dialog buttons
* @protected
*/
that.create_buttons = function() {
that.buttons.empty();
var visible = that.visible_buttons.indexOf('login') > -1;
var label = text.get('@i18n:login.login', "Login");
that.create_button({
name: 'login',
label: label,
visible: visible,
click: function() {
that.on_login();
}
});
visible = that.visible_buttons.indexOf('reset') > -1;
label = text.get('@i18n:buttons.reset_password_and_login', "Reset Password and Login");
that.create_button({
name: 'reset',
label: label,
visible: visible,
click: function() {
that.on_reset();
}
});
visible = that.visible_buttons.indexOf('cancel') > -1;
label = text.get('@i18n:buttons.cancel', "Cancel");
that.create_button({
name: 'cancel',
label: label,
visible: visible,
click: function() {
that.on_cancel();
}
});
};
/** @inheritDoc */
that.open = function() {
that.dialog_open();
that.show_session_form();
that.check_error_reason();
};
/**
* Check if response contains IPA specific rejection reason.
* @protected
*/
that.check_error_reason = function() {
if (this.xhr) {
var reason = this.xhr.getResponseHeader("X-IPA-Rejection-Reason");
if (reason) {
that.show_login_error_message(reason);
}
}
};
/**
* User name field value change handler
* @protected
*/
that.on_username_change = function() {
var password_field = that.fields.get_field('password');
var user_specified = !IPA.is_empty(that.username_widget.save());
password_field.set_required(user_specified);
if (!user_specified) that.password_widget.clear();
};
/**
* Enable fields with given name
* @protected
* @param {string[]} field_names
*/
that.enable_fields = function(field_names) {
var field, fields, i, enable;
fields = that.fields.get_fields();
for (i=0; i<fields.length; i++) {
field = fields[i];
enable = field_names.indexOf(field.name) > -1;
field.set_enabled(enable);
}
};
/**
* Shows session expired form. Hides other.
* @protected
*/
that.show_session_form = function() {
that.current_view = 'session';
that.enable_fields(['username', 'password']);
that.session_form.css('display', 'block');
that.reset_form.css('display', 'none');
that.display_buttons(['login']);
that.username_widget.focus_input();
};
/**
* Shows password reset form. Hides other.
* @protected
*/
that.show_reset_form = function() {
that.current_view = 'reset';
that.enable_fields(['username_r', 'new_password', 'verify_password']);
that.session_form.css('display', 'none');
that.reset_form.css('display', 'block');
that.display_buttons(['reset', 'cancel']);
var username = that.username_widget.save();
that.username_r_widget.update(username);
that.new_password_widget.focus_input();
};
/**
* Show login error message - based on reason
* @protected
* @param {"invalid"|"denied"|string} reason
*/
that.show_login_error_message = function(reason) {
var errors = {
'invalid': that.form_auth_failed,
'denied': that.denied
};
var message = errors[reason];
if (message) {
that.login_error_box.html(message);
that.login_error_box.css('display', 'block');
}
};
/**
* Cancel handler
* @protected
*/
that.on_cancel = function() {
that.username_widget.clear();
that.password_widget.clear();
that.username_r_widget.clear();
that.new_password_widget.clear();
that.verify_password_widget.clear();
that.show_session_form();
};
/**
* Initiates login procedure
* @protected
*/
that.on_login = function() {
var username = that.username_widget.save();
var password = that.password_widget.save();
//if user doesn't specify username and password try kerberos auth
if (IPA.is_empty(username) && IPA.is_empty(password)) {
that.on_retry();
return;
}
if (!that.validate()) return;
IPA.display_activity_icon();
var result = IPA.login_password(username[0], password[0]);
IPA.hide_activity_icon();
if (result === 'success') {
that.on_login_success();
} else if (result === 'password-expired') {
that.reset_error_box.css('display', 'none');
that.show_reset_form();
} else {
that.show_login_error_message(result);
}
};
/**
* Login success handler
* @protected
*/
that.on_login_success = function() {
that.login_error_box.css('display', 'none');
that.username_widget.clear();
that.password_widget.clear();
that.on_retry();
};
/**
* Initiates password reset procedure
* @protected
*/
that.on_reset = function() {
if (!that.validate()) return;
var username = that.username_widget.save();
var password = that.password_widget.save();
var new_password = that.new_password_widget.save();
var verify_password = that.verify_password_widget.save();
that.reset_error_box.css('display', 'none');
var result = IPA.reset_password(username[0],
password[0],
new_password[0]);
if (result.status === 'ok') {
that.on_reset_success();
} else {
that.reset_error_box.html(result.message);
that.reset_error_box.css('display', 'block');
}
};
/**
* Password reset success handler
* @protected
*/
that.on_reset_success = function() {
that.login_error_box.css('display', 'none');
that.reset_error_box.css('display', 'none');
that.password_widget.update(that.new_password_widget.save());
that.new_password_widget.clear();
that.verify_password_widget.clear();
that.show_session_form();
//re-login
that.on_login();
};
/**
* Key up handler for proper keyboard usage.
* @protected
*/
that.on_key_up = function(event) {
if (that.switching) {
that.switching = false;
return;
}
if (that.current_view === 'session') {
if (event.keyCode === keys.ENTER && !this.test_ignore(event)) {
that.on_login();
event.preventDefault();
}
} else {
if (event.keyCode === keys.ENTER && !this.test_ignore(event)) {
that.on_reset();
event.preventDefault();
} else if (event.keyCode === keys.ESCAPE) {
that.on_cancel();
event.preventDefault();
}
}
};
that.create_buttons();
return that;
};
/**
* Shorten text to desired number of characters.
*