Source:
protected ViewModel onValidSubmit(HttpServletRequest request, HttpServletResponse response, Form form) throws Exception { String password = form.getFieldValue("password"); Application application = (Application) request.getAttribute(Application.class.getName()); String sptoken = form.getFieldValue("sptoken"); if (isJsonPreferred(request, response)) { Map<String, Object> model = new HashMap<>(); try { Account account = application.resetPassword(sptoken, password); if (autoLogin) { final AuthenticationResult result = new TransientAuthenticationResult(account); this.authenticationResultSaver.set(request, response, result); model.put("account", accountModelFactory.toMap(account, Collections.EMPTY_LIST)); } else { response.setContentType(MediaType.APPLICATION_JSON_VALUE); return null; } } catch (Exception e) { model = errorModelFactory.toError(request, e).toMap(); response.setStatus(errorModelFactory.toError(request, e).getStatus()); } return new DefaultViewModel(View.STORMPATH_JSON_VIEW_NAME, model); } String next; try { Account account = application.resetPassword(sptoken, password); if (autoLogin) { final AuthenticationResult result = new TransientAuthenticationResult(account); this.authenticationResultSaver.set(request, response, result); next = this.loginNextUri; } else { next = this.nextUri; } } catch (ResourceException e) { if (e.getCode() == HttpStatus.SC_NOT_FOUND) { next = this.errorUri; } else { ErrorModel errorModel = errorModelFactory.toError(request, e); next = getUri() + "?sptoken=" + sptoken + "&error=" + URLEncoder.encode(errorModel.getMessage(), "UTF-8"); } } return new DefaultViewModel(next).setRedirect(true); }

Target:
protected ViewModel onValidSubmit(HttpServletRequest request, HttpServletResponse response, Form form) throws Exception { String password = form.getFieldValue("password"); Application application = (Application) request.getAttribute(Application.class.getName()); String sptoken = form.getFieldValue("sptoken"); if (isJsonPreferred(request, response)) { Map<String, Object> model = new HashMap<>(); try { Account account = application.resetPassword(sptoken, password); if (autoLogin) { final AuthenticationResult result = new TransientAuthenticationResult(account); this.authenticationResultSaver.set(request, response, result); model.put("account", accountModelFactory.toMap(account, Collections.EMPTY_LIST)); } else { response.setContentType(MediaType.APPLICATION_JSON_VALUE); return null; } } catch (Exception e) { model = errorModelFactory.toError(request, e).toMap(); response.setStatus(errorModelFactory.toError(request, e).getStatus()); } return new DefaultViewModel(View.STORMPATH_JSON_VIEW_NAME, model); } String next; try { Account account = application.resetPassword(sptoken, password); if (autoLogin) { final AuthenticationResult result = new TransientAuthenticationResult(account); this.authenticationResultSaver.set(request, response, result); next = this.loginNextUri; } else { next = this.nextUri; } } catch (ResourceException e) { if (e.getCode() == HttpStatus.SC_NOT_FOUND) { next = this.errorUri; } else { ErrorModel errorModel = errorModelFactory.toError(request, e); next = getUri() + "?sptoken=" + sptoken + "&error=" + URLEncoder.encode(errorModel.getMessage(), "UTF-8"); } } catch (Exception e) { log.error("Caught exception: {}. Redirecting to: {}", e.getMessage(), errorUri, e); next = errorUri; } return new DefaultViewModel(next).setRedirect(true); }