support in-home easy password

This commit is contained in:
Luke Pulverenti 2015-01-29 01:06:24 -05:00
parent 340fcbb607
commit 27b770b898
3 changed files with 117 additions and 9 deletions

View File

@ -94,20 +94,30 @@
<form class="localAccessForm localAccessSection userProfileSettingsForm" style="margin: 0 auto;"> <form class="localAccessForm localAccessSection userProfileSettingsForm" style="margin: 0 auto;">
<div class="detailSection"> <div class="detailSection">
<div class="detailSectionHeader"> <div class="detailSectionHeader">
${HeaderLocalAccess} ${HeaderEasyPinCode}
</div> </div>
<div class="detailSectionContent"> <div class="detailSectionContent">
<br />
<div>${EasyPasswordHelp}</div>
<br /> <br />
<div> <div>
<label for="chkEnableLocalAccessWithoutPassword">${LabelAllowLocalAccessWithoutPassword}</label> <label for="txtEasyPassword">${LabelEasyPinCode}</label>
<input type="checkbox" id="chkEnableLocalAccessWithoutPassword" /> <input type="password" id="txtEasyPassword" />
<div class="fieldDescription">${LabelAllowLocalAccessWithoutPasswordHelp}</div>
</div> </div>
<br /> <br />
<div> <div>
<button type="submit" data-theme="b" data-icon="check"> <label for="chkEnableLocalEasyPassword">${LabelInNetworkSignInWithEasyPassword}</label>
<input type="checkbox" id="chkEnableLocalEasyPassword" />
<div class="fieldDescription">${LabelInNetworkSignInWithEasyPasswordHelp}</div>
</div>
<br />
<div>
<button type="submit" data-theme="b" data-icon="check" data-mini="true">
${ButtonSave} ${ButtonSave}
</button> </button>
<button id="btnResetEasyPassword" style="display:none;" type="button" data-icon="lock" onclick="UpdatePasswordPage.resetEasyPassword();" data-mini="true">
${ButtonResetEasyPassword}
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -248,7 +248,15 @@
$('.passwordSection', page).show(); $('.passwordSection', page).show();
} }
$('#chkEnableLocalAccessWithoutPassword', page).checked(user.Configuration.EnableLocalPassword).checkboxradio('refresh'); if (user.HasConfiguredEasyPassword) {
$('#txtEasyPassword', page).val('').attr('placeholder', '******');
$('#btnResetEasyPassword', page).show();
} else {
$('#txtEasyPassword', page).val('').attr('placeholder', '');
$('#btnResetEasyPassword', page).hide();
}
$('#chkEnableLocalEasyPassword', page).checked(user.Configuration.EnableLocalPassword).checkboxradio('refresh');
}); });
$('#txtCurrentPassword', page).val(''); $('#txtCurrentPassword', page).val('');
@ -256,13 +264,30 @@
$('#txtNewPasswordConfirm', page).val(''); $('#txtNewPasswordConfirm', page).val('');
} }
function save(page) { function saveEasyPassword(page) {
var userId = getParameterByName("userId"); var userId = getParameterByName("userId");
var easyPassword = $('#txtEasyPassword', page).val();
if (easyPassword) {
ApiClient.updateEasyPassword(userId, easyPassword).done(function () {
onEasyPasswordSaved(page, userId);
});
} else {
onEasyPasswordSaved(page, userId);
}
}
function onEasyPasswordSaved(page, userId) {
ApiClient.getUser(userId).done(function (user) { ApiClient.getUser(userId).done(function (user) {
user.Configuration.EnableLocalPassword = $('#chkEnableLocalAccessWithoutPassword', page).checked(); user.Configuration.EnableLocalPassword = $('#chkEnableLocalEasyPassword', page).checked();
ApiClient.updateUserConfiguration(user.Id, user.Configuration).done(function () { ApiClient.updateUserConfiguration(user.Id, user.Configuration).done(function () {
@ -321,7 +346,7 @@
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
save(page); saveEasyPassword(page);
// Disable default form submission // Disable default form submission
return false; return false;
@ -357,6 +382,36 @@
}); });
}; };
self.resetEasyPassword = function () {
var msg = Globalize.translate('PinCodeResetConfirmation');
var page = $.mobile.activePage;
Dashboard.confirm(msg, Globalize.translate('HeaderPinCodeReset'), function (result) {
if (result) {
var userId = getParameterByName("userId");
Dashboard.showLoadingMsg();
ApiClient.resetEasyPassword(userId).done(function () {
Dashboard.hideLoadingMsg();
Dashboard.alert({
message: Globalize.translate('PinCodeResetComplete'),
title: Globalize.translate('HeaderPinCodeReset')
});
loadUser(page);
});
}
});
};
} }
window.UpdatePasswordPage = new updatePasswordPage(); window.UpdatePasswordPage = new updatePasswordPage();

View File

@ -2498,6 +2498,28 @@
}); });
}; };
/**
* Updates a user's easy password
* @param {String} userId
* @param {String} newPassword
*/
self.updateEasyPassword = function (userId, newPassword) {
if (!userId) {
throw new Error("null userId");
}
var url = self.getUrl("Users/" + userId + "/EasyPassword");
return self.ajax({
type: "POST",
url: url,
data: {
newPassword: CryptoJS.SHA1(newPassword).toString()
}
});
};
/** /**
* Resets a user's password * Resets a user's password
* @param {String} userId * @param {String} userId
@ -2523,6 +2545,27 @@
}); });
}; };
self.resetEasyPassword = function (userId) {
if (!userId) {
throw new Error("null userId");
}
var url = self.getUrl("Users/" + userId + "/EasyPassword");
var postData = {
};
postData.resetPassword = true;
return self.ajax({
type: "POST",
url: url,
data: postData
});
};
/** /**
* Updates the server's configuration * Updates the server's configuration
* @param {Object} configuration * @param {Object} configuration