Search in sources :

Example 1 with InvalidTokenException

use of com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException 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 2 with InvalidTokenException

use of com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException 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 3 with InvalidTokenException

use of com.networknt.portal.usermanagement.model.common.exception.InvalidTokenException 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

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