use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.
the class UserIdSuggestOracle method requestSuggestions.
@Override
public void requestSuggestions(final Request request, final Callback callback) {
dispatchServiceManager.execute(new GetUserIdCompletionsAction(request.getQuery()), new DispatchServiceCallback<GetPossibleItemCompletionsResult<UserId>>() {
@Override
public void handleSuccess(GetPossibleItemCompletionsResult<UserId> result) {
Collection<Suggestion> suggestions = new ArrayList<>();
for (final UserId userId : result.getPossibleItemCompletions()) {
suggestions.add(new Suggestion() {
@Override
public String getDisplayString() {
String userName = userId.getUserName();
String query = request.getQuery();
int queryIndex = userName.toLowerCase().indexOf(query.toLowerCase());
if (queryIndex != -1) {
return userName.substring(0, queryIndex) + "<span style='font-weight: bold;'>" + userName.substring(queryIndex, queryIndex + query.length()) + "</span>" + userName.substring(queryIndex + query.length());
} else {
return userName;
}
}
@Override
public String getReplacementString() {
return userId.getUserName();
}
});
}
callback.onSuggestionsReady(request, new Response(suggestions));
}
});
}
use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.
the class ResetPasswordActionHandler method execute.
@Nonnull
@Override
public ResetPasswordResult execute(@Nonnull ResetPasswordAction action, @Nonnull ExecutionContext executionContext) {
final String emailAddress = action.getResetPasswordData().getEmailAddress();
try {
Optional<UserId> userId = userDetailsManager.getUserByUserIdOrEmail(emailAddress);
if (!userId.isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
Optional<UserDetails> userDetails = userDetailsManager.getUserDetails(userId.get());
if (!userDetails.isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
if (!userDetails.get().getEmailAddress().isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
if (!userDetails.get().getEmailAddress().get().equalsIgnoreCase(emailAddress)) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
String pwd = IdUtil.getBase62UUID();
Salt salt = saltProvider.get();
SaltedPasswordDigest saltedPasswordDigest = passwordDigestAlgorithm.getDigestOfSaltedPassword(pwd, salt);
authenticationManager.setDigestedPassword(userId.get(), saltedPasswordDigest, salt);
mailer.sendEmail(userId.get(), emailAddress, pwd, ex -> {
throw new RuntimeException(ex);
});
logger.info("The password for {} has been reset. " + "An email has been sent to {} that contains the new password.", userId.get().getUserName(), emailAddress);
return new ResetPasswordResult(SUCCESS);
} catch (Exception e) {
logger.error("Could not reset the user password " + "associated with the email " + "address {}. The following " + "error occurred: {}.", emailAddress, e.getMessage(), e);
return new ResetPasswordResult(INTERNAL_ERROR);
}
}
use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.
the class GetChapSessionActionHandler method execute.
@Nonnull
@Override
public GetChapSessionResult execute(@Nonnull GetChapSessionAction action, @Nonnull ExecutionContext executionContext) {
UserId userId = action.getUserId();
if (userId.isGuest()) {
logger.info("Attempt at authenticating guest user");
return new GetChapSessionResult(Optional.empty());
}
Optional<Salt> salt = authenticationManager.getSalt(userId);
if (!salt.isPresent()) {
logger.info("Attempt to authenticate non-existing user: {}", userId);
return new GetChapSessionResult(Optional.empty());
}
ChapSession challengeMessage = chapSessionManager.getSession(salt.get());
return new GetChapSessionResult(Optional.of(challengeMessage));
}
use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.
the class PerspectiveLinkManagerImpl method addLinkedPerspective.
public void addLinkedPerspective(final PerspectiveId perspectiveId, final Callback callback) {
final UserId userId = loggedInUserProvider.getCurrentUserId();
dispatchServiceManager.execute(new GetPerspectivesAction(projectId, userId), new DispatchServiceCallback<GetPerspectivesResult>() {
@Override
public void handleSuccess(GetPerspectivesResult result) {
List<PerspectiveId> ids = new ArrayList<>(result.getPerspectives());
ids.add(perspectiveId);
final ImmutableList<PerspectiveId> perspectiveIds = ImmutableList.copyOf(ids);
dispatchServiceManager.execute(new SetPerspectivesAction(projectId, userId, perspectiveIds), new DispatchServiceCallback<SetPerspectivesResult>() {
@Override
public void handleSuccess(SetPerspectivesResult setPerspectivesResult) {
callback.handlePerspectives(perspectiveIds);
}
});
}
});
}
use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.
the class PerspectiveLinkManagerImpl method getLinkedPerspectives.
public void getLinkedPerspectives(final Callback callback) {
final UserId userId = loggedInUserProvider.getCurrentUserId();
dispatchServiceManager.execute(new GetPerspectivesAction(projectId, userId), new DispatchServiceCallback<GetPerspectivesResult>() {
@Override
public void handleSuccess(GetPerspectivesResult result) {
callback.handlePerspectives(result.getPerspectives());
}
});
}
Aggregations