Search in sources :

Example 1 with NoSuchUserException

use of com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException in project light-portal by networknt.

the class UserIdPutHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    String id = exchange.getQueryParameters().get("id").getFirst();
    ObjectMapper mapper = new ObjectMapper();
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    UserDto user = mapper.readValue(json, UserDto.class);
    User userResult = null;
    try {
        if (user.isEmailChange()) {
            userResult = service.changeEmail(id, user.getContactData().getEmail());
        } else if (user.isPasswordReset()) {
            userResult = service.changePassword(id, user.getPassword());
        } else if (user.isScreenNameChange()) {
            userResult = service.changeScreenName(id, user.getScreenName());
        } else {
            userResult = service.fromUserDto(user);
            userResult.setId(id);
            userResult = service.update(userResult);
        }
    } catch (NoSuchUserException e) {
    // TODO handler excption, add log info?
    }
    String result;
    if (userResult == null) {
        result = "no user changed;";
    } else {
        result = Config.getInstance().getMapper().writeValueAsString(service.toUserDto(userResult));
    }
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(result);
// exchange.endExchange();
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) HttpString(io.undertow.util.HttpString) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpString(io.undertow.util.HttpString)

Example 2 with NoSuchUserException

use of com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException in project light-portal by networknt.

the class UserLoginPutHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    LoginForm login = mapper.readValue(json, LoginForm.class);
    User userResult = null;
    try {
        if (login.getToken() != null) {
            userResult = service.confirmPasswordReset(login.getNameOrEmail(), login.getToken());
        }
        userResult = service.login(login.getNameOrEmail(), login.getPassword());
    } catch (NoSuchUserException e) {
    // TODO handler excption, add log info?
    } catch (InvalidTokenException e) {
    // TODO handler excption, add log info?
    }
    String result;
    if (userResult == null) {
        result = "Login failed, please re-try or contact to admin;";
    } else {
        result = "Login successfully: \n" + mapper.writeValueAsString(service.toUserDto(userResult));
    // TODO get session???
    }
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
Also used : InvalidTokenException(com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException) User(com.networknt.portal.usermanagement.model.common.model.user.User) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) HttpString(io.undertow.util.HttpString) LoginForm(com.networknt.portal.usermanagement.model.LoginForm) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpString(io.undertow.util.HttpString)

Example 3 with NoSuchUserException

use of com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException in project light-portal by networknt.

the class UserQueryWorkflow method update.

@EventHandlerMethod
public void update(DispatchedEvent<UserUpdatedEvent> de) {
    String id = de.getEntityId();
    UserDto user = de.getEvent().getUserDto();
    User userResult = null;
    try {
        if (user.isEmailChange()) {
            userResult = service.changeEmail(id, user.getContactData().getEmail());
        } else if (user.isPasswordReset()) {
            userResult = service.changePassword(id, user.getPassword());
        } else if (user.isScreenNameChange()) {
            userResult = service.changeScreenName(id, user.getScreenName());
        } else {
            userResult = service.fromUserDto(user);
            userResult.setId(id);
            userResult = service.update(userResult);
        }
    } catch (NoSuchUserException e) {
        logger.info("No Such User Error", id, e.getMessage());
    } catch (InvalidEmailException e) {
        logger.info("Invalid Email Error", id, e.getMessage());
    } catch (Exception e) {
        logger.info("Error on update user:", id, e.getMessage());
    }
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) EventHandlerMethod(com.networknt.eventuate.common.EventHandlerMethod)

Example 4 with NoSuchUserException

use of com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException in project light-portal by networknt.

the class ConfirmUser method handle.

@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
    ResponseResult response = new ResponseResult();
    String tokenId = ((Map<String, String>) input).get("tokenId");
    System.out.println("token:" + tokenId);
    String result = null;
    try {
        User user = service.confirmEmail(tokenId);
        if (user == null) {
            response.setCompleted(false);
            response.setMessage("no user active by the token");
        } else {
            response.setCompleted(true);
            response.setMessage("user active completed: " + user.getScreenName());
        }
        result = Config.getInstance().getMapper().writeValueAsString(response);
    } catch (NoSuchUserException e) {
        result = "no Such User";
    } catch (InvalidTokenException e) {
        result = "Invalid Token";
    } catch (Exception e) {
        logger.error("login system error:" + e);
    }
    return NioUtils.toByteBuffer(result);
}
Also used : InvalidTokenException(com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException) User(com.networknt.portal.usermanagement.model.common.model.user.User) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) Map(java.util.Map) InvalidTokenException(com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException)

Example 5 with NoSuchUserException

use of com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException in project light-portal by networknt.

the class UserLoginPutHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    LoginForm login = mapper.readValue(json, LoginForm.class);
    User userResult = null;
    try {
        if (login.getToken() != null) {
            userResult = service.confirmPasswordReset(login.getNameOrEmail(), login.getToken());
        }
        userResult = service.login(login.getNameOrEmail(), login.getPassword());
    } catch (NoSuchUserException e) {
    // TODO handler excption, add log info?
    } catch (InvalidTokenException e) {
    // TODO handler excption, add log info?
    }
    String result;
    if (userResult == null) {
        result = "Login failed, please re-try or contact to admin;";
    } else {
        result = "Login successfully: \n" + service.toUserDto(userResult);
    // TODO get session???
    }
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
Also used : InvalidTokenException(com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException) User(com.networknt.portal.usermanagement.model.common.model.user.User) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) HttpString(io.undertow.util.HttpString) LoginForm(com.networknt.portal.usermanagement.restquery.model.LoginForm) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpString(io.undertow.util.HttpString)

Aggregations

NoSuchUserException (com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException)6 User (com.networknt.portal.usermanagement.model.common.model.user.User)6 HttpString (io.undertow.util.HttpString)4 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 InvalidTokenException (com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException)3 UserDto (com.networknt.portal.usermanagement.model.common.domain.UserDto)2 HashMap (java.util.HashMap)2 EventHandlerMethod (com.networknt.eventuate.common.EventHandlerMethod)1 LoginForm (com.networknt.portal.usermanagement.model.LoginForm)1 InvalidEmailException (com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException)1 LoginForm (com.networknt.portal.usermanagement.restquery.model.LoginForm)1