add useraccounts resource which is responsible for supporting capabilities that allow a user update their account details.
This commit is contained in:
@@ -2,7 +2,6 @@ package org.mifosng.ui;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.data.AppUserData;
|
||||
import org.mifosng.data.ClientData;
|
||||
import org.mifosng.data.ClientDataWithAccountsData;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
@@ -17,7 +16,6 @@ import org.mifosng.data.PermissionData;
|
||||
import org.mifosng.data.RoleData;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.ChangePasswordCommand;
|
||||
import org.mifosng.data.command.EnrollClientCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
@@ -35,10 +33,6 @@ public interface CommonRestOperations {
|
||||
|
||||
void updateProtectedResource(ProtectedResourceDetails loadProtectedResourceDetailsById);
|
||||
|
||||
AppUserData retrieveCurrentUser();
|
||||
|
||||
EntityIdentifier updateCurrentUserPassword(ChangePasswordCommand command);
|
||||
|
||||
Collection<RoleData> retrieveAllRoles();
|
||||
|
||||
RoleData retrieveRole(Long roleId);
|
||||
|
||||
-44
@@ -6,7 +6,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosng.configuration.ApplicationConfigurationService;
|
||||
import org.mifosng.data.AppUserData;
|
||||
import org.mifosng.data.ClientData;
|
||||
import org.mifosng.data.ClientDataWithAccountsData;
|
||||
import org.mifosng.data.ClientList;
|
||||
@@ -29,7 +28,6 @@ import org.mifosng.data.RoleData;
|
||||
import org.mifosng.data.RoleList;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.ChangePasswordCommand;
|
||||
import org.mifosng.data.command.EnrollClientCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
@@ -547,25 +545,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier updateCurrentUserPassword(
|
||||
ChangePasswordCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/current/password"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri,
|
||||
createUpdateCurrentUserPasswordRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
private HttpEntity<UserCommand> createUserRequest(final UserCommand command) {
|
||||
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
@@ -577,18 +556,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
private HttpEntity<ChangePasswordCommand> createUpdateCurrentUserPasswordRequest(
|
||||
final ChangePasswordCommand command) {
|
||||
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept", "application/xml");
|
||||
requestHeaders.set("Content-Type", "application/xml");
|
||||
|
||||
HttpEntity<ChangePasswordCommand> requestEntity = new HttpEntity<ChangePasswordCommand>(
|
||||
command, requestHeaders);
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
private HttpEntity<RoleCommand> roleRequest(final RoleCommand command) {
|
||||
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
@@ -600,17 +567,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveCurrentUser() {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/current"));
|
||||
|
||||
ResponseEntity<AppUserData> s = this.oauthRestServiceTemplate.exchange(
|
||||
restUri, HttpMethod.GET, emptyRequest(), AppUserData.class);
|
||||
|
||||
return s.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RoleData> retrieveAllRoles() {
|
||||
try {
|
||||
|
||||
-58
@@ -4,23 +4,14 @@ import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mifosng.data.AppUserData;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.command.ChangePasswordCommand;
|
||||
import org.mifosng.data.command.UserCommand;
|
||||
import org.mifosng.ui.CommonRestOperations;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
/**
|
||||
* Controller for user and organisation administration functions.
|
||||
@@ -28,13 +19,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
@Controller
|
||||
public class AdministrationController {
|
||||
|
||||
private final CommonRestOperations commonRestOperations;
|
||||
|
||||
@Autowired
|
||||
public AdministrationController(final CommonRestOperations commonRestOperations) {
|
||||
this.commonRestOperations = commonRestOperations;
|
||||
}
|
||||
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public String accessDeniedException() {
|
||||
return "unAuthorizedAction";
|
||||
@@ -63,46 +47,4 @@ public class AdministrationController {
|
||||
public String userSettingsScreen() {
|
||||
return "admin/accountsettings";
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "org/admin/settings/details", method = RequestMethod.GET)
|
||||
public @ResponseBody AppUserData viewUserDetails() {
|
||||
|
||||
return this.commonRestOperations.retrieveCurrentUser();
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "org/admin/settings/details", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier updateUserDetails(
|
||||
@RequestParam(value="username", required=false) String username,
|
||||
@RequestParam(value="firstname", required=false) String firstname,
|
||||
@RequestParam(value="lastname", required=false) String lastname,
|
||||
@RequestParam(value="email", required=false) String email) {
|
||||
|
||||
UserCommand command = new UserCommand();
|
||||
command.setUsername(username);
|
||||
command.setFirstname(firstname);
|
||||
command.setLastname(lastname);
|
||||
command.setEmail(email);
|
||||
|
||||
return this.commonRestOperations.updateCurrentUserDetails(command);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "org/admin/settings/password", method = RequestMethod.GET)
|
||||
public @ResponseBody ChangePasswordCommand viewChangePasswordDetails() {
|
||||
|
||||
return new ChangePasswordCommand();
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "org/admin/settings/password", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier updateUserDetails(
|
||||
@RequestParam(value="password", required=false) String password,
|
||||
@RequestParam(value="passwordrepeat", required=false) String passwordrepeat) {
|
||||
|
||||
ChangePasswordCommand command = new ChangePasswordCommand();
|
||||
command.setPassword(password);
|
||||
command.setPasswordrepeat(passwordrepeat);
|
||||
|
||||
return this.commonRestOperations.updateCurrentUserPassword(command);
|
||||
}
|
||||
}
|
||||
+59
-25
@@ -59,9 +59,9 @@ $(document).ready(function() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
globalDate: function(dateParts) {
|
||||
globalDate: function(localDateAsISOString) {
|
||||
try {
|
||||
|
||||
var dateParts = localDateAsISOString.split("-")
|
||||
var year = dateParts[0];
|
||||
var month = parseInt(dateParts[1]) - 1; // month is zero indexed
|
||||
var day = dateParts[2];
|
||||
@@ -74,9 +74,9 @@ $(document).ready(function() {
|
||||
return "??";
|
||||
}
|
||||
},
|
||||
globalDateTime: function(dateParts) {
|
||||
globalDateTime: function(dateInMillis) {
|
||||
try {
|
||||
var d = new Date(dateParts);
|
||||
var d = new Date(dateInMillis);
|
||||
|
||||
return Globalize.format(d,"F");
|
||||
} catch(e) {
|
||||
@@ -118,17 +118,25 @@ $(document).ready(function() {
|
||||
removeErrors(placeholderDiv);
|
||||
|
||||
var jsonErrors = JSON.parse(jqXHR.responseText);
|
||||
|
||||
var valErrors = jsonErrors.errors;
|
||||
var errorArray = new Array();
|
||||
var arrayIndex = 0;
|
||||
$.each(jsonErrors, function() {
|
||||
var fieldId = '#' + this.field;
|
||||
$.each(valErrors, function() {
|
||||
var fieldId = '#' + this.parameterName;
|
||||
$(fieldId).addClass("ui-state-error");
|
||||
|
||||
var errorObj = new Object();
|
||||
errorObj.field = this.field;
|
||||
errorObj.code = this.code;
|
||||
errorObj.message = jQuery.i18n.prop(this.code, this.args);
|
||||
errorObj.field = this.parameterName;
|
||||
errorObj.code = this.userMessageGlobalisationCode;
|
||||
|
||||
var argArray = new Array();
|
||||
var argArrayIndex = 0;
|
||||
$.each(this.args, function() {
|
||||
argArray[argArrayIndex] = this.value;
|
||||
argArrayIndex++;
|
||||
});
|
||||
// hardcoded support for six arguments
|
||||
errorObj.message = jQuery.i18n.prop(this.userMessageGlobalisationCode, argArray[0], argArray[1], argArray[2], argArray[3], argArray[4], argArray[5]);
|
||||
errorObj.value = this.value;
|
||||
|
||||
errorArray[arrayIndex] = errorObj;
|
||||
@@ -148,6 +156,29 @@ $(document).ready(function() {
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.serializeObject = function()
|
||||
{
|
||||
var o = {};
|
||||
var a = this.serializeArray();
|
||||
$.each(a, function() {
|
||||
if (o[this.name] !== undefined) {
|
||||
if (!o[this.name].push) {
|
||||
o[this.name] = [o[this.name]];
|
||||
}
|
||||
o[this.name].push(this.value || '');
|
||||
} else {
|
||||
|
||||
if (this.name === 'selectedItems' || this.name === 'notSelectedItems') {
|
||||
o[this.name] = new Array();
|
||||
o[this.name].push(this.value || '');
|
||||
} else {
|
||||
o[this.name] = this.value || '';
|
||||
}
|
||||
}
|
||||
});
|
||||
return o;
|
||||
};
|
||||
|
||||
function showNotAvailableDialog(titleCode) {
|
||||
var dialogDiv = $("<div id='notavailable-dialog-form'></div>");
|
||||
|
||||
@@ -171,16 +202,16 @@ $(document).ready(function() {
|
||||
}).dialog('open');
|
||||
}
|
||||
|
||||
function popupDialogWithFormView(url, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||
function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
url: getUrl,
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
|
||||
console.log(data);
|
||||
var formHtml = $(templateSelector).render(data);
|
||||
|
||||
dialogDiv.append(formHtml);
|
||||
@@ -198,13 +229,16 @@ $(document).ready(function() {
|
||||
$('#selectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: form_data,
|
||||
url: postUrl,
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: saveSuccessFunction,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
@@ -262,7 +296,8 @@ $(document).ready(function() {
|
||||
$("#settings").html(tableHtml);
|
||||
|
||||
$('#changepassword').click(function(e) {
|
||||
var url = '${rootContext}org/admin/settings/password';
|
||||
var getUrl = 'http://localhost:8080/mifosng-provider/api/v1/useraccounts/current/password/template';
|
||||
var putUrl = 'http://localhost:8080/mifosng-provider/api/v1/useraccounts/current/password';
|
||||
var templateSelector = "#changePasswordFormTemplate";
|
||||
var width = 600;
|
||||
var height = 350;
|
||||
@@ -272,13 +307,13 @@ $(document).ready(function() {
|
||||
$("#tabs").tabs('load', 0);
|
||||
}
|
||||
|
||||
popupDialogWithFormView(url, 'dialog.title.update.password', templateSelector, width, height, saveSuccessFunction);
|
||||
popupDialogWithFormView(getUrl, putUrl, 'PUT', 'dialog.title.update.password', templateSelector, width, height, saveSuccessFunction);
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#changedetails').click(function(e) {
|
||||
var url = '${rootContext}org/admin/settings/details';
|
||||
var getAndPutUrl = 'http://localhost:8080/mifosng-provider/api/v1/useraccounts/current';
|
||||
var templateSelector = "#userSettingsFormTemplate";
|
||||
var width = 600;
|
||||
var height = 350;
|
||||
@@ -288,7 +323,7 @@ $(document).ready(function() {
|
||||
$("#tabs").tabs('load', 0);
|
||||
}
|
||||
|
||||
popupDialogWithFormView(url, 'dialog.title.update.details', templateSelector, width, height, saveSuccessFunction);
|
||||
popupDialogWithFormView(getAndPutUrl, getAndPutUrl, 'PUT', 'dialog.title.update.details', templateSelector, width, height, saveSuccessFunction);
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
@@ -309,9 +344,8 @@ $(document).ready(function() {
|
||||
<div id="spacer" style="line-height: 15px;"> </div>
|
||||
<div id="content">
|
||||
<div id="tabs">
|
||||
<c:url value="/org/admin/settings/details" var="currentUserSettingsUrl" />
|
||||
<ul>
|
||||
<li><a href="${currentUserSettingsUrl}" title="settings"><spring:message code="tab.settings"/></a></li>
|
||||
<li><a href="http://localhost:8080/mifosng-provider/api/v1/useraccounts/current" title="settings"><spring:message code="tab.settings"/></a></li>
|
||||
</ul>
|
||||
<div id="settings">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user