Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implimented requestpasswordreset endpoint to receive either email o… #334

merged 7 commits into from Aug 10, 2018
Copy path View file
@@ -11,7 +11,7 @@
<description>OpenMRS module project for Rest Web Services</description>


@@ -0,0 +1,71 @@
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.

import java.util.Map;

import org.openmrs.User;
import org.openmrs.api.InvalidActivationKeyException;
import org.openmrs.api.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;

@RequestMapping(value = "/rest/" + RestConstants.VERSION_1)

This comment has been minimized.

Copy link

wluyima Aug 2, 2018


You are missing the resource name passwordreset

public class PasswordResetController extends BaseRestController {

private UserService userService;

@RequestMapping(value = "/requestpasswordreset", method = RequestMethod.POST)
public void requestPasswordReset(@RequestBody Map<String, String> body) {
User user = null;

if (body.containsKey("email")) {
String email = body.get("email");
user = userService.getUserByEmail(email);
else if (body.containsKey("username")) {
String userName = body.get("username");
user = userService.getUserByUsername(userName);

if (user != null) {

@RequestMapping(value = "/resetpasswordrequest", method = RequestMethod.POST)
public void resetPassword(@RequestBody Map<String, String> body) {
String newPassword = body.get("newPassword");

String token = body.get("token");

try {
userService.changeUserPasswordUsingActivationKey(token, newPassword);
catch (InvalidActivationKeyException ex) {


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.