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