jellyfin-web/dashboard-ui/scripts/userpassword.js

157 lines
4.1 KiB
JavaScript
Raw Normal View History

2013-04-18 12:09:07 -07:00
(function ($, document, window) {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function loadUser(page) {
2013-02-20 18:33:05 -07:00
var userid = getParameterByName("userId");
ApiClient.getUser(userid).done(function (user) {
Dashboard.setPageTitle(user.Name);
2014-08-15 09:35:41 -07:00
if (user.HasConfiguredPassword) {
2013-02-20 18:33:05 -07:00
$('#btnResetPassword', page).show();
$('#fldCurrentPassword', page).show();
2013-12-24 11:37:29 -07:00
$('.formheader', page).hide();
2014-08-15 09:35:41 -07:00
$('.localAccessSection', page).show();
2013-02-20 18:33:05 -07:00
} else {
$('#btnResetPassword', page).hide();
$('#fldCurrentPassword', page).hide();
2014-04-01 15:23:07 -07:00
$('.formheader', page).show();
2014-08-15 09:35:41 -07:00
$('.localAccessSection', page).hide();
2013-02-20 18:33:05 -07:00
}
2014-08-15 09:35:41 -07:00
$('#chkEnableLocalAccessWithoutPassword', page).checked(user.Configuration.EnableLocalPassword).checkboxradio('refresh');
2013-02-20 18:33:05 -07:00
});
$('#txtCurrentPassword', page).val('');
$('#txtNewPassword', page).val('');
$('#txtNewPasswordConfirm', page).val('');
2013-04-18 12:09:07 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function save(page) {
2013-02-20 18:33:05 -07:00
var userId = getParameterByName("userId");
2014-08-15 09:35:41 -07:00
ApiClient.getUser(userId).done(function (user) {
user.Configuration.EnableLocalPassword = $('#chkEnableLocalAccessWithoutPassword', page).checked();
ApiClient.updateUser(user).done(function() {
Dashboard.hideLoadingMsg();
Dashboard.alert(Globalize.translate('MessageSettingsSaved'));
loadUser(page);
});
});
}
function savePassword(page) {
var userId = getParameterByName("userId");
2013-02-20 18:33:05 -07:00
var currentPassword = $('#txtCurrentPassword', page).val();
var newPassword = $('#txtNewPassword', page).val();
2013-04-18 12:09:07 -07:00
ApiClient.updateUserPassword(userId, currentPassword, newPassword).done(function () {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('PasswordSaved'));
2013-04-18 12:09:07 -07:00
loadUser(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
});
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function updatePasswordPage() {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
var self = this;
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
self.onSubmit = function () {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
var page = $.mobile.activePage;
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
if ($('#txtNewPassword', page).val() != $('#txtNewPasswordConfirm', page).val()) {
2013-02-20 18:33:05 -07:00
2014-05-30 12:23:56 -07:00
Dashboard.showError(Globalize.translate('PasswordMatchError'));
2013-04-18 12:09:07 -07:00
return false;
2013-02-20 18:33:05 -07:00
}
2013-04-18 12:09:07 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-08-15 09:35:41 -07:00
savePassword(page);
// Disable default form submission
return false;
};
self.onLocalAccessSubmit = function () {
var page = $.mobile.activePage;
Dashboard.showLoadingMsg();
2013-04-18 12:09:07 -07:00
save(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
// Disable default form submission
2013-02-20 18:33:05 -07:00
return false;
2013-04-18 12:09:07 -07:00
};
self.resetPassword = function () {
2014-05-30 12:23:56 -07:00
var msg = Globalize.translate('PasswordResetConfirmation');
2013-04-18 12:09:07 -07:00
var page = $.mobile.activePage;
2014-05-30 12:23:56 -07:00
Dashboard.confirm(msg, Globalize.translate('PasswordResetHeader'), function (result) {
2013-04-18 12:09:07 -07:00
if (result) {
var userId = getParameterByName("userId");
Dashboard.showLoadingMsg();
ApiClient.resetUserPassword(userId).done(function () {
Dashboard.hideLoadingMsg();
2013-12-26 19:23:57 -07:00
Dashboard.alert({
2014-05-30 12:23:56 -07:00
message: Globalize.translate('PasswordResetComplete'),
title: Globalize.translate('PasswordResetHeader')
2013-12-26 19:23:57 -07:00
});
2014-03-30 19:33:10 -07:00
2013-04-18 12:09:07 -07:00
loadUser(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
});
}
});
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
};
2013-02-20 18:33:05 -07:00
}
2013-04-18 12:09:07 -07:00
window.UpdatePasswordPage = new updatePasswordPage();
$(document).on('pagebeforeshow', "#updatePasswordPage", function () {
var page = this;
Dashboard.getCurrentUser().done(function (loggedInUser) {
if (loggedInUser.Configuration.IsAdministrator) {
$('#lnkParentalControl', page).show();
2013-04-18 12:09:07 -07:00
} else {
$('#lnkParentalControl', page).hide();
2013-04-18 12:09:07 -07:00
}
});
}).on('pageshow', "#updatePasswordPage", function () {
var page = this;
loadUser(page);
});
})(jQuery, document, window);