All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rocketbase.commons.resource.ForgotPasswordResource Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package io.rocketbase.commons.resource;

import io.rocketbase.commons.dto.forgot.ForgotPasswordRequest;
import io.rocketbase.commons.dto.forgot.PerformPasswordResetRequest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

public class ForgotPasswordResource implements BaseRestResource {

    protected String baseAuthApiUrl;
    protected RestTemplate restTemplate;

    public ForgotPasswordResource(String baseAuthApiUrl) {
        this(baseAuthApiUrl, null);
    }

    public ForgotPasswordResource(String baseAuthApiUrl, RestTemplate restTemplate) {
        Assert.hasText(baseAuthApiUrl, "baseAuthApiUrl is required");
        this.baseAuthApiUrl = baseAuthApiUrl;
        this.restTemplate = restTemplate;
    }

    protected RestTemplate getRestTemplate() {
        if (restTemplate == null) {
            restTemplate = new RestTemplate();
            restTemplate.setErrorHandler(new BasicResponseErrorHandler());
        }
        return restTemplate;
    }

    public void forgotPassword(ForgotPasswordRequest forgotPassword) {
        ResponseEntity response = getRestTemplate()
                .exchange(UriComponentsBuilder.fromUriString(ensureEndsWithSlash(baseAuthApiUrl))
                                .path("/auth/forgot-password").toUriString(),
                        HttpMethod.PUT,
                        new HttpEntity<>(forgotPassword),
                        Void.class);
    }

    public void resetPassword(PerformPasswordResetRequest performPasswordReset) {
        ResponseEntity response = getRestTemplate()
                .exchange(UriComponentsBuilder.fromUriString(ensureEndsWithSlash(baseAuthApiUrl))
                                .path("/auth/reset-password").toUriString(),
                        HttpMethod.PUT,
                        new HttpEntity<>(performPasswordReset),
                        Void.class);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy