Add authentication support (#185)

This commit is contained in:
Michael Green
2023-11-25 14:50:44 +11:00
committed by GitHub
parent 2ade60c551
commit 3d2f94681a
88 changed files with 6187 additions and 124 deletions

View File

@@ -24,7 +24,7 @@
$('#collection_addgame').select2({
ajax: {
url: '/api/v1.0/Collections',
url: '/api/v1.1/Collections',
placeholder: 'Select collection',
processResults: function (data) {
var arr = [];
@@ -59,7 +59,7 @@
if (CollectionId != 0) {
ajaxCall(
'/api/v1.0/Collections/' + CollectionId + '/AlwaysInclude' + RebuildCollection,
'/api/v1.1/Collections/' + CollectionId + '/AlwaysInclude' + RebuildCollection,
'PATCH',
function (result) {
closeSubDialog();

View File

@@ -12,7 +12,7 @@
<script type="text/javascript">
function deleteCollection() {
ajaxCall(
'/api/v1.0/Collections/' + subModalVariables,
'/api/v1.1/Collections/' + subModalVariables,
'DELETE',
function (result) {
GetCollections();

View File

@@ -136,7 +136,7 @@
// setup dropdowns
$('#collection_platform').select2({
ajax: {
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
processResults: function (data) {
var filter = data['platforms'];
@@ -159,7 +159,7 @@
$('#collection_genres').select2({
ajax: {
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
processResults: function (data) {
var filter = data['genres'];
@@ -182,7 +182,7 @@
$('#collection_players').select2({
ajax: {
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
processResults: function (data) {
var filter = data['gamemodes'];
@@ -205,7 +205,7 @@
$('#collection_playerperspectives').select2({
ajax: {
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
processResults: function (data) {
var filter = data['playerperspectives'];
@@ -228,7 +228,7 @@
$('#collection_themes').select2({
ajax: {
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
processResults: function (data) {
var filter = data['themes'];
@@ -258,7 +258,7 @@
// edit mode
ajaxCall(
'/api/v1.0/Collections/' + modalVariables,
'/api/v1.1/Collections/' + modalVariables,
'GET',
function(result) {
if (result.name) { document.getElementById('collection_name').value = result.name; }
@@ -278,7 +278,7 @@
// fill select2 controls
$.ajax(
{
url: '/api/v1.0/Filter',
url: '/api/v1.1/Filter',
type: 'GET',
indexValue: result,
dataType: 'json',
@@ -344,7 +344,7 @@
// existing object - save over the top
item.id = modalVariables;
ajaxCall(
'/api/v1.0/Collections/' + modalVariables,
'/api/v1.1/Collections/' + modalVariables,
'PATCH',
function(result) {
location.reload();
@@ -357,7 +357,7 @@
} else {
// new object
ajaxCall(
'/api/v1.0/Collections',
'/api/v1.1/Collections',
'POST',
function(result) {
location.reload();
@@ -426,7 +426,7 @@
var item = GenerateCollectionItem();
ajaxCall(
'/api/v1.0/Collections/Preview',
'/api/v1.1/Collections/Preview',
'POST',
function(result) {
DisplayPreview(result, 'collectionedit_previewbox_content');
@@ -579,7 +579,7 @@
var gameImage = document.createElement('img');
gameImage.className = 'game_tile_image game_tile_image_small';
if (gameItem.cover) {
gameImage.src = '/api/v1.0/Games/' + gameItem.id + '/cover/image';
gameImage.src = '/api/v1.1/Games/' + gameItem.id + '/cover/image';
} else {
gameImage.src = '/images/unknowngame.png';
gameImage.className = 'game_tile_image game_tile_image_small unknown';

View File

@@ -12,7 +12,7 @@
<script type="text/javascript">
function deleteLibrary() {
ajaxCall(
'/api/v1.0/Library/' + subModalVariables,
'/api/v1.1/Library/' + subModalVariables,
'DELETE',
function (result) {
drawLibrary();

View File

@@ -32,7 +32,7 @@
$('#newlibrary_defaultplatform').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1.0/Search/Platform',
url: '/api/v1.1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
@@ -76,7 +76,7 @@
alert("A path must be provided.");
} else {
ajaxCall(
'/api/v1.0/Library?Name=' + encodeURIComponent(libName) + '&DefaultPlatformId=' + libPlatform[0].id + '&Path=' + encodeURIComponent(libPath),
'/api/v1.1/Library?Name=' + encodeURIComponent(libName) + '&DefaultPlatformId=' + libPlatform[0].id + '&Path=' + encodeURIComponent(libPath),
'POST',
function(result) {
drawLibrary();

View File

@@ -12,7 +12,7 @@
<script type="text/javascript">
function deleteCollection() {
ajaxCall(
'/api/v1.0/Games/' + gameData.id + '/romgroup/' + subModalVariables,
'/api/v1.1/Games/' + gameData.id + '/romgroup/' + subModalVariables,
'DELETE',
function (result) {
loadRoms();

View File

@@ -105,7 +105,7 @@
DisplayWebEmulatorContent(false);
ajaxCall(
'/api/v1.0/PlatformMaps/' + modalVariables,
'/api/v1.1/PlatformMaps/' + modalVariables,
'GET',
function (result) {
// set heading
@@ -338,7 +338,7 @@
console.log(JSON.stringify(item));
ajaxCall(
'/api/v1.0/PlatformMaps/' + modalVariables,
'/api/v1.1/PlatformMaps/' + modalVariables,
'PATCH',
function (result) {
loadPlatformMapping();

View File

@@ -11,7 +11,7 @@
<script type="text/javascript">
function deleteRom() {
ajaxCall('/api/v1.0/Games/' + gameId + '/roms/' + modalVariables, 'DELETE', function (result) {
ajaxCall('/api/v1.1/Games/' + gameId + '/roms/' + modalVariables, 'DELETE', function (result) {
window.location.reload();
});
}

View File

@@ -118,7 +118,7 @@
}
}
ajaxCall('/api/v1.0/Games/' + gameId + '/roms/' + modalVariables, 'GET', function (result) {
ajaxCall('/api/v1.1/Games/' + gameId + '/roms/' + modalVariables, 'GET', function (result) {
romData = result;
document.getElementById('modal-heading').innerHTML = result.name;
document.getElementById('rominfo_library').innerHTML = result.library.name;
@@ -169,7 +169,7 @@
$('#properties_fixplatform').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1.0/Search/Platform',
url: '/api/v1.1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
@@ -200,7 +200,7 @@
minimumInputLength: 3,
templateResult: DropDownRenderGameOption,
ajax: {
url: '/api/v1.0/Search/Game',
url: '/api/v1.1/Search/Game',
data: function (params) {
fixplatform = $('#properties_fixplatform').select2('data');
@@ -236,7 +236,7 @@
document.getElementById('properties_fixsave').setAttribute("disabled", "disabled");
ajaxCall('/api/v1.0/Games/' + gameId + '/roms/' + modalVariables + '?NewPlatformId=' + fixplatform[0].id + '&NewGameId=' + fixgame[0].id, 'PATCH', function (result) {
ajaxCall('/api/v1.1/Games/' + gameId + '/roms/' + modalVariables + '?NewPlatformId=' + fixplatform[0].id + '&NewGameId=' + fixgame[0].id, 'PATCH', function (result) {
window.location.reload();
});
}

View File

@@ -0,0 +1,29 @@
<p>Are you sure you want to delete the selected user?</p>
<p><strong>Warning:</strong> This cannot be undone!</p>
<div style="width: 100%; text-align: center;">
<div style="display: inline-block; margin-right: 20px;">
<button class="redbutton" value="Delete" onclick="deleteUserCallback();">Delete</button>
</div>
<div style="display: inline-block; margin-left: 20px;">
<button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</div>
</div>
<script type="text/javascript">
function deleteUserCallback() {
ajaxCall(
'/api/v1.1/Account/Users/' + subModalVariables,
'DELETE',
function(result) {
console.log('Deleted user');
GetUsers();
closeSubDialog();
},
function(error) {
console.log(JSON.stringify(error));
GetUsers();
closeSubDialog();
}
);
}
</script>

View File

@@ -0,0 +1,375 @@
<div id="properties_toc">
<div id="properties_user_toc_password" name="properties_user_toc_item" onclick="UserSelectTab('password');">Password</div>
<div id="properties_user_toc_role" name="properties_user_toc_item" onclick="UserSelectTab('role');">Role</div>
<div id="properties_user_toc_age" name="properties_user_toc_item" onclick="UserSelectTab('age');">Content Restrictions</div>
<!--<div id="properties_toc_manage" name="properties_toc_item" onclick="SelectTab('manage');">Manage</div>-->
</div>
<div id="properties_bodypanel" style="height: 450px; overflow-y: scroll;">
<div id="properties_bodypanel_password" name="properties_user_tab" style="display: none;">
<table style="width: 100%;">
<tr>
<th>
Password
</th>
<td>
<input type="password" id="settings_users_edit_password" style="width: 95%;" onkeyup="checkPasswordsMatch();" />
</td>
</tr>
<tr>
<th>
Confirm password
</th>
<td>
<input type="password" id="settings_users_edit_confirmpassword" style="width: 95%;" onkeyup="checkPasswordsMatch();" />
</td>
</tr>
<tr>
<td colspan="2" id="settings_users_edit_label"></td>
</tr>
</table>
</div>
<div id="properties_bodypanel_role" name="properties_user_tab" style="display: none;">
<table style="width: 100%;" class="romtable">
<tr>
<th>
</th>
<th>
<input type="radio" name="settings_user_role" id="settings_user_role_player" value="Player"> <label for="settings_user_role_player">Player</label>
</th>
<th>
<input type="radio" name="settings_user_role" id="settings_user_role_gamer" value="Gamer"> <label for="settings_user_role_gamer">Gamer</label>
</th>
<th>
<input type="radio" name="settings_user_role" id="settings_user_role_admin" value="Admin"> <label for="settings_user_role_admin">Administrator</label>
</th>
</tr>
<tr>
<th colspan="4"><h3>Games and ROM's</h3></td>
</tr>
<tr class="romrow">
<td class="romcell">Play games</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Download ROM images</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Upload ROM images</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Create and delete multidisk packages</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Delete ROM images</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Fix ROM image matches</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr>
<th colspan="4"><h3>Collections</h3></td>
</tr>
<tr class="romrow">
<td class="romcell">Download packages</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Create packages</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Edit packages</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Delete packages</td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr>
<th colspan="4"><h3>Settings</h3></td>
</tr>
<tr class="romrow">
<td class="romcell">Download firmware</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">View background tasks</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">View platform mapping</td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Modify platform mapping</td>
<td class="romcell"></td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Manually start background tasks</td>
<td class="romcell"></td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">View logs</td>
<td class="romcell"></td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
<tr class="romrow">
<td class="romcell">Manage user accounts</td>
<td class="romcell"></td>
<td class="romcell"></td>
<td class="romcell"><img src="/images/tick.svg" class="banner_button_image" /></td>
</tr>
</table>
</div>
<div id="properties_bodypanel_age" name="properties_user_tab" style="display: none;">
<h3>Classification Restrictions</h3>
<div id="properties_bodypanel_age_classification">
</div>
<input type="checkbox" id="properties_bodypanel_age_includeunclassified"> <label for="properties_bodypanel_age_includeunclassified">Include unclassified titles</label>
</div>
</div>
<div style="width: 100%; padding-top: 10px; text-align: right;">
<button id="settings_users_edit_okbutton" value="OK" onclick="saveProperties();">OK</button>
</div>
<script type="text/javascript">
ajaxCall(
'/api/v1.1/Account/users/' + modalVariables,
'GET',
function(result) {
document.getElementById('modal-heading').innerHTML = result.emailAddress;
// role page
document.getElementById('settings_user_role_' + result.highestRole.toLowerCase()).checked = true;
// age restriction page
var ageRatingsContainer = document.getElementById('properties_bodypanel_age_classification');
var ageRatingsTable = document.createElement('table');
ageRatingsTable.style.width = '100%';
ageRatingsTable.cellSpacing = 0;
ageRatingsTable.appendChild(
createTableRow(
true,
[
'Highest Allowed Rating',
'Included Ratings'
],
'',
''
)
);
for (var ageGroup in AgeRatingGroups) {
if (AgeRatingGroups.hasOwnProperty(ageGroup)) {
var ratingsValues = '';
var classBoards = AgeRatingGroups[ageGroup];
for (var classBoard in classBoards) {
for (var rating in classBoards[classBoard]) {
ratingsValues += "<img src='/api/v1.1/Ratings/Images/" + classBoard + "/" + classBoards[classBoard][rating] + "/image.svg' class='rating_image_mini' />";
}
}
var radioCheckedState = '';
if (result.securityProfile.ageRestrictionPolicy.maximumAgeRestriction.toLowerCase() == ageGroup.toLocaleLowerCase()) {
radioCheckedState = "checked='checked'";
}
ageRatingsTable.appendChild(
createTableRow(
false,
[
"<input type='radio' id='properties_bodypanel_age_classification_" + ageGroup + "' name='classification_group' " + radioCheckedState + " value='" + ageGroup + "' /> <label for='properties_bodypanel_age_classification_" + ageGroup + "'>" + ageGroup + "</label>",
ratingsValues
],
'romrow',
'romcell'
)
);
}
}
ageRatingsContainer.appendChild(ageRatingsTable);
document.getElementById('properties_bodypanel_age_includeunclassified').checked = result.securityProfile.ageRestrictionPolicy.includeUnrated;
},
function(error) {
closeDialog();
}
);
function UserSelectTab(TabName) {
var tabs = document.getElementsByName('properties_user_tab');
for (var i = 0; i < tabs.length; i++) {
if ((tabs[i].id) == ("properties_bodypanel_" + TabName)) {
tabs[i].style.display = '';
} else {
tabs[i].style.display = 'none';
}
}
var tocs = document.getElementsByName('properties_user_toc_item');
for (var i = 0; i < tocs.length; i++) {
if ((tocs[i].id) == ("properties_user_toc_" + TabName)) {
tocs[i].className = "properties_toc_item_selected";
} else {
tocs[i].className = '';
}
}
}
function checkPasswordsMatch() {
var newPassword = document.getElementById('settings_users_edit_password').value;
var conPassword = document.getElementById('settings_users_edit_confirmpassword').value;
var errorLabel = document.getElementById('settings_users_edit_label');
var submitButton = document.getElementById('settings_users_edit_okbutton');
if (newPassword.length > 0) {
if (newPassword == conPassword) {
// check if password meets requirements
if (newPassword.length > 10) {
errorLabel.innerHTML = "";
submitButton.removeAttribute('disabled');
return true;
} else {
errorLabel.innerHTML = "Password should be at least 10 characters long";
submitButton.setAttribute('disabled', 'disabled');
return false;
}
} else {
errorLabel.innerHTML = "New and confirmed passwords do not match";
submitButton.setAttribute('disabled', 'disabled');
return false;
}
} else {
errorLabel.innerHTML = "Password will not be changed";
submitButton.removeAttribute('disabled');
return true;
}
}
function saveProperties() {
saveRole();
}
function saveRole() {
if (checkPasswordsMatch() == true) {
// process role
var selectedRole = $("input[type='radio'][name='settings_user_role']:checked").val();
ajaxCall(
'/api/v1.1/Account/users/' + modalVariables + '/Roles?RoleName=' + selectedRole,
'POST',
function(result) {
saveSecurityProfile();
},
function(error) {
saveSecurityProfile();
}
);
}
}
function saveSecurityProfile() {
if (checkPasswordsMatch() == true) {
// process security profile
var securityProfile = {
"ageRestrictionPolicy": {
"maximumAgeRestriction": $("input[type='radio'][name='classification_group']:checked").val(),
"includeUnrated": document.getElementById('properties_bodypanel_age_includeunclassified').checked
}
};
ajaxCall(
'/api/v1.1/Account/users/' + modalVariables + '/SecurityProfile',
'POST',
function(result) {
savePassword();
},
function(error) {
savePassword();
},
JSON.stringify(securityProfile)
);
}
}
function savePassword() {
console.log("Save Password");
if (checkPasswordsMatch() == true) {
console.log("Passwords match");
var newPassword = document.getElementById('settings_users_edit_password').value;
if (newPassword.length > 0) {
var model = {
"newPassword": newPassword,
"confirmPassword": newPassword
}
ajaxCall(
'/api/v1.1/Account/Users/' + modalVariables + '/Password',
'POST',
function(result) {
console.log(JSON.stringify(result));
savePropertiesCallback();
},
function(error) {
console.log(JSON.stringify(error));
savePropertiesCallback();
},
JSON.stringify(model)
);
} else {
console.log("Password not long enough to change");
savePropertiesCallback();
}
} else {
console.log("Passwords don't match");
}
}
function savePropertiesCallback() {
GetUsers();
closeDialog();
}
UserSelectTab('password');
</script>

View File

@@ -0,0 +1,88 @@
<h3>New User</h3>
<table style="width: 100%;">
<tr>
<th>
Email
</th>
<td>
<input type="text" id="settings_users_new_username" style="width: 95%;" onkeyup="checkPasswordsMatch();" />
</td>
</tr>
<tr>
<th>
Password
</th>
<td>
<input type="password" id="settings_users_new_password" style="width: 95%;" onkeyup="checkPasswordsMatch();" />
</td>
</tr>
<tr>
<th>
Confirm password
</th>
<td>
<input type="password" id="settings_users_new_confirmpassword" style="width: 95%;" onkeyup="checkPasswordsMatch();" />
</td>
</tr>
<tr>
<td colspan="2" id="settings_users_new_label"></td>
</tr>
<tr>
<td colspan="2" style="text-align: right; padding-top: 10px;">
<button value="OK" id="settings_users_new_okbutton" disabled="disabled" onclick="createUser();">OK</button><button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</td>
</tr>
</table>
<script type="text/javascript">
function checkPasswordsMatch() {
var userNameVal = document.getElementById('settings_users_new_username').value;
var newPassword = document.getElementById('settings_users_new_password').value;
var conPassword = document.getElementById('settings_users_new_confirmpassword').value;
var errorLabel = document.getElementById('settings_users_new_label');
var submitButton = document.getElementById('settings_users_new_okbutton');
if (userNameVal.includes("@")) {
if (newPassword == conPassword) {
// check if password meets requirements
if (newPassword.length > 10) {
errorLabel.innerHTML = "";
submitButton.removeAttribute('disabled');
} else {
errorLabel.innerHTML = "Password should be at least 10 characters long";
submitButton.setAttribute('disabled', 'disabled');
}
} else {
errorLabel.innerHTML = "New and confirmed passwords do not match";
submitButton.setAttribute('disabled', 'disabled');
}
} else {
errorLabel.innerHTML = "Email address is invalid";
submitButton.setAttribute('disabled', 'disabled');
}
}
function createUser() {
var model = {
"userName": document.getElementById('settings_users_new_username').value,
"email": document.getElementById('settings_users_new_username').value,
"password": document.getElementById('settings_users_new_password').value,
"confirmPassword": document.getElementById('settings_users_new_confirmpassword').value
}
ajaxCall(
'/api/v1.1/Account/Users',
'POST',
function(result) {
GetUsers();
closeSubDialog();
},
function(error) {
GetUsers();
closeSubDialog();
},
JSON.stringify(model)
);
}
</script>

View File

@@ -28,7 +28,7 @@
document.getElementById('upload_platformoverride').innerHTML = "<option value='0' selected='selected'>Automatic Platform</option>";
var myDropzone = new Dropzone("div#upload_target", {
url: "/api/v1.0/Roms",
url: "/api/v1.1/Roms",
autoProcessQueue: true,
uploadMultiple: true,
paramName: myParamName,
@@ -84,7 +84,7 @@
$('#upload_platformoverride').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1.0/Search/Platform',
url: '/api/v1.1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
@@ -125,6 +125,6 @@
}
console.log(queryString);
myDropzone.options.url = "/api/v1.0/Roms" + queryString;
myDropzone.options.url = "/api/v1.1/Roms" + queryString;
});
</script>

View File

@@ -0,0 +1,122 @@
<div id="properties_toc">
<div id="properties_profile_toc_general" name="properties_profile_toc_item" onclick="ProfileSelectTab('general');">Account</div>
</div>
<div id="properties_bodypanel">
<div id="properties_bodypanel_general" name="properties_profile_tab" style="display: none;">
<h3>Reset Password</h3>
<table style="width: 100%;">
<tr>
<th>Old Password</th>
<td><input type="password" id="profile_oldpassword" style="width: 95%;" /></td>
</tr>
<tr>
<th>New Password</th>
<td><input type="password" id="profile_newpassword" style="width: 95%;" onkeyup="checkPasswordsMatch();" /></td>
</tr>
<tr>
<th>Confirm Password</th>
<td><input type="password" id="profile_confirmpassword" style="width: 95%;" onkeyup="checkPasswordsMatch();" /></td>
</tr>
<tr>
<td colspan="2" id="profile_passwordnotice"></td>
</tr>
<tr>
<td colspan="2" style="text-align: right;">
<button id="profile_resetpassword" value="Reset Password" disabled="disabled" onclick="ResetPassword();">Reset Password</button>
</td>
</tr>
</table>
</div>
</div>
<script type="text/javascript">
document.getElementById('modal-heading').innerHTML = userProfile.emailAddress;
function ProfileSelectTab(TabName) {
var tabs = document.getElementsByName('properties_profile_tab');
for (var i = 0; i < tabs.length; i++) {
if ((tabs[i].id) == ("properties_bodypanel_" + TabName)) {
tabs[i].style.display = '';
} else {
tabs[i].style.display = 'none';
}
}
var tocs = document.getElementsByName('properties_profile_toc_item');
for (var i = 0; i < tocs.length; i++) {
if ((tocs[i].id) == ("properties_profile_toc_" + TabName)) {
tocs[i].className = "properties_toc_item_selected";
} else {
tocs[i].className = '';
}
}
}
function checkPasswordsMatch() {
var oldPassword = document.getElementById('profile_oldpassword').value;
var newPassword = document.getElementById('profile_newpassword').value;
var conPassword = document.getElementById('profile_confirmpassword').value;
var errorLabel = document.getElementById('profile_passwordnotice');
var submitButton = document.getElementById('profile_resetpassword');
// make sure the new password is not the same as the old one
if (newPassword == oldPassword) {
errorLabel.innerHTML = "New password should not match the old password";
submitButton.setAttribute('disabled', 'disabled');
} else {
if (newPassword == conPassword) {
// check if password meets requirements
if (newPassword.length > 10) {
errorLabel.innerHTML = "";
submitButton.removeAttribute('disabled');
} else {
errorLabel.innerHTML = "Password should be at least 10 characters long";
submitButton.setAttribute('disabled', 'disabled');
}
} else {
errorLabel.innerHTML = "New and confirmed passwords do not match";
submitButton.setAttribute('disabled', 'disabled');
}
}
}
function ResetPassword() {
var oldPassword = document.getElementById('profile_oldpassword').value;
var newPassword = document.getElementById('profile_newpassword').value;
var conPassword = document.getElementById('profile_confirmpassword').value;
var model = {
"OldPassword": oldPassword,
"NewPassword": newPassword,
"ConfirmPassword": conPassword
}
ajaxCall(
'/api/v1.1/Account/ChangePassword',
'POST',
function(result) {
ResetPasswordCallback(result);
},
function(error) {
ResetPasswordCallback(error);
},
JSON.stringify(model)
);
}
function ResetPasswordCallback(result) {
var errorLabel = document.getElementById('profile_passwordnotice');
if (result.succeeded == false) {
errorLabel.innerHTML = result.errors.description;
} else {
document.getElementById('profile_oldpassword').value = '';
document.getElementById('profile_newpassword').value = '';
document.getElementById('profile_confirmpassword').value = '';
document.getElementById('profile_resetpassword').setAttribute('disabled', 'disabled');
errorLabel.innerHTML = "Password changed.";
}
}
ProfileSelectTab('general');
</script>