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

123 lines
3.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);
if (user.HasPassword) {
$('#btnResetPassword', page).show();
$('#fldCurrentPassword', page).show();
2013-12-24 11:37:29 -07:00
$('.formheader', page).hide();
2013-02-20 18:33:05 -07:00
} else {
$('#btnResetPassword', page).hide();
$('#fldCurrentPassword', page).hide();
2013-12-24 11:37:29 -07:00
$('.formheader', page).html('Create Password').show();
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");
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
2013-04-18 12:09:07 -07:00
Dashboard.alert("Password saved.");
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
2013-04-18 12:09:07 -07:00
Dashboard.showError("Password and password confirmation must match.");
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
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 () {
var msg = "Are you sure you wish to reset the password?";
var page = $.mobile.activePage;
Dashboard.confirm(msg, "Password Reset", function (result) {
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({
message: "The password has been reset.",
title: "Password Reset"
});
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);