use of com.google.api.server.spi.response.NotFoundException in project cryptonomica by Cryptonomica.
the class StripePaymentsAPI method checkPaymentVerificationCode.
// end of processStripePayment
@ApiMethod(name = "checkPaymentVerificationCode", path = "checkPaymentVerificationCode", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject checkPaymentVerificationCode(final HttpServletRequest httpServletRequest, final User googleUser, @Named("fingerprint") final String fingerprint, @Named("paymentVerificationCode") final String paymentVerificationCode) throws Exception {
/* --- Ensure cryptonomica registered user */
final CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* record login: */
Login login = UserTools.registerLogin(httpServletRequest, googleUser);
/* --- Check form: */
LOG.warning("paymentVerificationCode from user: " + paymentVerificationCode);
/* --- create return object */
StringWrapperObject result = new StringWrapperObject();
/* --- get OpenPGP key data */
PGPPublicKeyData pgpPublicKeyData = null;
pgpPublicKeyData = ofy().load().type(PGPPublicKeyData.class).filter("fingerprintStr", fingerprint).first().now();
//
if (pgpPublicKeyData == null) {
throw new Exception("OpenPGP public key certificate not found in our database for " + fingerprint);
}
//
if (!pgpPublicKeyData.getUserEmail().getEmail().equalsIgnoreCase(cryptonomicaUser.getEmail().getEmail())) {
throw new Exception("Google Account email and email in key certificate does not much");
}
// first check for null:
if (pgpPublicKeyData.getPaid() != null && pgpPublicKeyData.getPaid()) {
throw new Exception("Verification of key " + fingerprint + " already paid");
}
//
StripePaymentForKeyVerification stripePaymentForKeyVerification = null;
List<StripePaymentForKeyVerification> paymentForKeyVerificationList = ofy().load().type(StripePaymentForKeyVerification.class).filter("fingerprint", fingerprint).list();
if (paymentForKeyVerificationList == null || paymentForKeyVerificationList.size() < 1) {
throw new Exception("No payments for verification of the key " + fingerprint + "found");
} else if (paymentForKeyVerificationList.size() > 1) {
throw new Exception("Multiple payments exist for the key: " + fingerprint + ", please write to support@cryptonomica.net");
} else {
stripePaymentForKeyVerification = paymentForKeyVerificationList.get(0);
}
OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
if (onlineVerification == null) {
throw new NotFoundException("OnlineVerification record not found in data base");
}
if (stripePaymentForKeyVerification.getPaymentVerificationCode().equalsIgnoreCase(paymentVerificationCode)) {
stripePaymentForKeyVerification.setVerified(true);
Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
Key<Login> loginKey = Key.create(cryptonomicaUserKey, Login.class, login.getId());
stripePaymentForKeyVerification.setCheckPaymentVerificationCodeLogin(loginKey);
// async
ofy().save().entity(stripePaymentForKeyVerification);
// add data to PGP Public Key and save:
pgpPublicKeyData.setPaid(true);
ofy().save().entity(pgpPublicKeyData).now();
// add data to OnlineVerification and save:
// onlineVerification.setPaimentVerified(Boolean.TRUE);
onlineVerification.setPaymentVerified(Boolean.TRUE);
// <<<<<<<<<< set as ready to manual review
onlineVerification.setOnlineVerificationFinished(Boolean.TRUE);
// async
ofy().save().entity(onlineVerification);
result.setMessage("Code verified!");
} else {
stripePaymentForKeyVerification.setFailedVerificationAttemps(stripePaymentForKeyVerification.getFailedVerificationAttemps() + 1);
if (stripePaymentForKeyVerification.getFailedVerificationAttemps() >= 5) {
throw new Exception("The number of attempts is exhausted. Please, write to support@cryptonomica.net");
} else {
throw new Exception("Code does not much. It was attempt # " + stripePaymentForKeyVerification.getFailedVerificationAttemps());
}
}
// On this step user completed entering verification data, send email to compliance:
ArrayList<VerificationDocument> verificationDocumentArrayList = new ArrayList<>();
int verificationDocumentsListSize = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list().size();
LOG.warning("verificationDocumentsListSize: " + verificationDocumentsListSize);
if (verificationDocumentsListSize > 0) {
List<VerificationDocument> verificationDocumentList = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list();
verificationDocumentArrayList.addAll(verificationDocumentList);
LOG.warning(GSON.toJson(verificationDocumentArrayList));
}
OnlineVerificationView onlineVerificationView = new OnlineVerificationView(onlineVerification, verificationDocumentArrayList);
Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
final Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/_ah/SendGridServlet").param("email", "verification@cryptonomica.net").param("messageSubject", "[verification] Request for online verification").param("messageText", "New request for online verification received: \n\n" + "see entered data on:\n" + "https://cryptonomica.net/#/onlineVerificationView/" + fingerprint + "\n\n" + "verification request data in JSON format: \n\n" + prettyGson.toJson(onlineVerificationView)));
return result;
}
use of com.google.api.server.spi.response.NotFoundException in project cryptonomica by Cryptonomica.
the class VerificationAPI method getVerificationByWebSafeString.
// end: getVerificationByID
/* --- Get verification info by web-safe key string: */
@ApiMethod(name = "getVerificationByWebSafeString", path = "getVerificationByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByWebSafeString(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationWebSafeString") final String verificationWebSafeString) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Check input: */
if (verificationWebSafeString == null || verificationWebSafeString.equals("")) {
throw new BadRequestException("Verification ID missing");
}
/* --- Load verification entity from DS: */
Key<Verification> verificationKey = Key.create(verificationWebSafeString);
Verification verification = ofy().load().key(verificationKey).now();
if (verification == null) {
throw new NotFoundException("Verification info not found");
}
/* --- Create new verification info representation: */
VerificationGeneralView verificationGeneralView = new VerificationGeneralView(verification);
LOG.warning(new Gson().toJson(verificationGeneralView));
return verificationGeneralView;
}
use of com.google.api.server.spi.response.NotFoundException in project iosched by google.
the class FcmSendEndpoint method sendUserSync.
/**
* Ping a user's devices to sync user data. This is likely called when the server makes
* a change to user data and wants the corresponding user's clients to sync.
*
* @param context Servlet context (injected by Endpoints)
* @param user User making the request (injected by Endpoints)
* @param userId ID of the user whose devices should sync.
* @return SendUserSyncResult which contains the number of devices pinged.
*/
@ApiMethod(name = "sendUserSync", path = "users/{userId}", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public SendUserSyncResult sendUserSync(ServletContext context, User user, @Named("userId") String userId) throws UnauthorizedException, NotFoundException {
validateServiceAccount(user);
MessageSender sender = new MessageSender(context);
List<Device> devices = DeviceStore.findDevicesByUserId(userId);
if (devices.isEmpty()) {
throw new NotFoundException("No devices for user found");
}
sender.multicastSend(devices, ACTION_SYNC_USER, null);
return new SendUserSyncResult(devices.size());
}
use of com.google.api.server.spi.response.NotFoundException in project endpoints-java by cloudendpoints.
the class LocalDiscoveryProvider method getRestDocument.
@Override
public RestDescription getRestDocument(String root, String name, String version) throws NotFoundException {
ensureDiscoveryResult();
RestDescription doc = discoveryDocs.get(new ApiKey(name, version, null));
if (doc == null) {
throw new NotFoundException("Not Found");
}
return replaceRoot(doc, root);
}
use of com.google.api.server.spi.response.NotFoundException in project endpoints-java by cloudendpoints.
the class AbstractDiscoveryProvider method getApiConfigs.
ImmutableList<ApiConfig> getApiConfigs(String name, String version) throws NotFoundException {
ApiKey key = new ApiKey(name, version, null);
ImmutableList<ApiConfig> configs = configsByKey.get(key);
if (configs.isEmpty()) {
logger.atInfo().log("No configuration found for name: %s, version: %s", name, version);
throw new NotFoundException("Not Found");
}
return configs;
}
Aggregations