tidy up users resource supporting better updates. useraccounts resources has been removed along with change password template convenience api.
This commit is contained in:
+1
@@ -79,6 +79,7 @@ public class ApplicationPagesRoutesController {
|
||||
BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal();
|
||||
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
|
||||
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
|
||||
model.addAttribute("userId", userDetails.getUserId());
|
||||
return "admin/accountsettings";
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ public class ApiDelegatingAuthenticationProvider extends AbstractUserDetailsAuth
|
||||
authorities.add(new SimpleGrantedAuthority(permission));
|
||||
}
|
||||
User user = new User(authenticatedUserData.getUsername(), "[not needed]", authorities);
|
||||
userDetails = new BasicAuthUserDetails(user, authenticatedUserData.getBase64EncodedAuthenticationKey(), platformApiUrl);
|
||||
userDetails = new BasicAuthUserDetails(user, authenticatedUserData.getBase64EncodedAuthenticationKey(), platformApiUrl, authenticatedUserData.getUserId());
|
||||
}
|
||||
|
||||
return userDetails;
|
||||
@@ -80,8 +80,8 @@ public class ApiDelegatingAuthenticationProvider extends AbstractUserDetailsAuth
|
||||
|
||||
private HttpEntity<Object> authRequest() {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept", "application/xml");
|
||||
requestHeaders.set("Content-Type", "application/xml");
|
||||
requestHeaders.set("Accept", "application/json");
|
||||
requestHeaders.set("Content-Type", "application/json");
|
||||
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestHeaders);
|
||||
return requestEntity;
|
||||
|
||||
+7
-1
@@ -11,11 +11,13 @@ public class BasicAuthUserDetails implements UserDetails {
|
||||
private final User user;
|
||||
private final String basicAuthenticationKey;
|
||||
private final String fullApiUrl;
|
||||
private final Long userId;
|
||||
|
||||
public BasicAuthUserDetails(User user, String basicAuthenticationKey, String fullApiUrl) {
|
||||
public BasicAuthUserDetails(User user, String basicAuthenticationKey, String fullApiUrl, Long userId) {
|
||||
this.user = user;
|
||||
this.basicAuthenticationKey = basicAuthenticationKey;
|
||||
this.fullApiUrl = fullApiUrl;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,4 +62,8 @@ public class BasicAuthUserDetails implements UserDetails {
|
||||
public String getFullApiUrl() {
|
||||
return this.fullApiUrl;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
}
|
||||
+77
-7
@@ -23,6 +23,7 @@ $(document).ready(function() {
|
||||
// basic auth details
|
||||
var base64 = "${basicAuthKey}";
|
||||
var baseApiUrl = "${baseApiUrl}";
|
||||
var userId = "${userId}";
|
||||
|
||||
// these helpers are registered for the jsViews and jsRender functionality to fix bug with display zero!
|
||||
$.views.registerHelpers({
|
||||
@@ -215,7 +216,6 @@ $(document).ready(function() {
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: function(xhr) {
|
||||
console.log("base64: " + base64);
|
||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||
},
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
@@ -249,7 +249,6 @@ $(document).ready(function() {
|
||||
data: newFormData,
|
||||
cache: false,
|
||||
beforeSend: function(xhr) {
|
||||
console.log("base64: " + base64);
|
||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||
},
|
||||
success: saveSuccessFunction,
|
||||
@@ -295,6 +294,78 @@ $(document).ready(function() {
|
||||
});
|
||||
}
|
||||
|
||||
function popupDialogWithPostOnlyFormView(postOrPutUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||
|
||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||
|
||||
var data = new Object();
|
||||
var formHtml = $(templateSelector).render(data);
|
||||
|
||||
dialogDiv.append(formHtml);
|
||||
|
||||
var saveButton = jQuery.i18n.prop('dialog.button.save');
|
||||
var cancelButton = jQuery.i18n.prop('dialog.button.cancel');
|
||||
|
||||
var buttonsOpts = {};
|
||||
buttonsOpts[saveButton] = function() {
|
||||
|
||||
$('.multiSelectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: postOrPutUrl,
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
data: newFormData,
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||
},
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
dialogDiv.dialog("close");
|
||||
$newtabs.tabs('load', tabIndex);
|
||||
}
|
||||
});
|
||||
|
||||
jqxhr.error(function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
});
|
||||
};
|
||||
|
||||
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
|
||||
|
||||
dialogDiv.dialog({
|
||||
title: jQuery.i18n.prop(titleCode),
|
||||
width: width,
|
||||
height: height,
|
||||
modal: true,
|
||||
buttons: buttonsOpts,
|
||||
close: function() {
|
||||
// if i dont do this, theres a problem with errors being appended to dialog view second time round
|
||||
$(this).remove();
|
||||
},
|
||||
open: function (event, ui) {
|
||||
$('.multiadd').click(function() {
|
||||
return !$('.multiNotSelectedItems option:selected').remove().appendTo('#selectedItems');
|
||||
});
|
||||
|
||||
$('.multiremove').click(function() {
|
||||
return !$('.multiSelectedItems option:selected').remove().appendTo('#notSelectedItems');
|
||||
});
|
||||
|
||||
$('.datepickerfield').datepicker({constrainInput: true, dateFormat: 'dd MM yy'});
|
||||
|
||||
$("#entityform textarea").first().focus();
|
||||
$('#entityform input').first().focus();
|
||||
}
|
||||
}).dialog('open');
|
||||
}
|
||||
|
||||
$("#tabs").tabs({
|
||||
"ajaxOptions": {
|
||||
type: 'GET',
|
||||
@@ -313,8 +384,7 @@ $(document).ready(function() {
|
||||
$("#settings").html(tableHtml);
|
||||
|
||||
$('#changepassword').click(function(e) {
|
||||
var getUrl = baseApiUrl + 'useraccounts/current/password/template';
|
||||
var putUrl = baseApiUrl + 'useraccounts/current/password';
|
||||
var putUrl = baseApiUrl + 'users/' + userId;
|
||||
var templateSelector = "#changePasswordFormTemplate";
|
||||
var width = 600;
|
||||
var height = 350;
|
||||
@@ -324,13 +394,13 @@ $(document).ready(function() {
|
||||
$("#tabs").tabs('load', 0);
|
||||
}
|
||||
|
||||
popupDialogWithFormView(getUrl, putUrl, 'PUT', 'dialog.title.update.password', templateSelector, width, height, saveSuccessFunction);
|
||||
popupDialogWithPostOnlyFormView(putUrl, 'PUT', 'dialog.title.update.password', templateSelector, width, height, saveSuccessFunction);
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#changedetails').click(function(e) {
|
||||
var getAndPutUrl = baseApiUrl + 'useraccounts/current';
|
||||
var getAndPutUrl = baseApiUrl + 'users/' + userId;
|
||||
var templateSelector = "#userSettingsFormTemplate";
|
||||
var width = 600;
|
||||
var height = 350;
|
||||
@@ -362,7 +432,7 @@ $(document).ready(function() {
|
||||
<div id="content">
|
||||
<div id="tabs">
|
||||
<ul>
|
||||
<li><a href="${baseApiUrl}useraccounts/current" title="settings"><spring:message code="tab.settings"/></a></li>
|
||||
<li><a href="${baseApiUrl}users/${userId}" title="settings"><spring:message code="tab.settings"/></a></li>
|
||||
</ul>
|
||||
<div id="settings">
|
||||
</div>
|
||||
|
||||
+2
-2
@@ -297,8 +297,8 @@
|
||||
<label for="password"><spring:message code="form.label.new.password"/></label>
|
||||
<input id="password" name="password" title="" type="password" value="{{=password}}" size="75"/>
|
||||
|
||||
<label for="passwordrepeat"><spring:message code="form.label.repeat.new.password"/></label>
|
||||
<input id="passwordrepeat" name="passwordrepeat" title="" type="password" value="{{=passwordrepeat}}" size="75"/>
|
||||
<label for="repeatPassword"><spring:message code="form.label.repeat.new.password"/></label>
|
||||
<input id="repeatPassword" name="repeatPassword" title="" type="password" value="{{=passwordrepeat}}" size="75"/>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user