Search in sources :

Example 1 with ConfirmationToken

use of com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken in project light-portal by networknt.

the class UserPostHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    // add a new object
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    UserDto userDto = mapper.readValue(json, UserDto.class);
    String result = "Ok!";
    try {
        User user = service.fromUserDto(userDto);
        service.signup(user, userDto.getPassword(), false);
        // TODO remove the following implemetation after confirm email implemented
        Optional<ConfirmationToken> token = user.getConfirmationTokens().stream().findFirst();
        if (token.isPresent()) {
            result = "http://localhost:8080/v1/user/token/" + token.get().getId();
        }
    } catch (Exception e) {
        result = e.getMessage();
    // TODO handler excption, add log info?
    }
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) ConfirmationToken(com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpString(io.undertow.util.HttpString) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) HttpString(io.undertow.util.HttpString)

Example 2 with ConfirmationToken

use of com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken in project light-portal by networknt.

the class UserQueryWorkflow method create.

@EventHandlerMethod
public void create(DispatchedEvent<UserSignUpEvent> de) {
    UserSignUpEvent event = de.getEvent();
    String id = de.getEntityId();
    UserDto userDto = event.getUserDto();
    Int128 eventId = de.getEventId();
    logger.info("**************** account version={}, {}", id, eventId);
    String json = JSonMapper.toJson(userDto);
    try {
        User user = service.fromUserDto(userDto, id);
        service.signup(user, userDto.getPassword(), true);
        // TODO remove the following implemetation after confirm email implemented
        Optional<ConfirmationToken> token = user.getConfirmationTokens().stream().findFirst();
        if (token.isPresent()) {
            // TODO send email
            System.out.println("Link in the email:\n" + "http://localhost:8081/v1/user/token/" + user.getId() + "?token=" + token.get().getId());
        }
    } catch (Exception e) {
        System.out.println("error:" + e.getMessage());
        logger.error("user signup failed:", userDto + " error:" + e.getMessage());
    // TODO handler excption, add log info?
    }
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) ConfirmationToken(com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) UserSignUpEvent(com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent) Int128(com.networknt.eventuate.common.Int128) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) EventHandlerMethod(com.networknt.eventuate.common.EventHandlerMethod)

Aggregations

UserDto (com.networknt.portal.usermanagement.model.common.domain.UserDto)2 NoSuchUserException (com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException)2 ConfirmationToken (com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken)2 User (com.networknt.portal.usermanagement.model.common.model.user.User)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EventHandlerMethod (com.networknt.eventuate.common.EventHandlerMethod)1 Int128 (com.networknt.eventuate.common.Int128)1 UserSignUpEvent (com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent)1 InvalidEmailException (com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException)1 HttpString (io.undertow.util.HttpString)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1