Search in sources :

Example 6 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationController method signUp.

@PostMapping({ "/v3/auth/signUp", "/api/v1/auth/signUp" })
@ResponseStatus(HttpStatus.CREATED)
public StatusMessage signUp() {
    JsonNode node = parseJson(JsonNode.class);
    StudyParticipant participant = parseJson(node, StudyParticipant.class);
    String appId = JsonUtils.asText(node, APP_ID_PROPERTY, STUDY_PROPERTY);
    getMetrics().setAppId(appId);
    App app = getAppOrThrowException(appId);
    authenticationService.signUp(app, participant);
    return new StatusMessage("Signed up.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) JsonNode(com.fasterxml.jackson.databind.JsonNode) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 7 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationController method requestResetPassword.

@PostMapping({ "/v3/auth/requestResetPassword", "/api/v1/auth/requestResetPassword" })
@ResponseStatus(HttpStatus.ACCEPTED)
public StatusMessage requestResetPassword() {
    SignIn signIn = parseJson(SignIn.class);
    App app = appService.getApp(signIn.getAppId());
    verifySupportedVersionOrThrowException(app);
    authenticationService.requestResetPassword(app, false, signIn);
    // Email is chosen over phone number, so if email was provided, respond as if we used it.
    if (signIn.getEmail() != null) {
        return new StatusMessage(EMAIL_RESET_PWD_MSG);
    }
    return new StatusMessage(PHONE_RESET_PWD_MSG);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 8 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationController method signOutV4.

@PostMapping("/v4/auth/signOut")
public StatusMessage signOutV4() {
    final UserSession session = getSessionIfItExists();
    // Always set, even if we eventually decide to return an error code when there's no session
    Cookie cookie = HttpUtil.makeSessionCookie("", 0);
    response().addCookie(cookie);
    response().setHeader(CLEAR_SITE_DATA_HEADER, CLEAR_SITE_DATA_VALUE);
    if (session != null) {
        authenticationService.signOut(session);
    } else {
        throw new BadRequestException("Not signed in");
    }
    return new StatusMessage("Signed out.");
}
Also used : Cookie(javax.servlet.http.Cookie) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationController method resendPhoneVerification.

@PostMapping("/v3/auth/resendPhoneVerification")
@ResponseStatus(HttpStatus.ACCEPTED)
public StatusMessage resendPhoneVerification() {
    AccountId accountId = parseJson(AccountId.class);
    // Must be here to get the correct exception if app property is missing
    getAppOrThrowException(accountId.getUnguardedAccountId().getAppId());
    authenticationService.resendVerification(ChannelType.PHONE, accountId);
    return new StatusMessage(PHONE_VERIFY_REQUEST_MSG);
}
Also used : AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 10 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantControllerTest method createCustomActivityEvent.

@Test
public void createCustomActivityEvent() throws Exception {
    CustomActivityEventRequest request = new CustomActivityEventRequest.Builder().withEventKey("eventKey").withTimestamp(TIMESTAMP).build();
    mockRequestBody(mockRequest, request);
    StatusMessage retValue = controller.createCustomActivityEvent(TEST_USER_ID);
    assertEquals(retValue.getMessage(), "Event recorded.");
    verify(mockParticipantService).createCustomActivityEvent(eq(app), eq(TEST_USER_ID), eventRequestCaptor.capture());
    CustomActivityEventRequest captured = eventRequestCaptor.getValue();
    assertEquals(captured.getEventKey(), "eventKey");
    assertEquals(captured.getTimestamp(), TIMESTAMP);
}
Also used : CustomActivityEventRequest(org.sagebionetworks.bridge.models.activities.CustomActivityEventRequest) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Aggregations

StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)239 Test (org.testng.annotations.Test)168 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)58 PostMapping (org.springframework.web.bind.annotation.PostMapping)43 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)36 App (org.sagebionetworks.bridge.models.apps.App)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)23 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)22 Account (org.sagebionetworks.bridge.models.accounts.Account)21 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)13 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)12 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)11 RequestContext (org.sagebionetworks.bridge.RequestContext)10 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)10 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)9 Cookie (javax.servlet.http.Cookie)6 Appointment (org.hl7.fhir.dstu3.model.Appointment)6 NotificationMessage (org.sagebionetworks.bridge.models.notifications.NotificationMessage)6