Search in sources :

Example 1 with ConfirmEmailInitResponse

use of edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse in project dataverse by IQSS.

the class Admin method startConfirmEmailProcess.

/**
 * This method is used in integration tests.
 *
 * @param userId The database id of an AuthenticatedUser.
 */
@Path("confirmEmail/{userId}")
@POST
public Response startConfirmEmailProcess(@PathParam("userId") long userId) {
    AuthenticatedUser user = authSvc.findByID(userId);
    if (user != null) {
        try {
            ConfirmEmailInitResponse confirmEmailInitResponse = confirmEmailSvc.beginConfirm(user);
            ConfirmEmailData confirmEmailData = confirmEmailInitResponse.getConfirmEmailData();
            return ok(Json.createObjectBuilder().add("tokenCreated", confirmEmailData.getCreated().toString()).add("identifier", user.getUserIdentifier()));
        } catch (ConfirmEmailException ex) {
            return error(Status.BAD_REQUEST, "Could not start confirm email process for user " + userId + ": " + ex.getLocalizedMessage());
        }
    }
    return error(Status.BAD_REQUEST, "Could not find user based on " + userId);
}
Also used : ConfirmEmailException(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException) ConfirmEmailInitResponse(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) ConfirmEmailData(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 ConfirmEmailData (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData)1 ConfirmEmailException (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException)1 ConfirmEmailInitResponse (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1