use of com.google.gerrit.server.mail.send.RegisterNewEmailSender in project gerrit by GerritCodeReview.
the class CreateEmail method apply.
public Response<EmailInfo> apply(IdentifiedUser user, EmailInput input) throws AuthException, BadRequestException, ResourceConflictException, ResourceNotFoundException, OrmException, EmailException, MethodNotAllowedException, IOException, ConfigInvalidException, PermissionBackendException {
if (input.email != null && !email.equals(input.email)) {
throw new BadRequestException("email address must match URL");
}
EmailInfo info = new EmailInfo();
info.email = email;
if (input.noConfirmation || isDevMode) {
if (isDevMode) {
log.warn("skipping email validation in developer mode");
}
try {
accountManager.link(user.getAccountId(), AuthRequest.forEmail(email));
} catch (AccountException e) {
throw new ResourceConflictException(e.getMessage());
}
if (input.preferred) {
putPreferred.apply(new AccountResource.Email(user, email), null);
info.preferred = true;
}
} else {
try {
RegisterNewEmailSender sender = registerNewEmailFactory.create(email);
if (!sender.isAllowed()) {
throw new MethodNotAllowedException("Not allowed to add email address " + email);
}
sender.send();
info.pendingConfirmation = true;
} catch (EmailException | RuntimeException e) {
log.error("Cannot send email verification message to " + email, e);
throw e;
}
}
return Response.created(info);
}
Aggregations