Skip to content

Commit

Permalink
Add API to allow self service user to change their password
Browse files Browse the repository at this point in the history
  • Loading branch information
rajuan committed Oct 25, 2016
1 parent 525e8be commit b3c4f75
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
40 changes: 40 additions & 0 deletions api-docs/apiLive.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3360,6 +3360,14 @@ <h2 class="flybar-button">Self Service</h2>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="#selfuser">Update User</a></td>
<td>self/user</td>
<td></td>
<td></td>
<td><a href="#selfuser">Update User</a></td>
<td></td>
</tr>
<tr>
<td><a href="#selflistclients">Clients</a></td>
<td>self/clients</td>
Expand Down Expand Up @@ -42919,6 +42927,38 @@ <h4>Fetch authenticated user details </h4>
</div>
</div>

<a id="selfuser" name="selfuser" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Update User</h4>
<p>This API can be used by Self Service user to update their own user information. Currently, "password" and "repeatPassword" are the only parameters accepted.</p>
</div>
<div class="method-example">
<code class="method-declaration">
PUT https://DomainName/api/v1/self/user
</code>
<code class="method-request">
PUT self/user
Content-Type: application/json

{
"password":"Abcd1234",
"repeatPassword":"Abcd1234"
}
</code>
<p>Example response</p>
<code class="method-response">
{
"officeId": 1,
"resourceId": 6,
"changes": {
"passwordEncoded": "6a72a630795be86fe926ce540fc45b6b922fe5ba130f185fe806a26b5e5efcdd"
}
}
</code>
</div>
</div>

<a id="selflistclients" name="selflistclients" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fineract.portfolio.self.security.api;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.PUT;
import javax.ws.rs.Path;

import org.apache.commons.lang.StringUtils;
import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.api.UsersApiResource;
import org.apache.fineract.useradministration.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.gson.reflect.TypeToken;

@Path("/self/user")
@Component
public class SelfUserApiResource {

private final UsersApiResource usersApiResource;
private final PlatformSecurityContext context;
private final FromJsonHelper fromApiJsonHelper;
private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("password", "repeatPassword"));

@Autowired
public SelfUserApiResource(final UsersApiResource usersApiResource,
final PlatformSecurityContext context,
final FromJsonHelper fromApiJsonHelper){

this.usersApiResource = usersApiResource;
this.context = context;
this.fromApiJsonHelper = fromApiJsonHelper;
}

@PUT
public String update(final String apiRequestBodyAsJson) {
if (StringUtils.isBlank(apiRequestBodyAsJson)) { throw new InvalidJsonException(); }

final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap,
apiRequestBodyAsJson,
this.supportedParameters);

final AppUser appUser = this.context.authenticatedUser();
return this.usersApiResource.update(appUser.getId(), apiRequestBodyAsJson);
}

}

0 comments on commit b3c4f75

Please sign in to comment.