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();
}
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);
}
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();
}
Aggregations