use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class OnlineVerificationAPI method sendTestSms.
// end: getDocumentsUploadKey
/* --- Test SMS service: */
@ApiMethod(name = "sendTestSms", path = "sendTestSms", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject sendTestSms(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("phoneNumber") final String phoneNumber, @Named("smsMessage") final String smsMessage) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException, NumberParseException, IllegalArgumentException, TwilioRestException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Send SMS */
Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);
return new StringWrapperObject(message.toJSON());
}
use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class OnlineVerificationAPI method checkSms.
// end of sendTestSms();
/* --- Check SMS */
@ApiMethod(name = "checkSms", path = "checkSms", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject checkSms(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("smsMessage") final String smsMessage, @Named("fingerprint") final String fingerprint) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException, NumberParseException, IllegalArgumentException, TwilioRestException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Check if OnlineVerificaiton entity exists */
OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
if (onlineVerification == null) {
throw new NotFoundException("OnlineVerification entity does not exist in data base");
}
// --- store SMS:
PhoneVerification phoneVerification = null;
phoneVerification = ofy().load().key(Key.create(PhoneVerification.class, fingerprint)).now();
if (phoneVerification == null) {
throw new NotFoundException("Send sms message not found for key " + fingerprint);
}
LOG.warning("phoneVerification.getSmsMessage(): " + phoneVerification.getSmsMessage());
LOG.warning("smsMessage: " + smsMessage);
Boolean verificationResult = phoneVerification.getSmsMessage().toString().equalsIgnoreCase(smsMessage);
phoneVerification.setVerified(verificationResult);
StringWrapperObject result = new StringWrapperObject();
if (verificationResult) {
result.setMessage("Phone verified!");
} else {
phoneVerification.setFailedVerificationAttemps(phoneVerification.getFailedVerificationAttemps() + 1);
ofy().save().entity(phoneVerification).now();
if (phoneVerification.getFailedVerificationAttemps() >= 3) {
throw new BadRequestException("The number of attempts is exhausted. Please resend new sms");
} else {
throw new BadRequestException("Code does not much. It was attempt # " + phoneVerification.getFailedVerificationAttemps());
}
}
// save phone verification
ofy().save().entity(phoneVerification).now();
// record to verification
onlineVerification.setPhoneNumber(phoneVerification.getPhoneNumber());
ofy().save().entity(onlineVerification).now();
return result;
}
use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class OnlineVerificationAPI method sendSms.
// end of sendTestSms();
/* --- Send SMS : */
@ApiMethod(name = "sendSms", path = "sendSms", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject sendSms(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("phoneNumber") final String phoneNumber, // in international format, f.e. +972523333333
@Named("fingerprint") final String fingerprint) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException, NumberParseException, IllegalArgumentException, TwilioRestException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
// --- create SMS:
String smsMessage = RandomStringUtils.randomNumeric(7);
LOG.warning("smsMessage: " + smsMessage);
// --- store SMS:
PhoneVerification phoneVerification = null;
phoneVerification = ofy().load().key(Key.create(PhoneVerification.class, fingerprint)).now();
if (phoneVerification == null) {
phoneVerification = new PhoneVerification(fingerprint);
}
if (phoneVerification.getVerified()) {
throw new BadRequestException("Phone already verified for this OpenPGP public key " + fingerprint);
}
phoneVerification.setPhoneNumber(phoneNumber);
phoneVerification.setUserEmail(cryptonomicaUser.getEmail());
phoneVerification.setSmsMessage(smsMessage);
phoneVerification.setFailedVerificationAttemps(0);
phoneVerification.setSmsMessageSend(new Date());
LOG.warning(GSON.toJson(phoneVerification));
/* --- Send SMS */
Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);
LOG.warning(message.toJSON());
/* --- Save phoneVerification */
ofy().save().entity(phoneVerification).now();
return new StringWrapperObject("SMS message send successfully");
}
use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class PGPPublicKeyAPI method addFingerprintStrProperties.
@ApiMethod(name = "addFingerprintStrProperties", path = "addFingerprintStrProperties", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // (fingerprint -> fingerprintStr)
StringWrapperObject addFingerprintStrProperties(final User googleUser) throws Exception {
/* Check authorization: */
UserTools.ensureCryptonomicaOfficer(googleUser);
/* Load PGPPublicKeyData from DB*/
List<PGPPublicKeyData> pgpPublicKeyDataList = ofy().load().type(PGPPublicKeyData.class).limit(20).list();
if (pgpPublicKeyDataList.size() > 10) {
throw new Exception("there are to many keys in the database");
}
for (PGPPublicKeyData pgpPublicKeyData : pgpPublicKeyDataList) {
pgpPublicKeyData.setFingerprintStr(pgpPublicKeyData.getFingerprint());
}
Map<Key<PGPPublicKeyData>, PGPPublicKeyData> result = ofy().save().entities(pgpPublicKeyDataList).now();
String resultJSON = new Gson().toJson(result);
return new StringWrapperObject(resultJSON);
}
use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class UserSearchAndViewAPI method echo.
// end of getUserProfileById @ApiMethod
@ApiMethod(name = "echo", path = "echo", httpMethod = ApiMethod.HttpMethod.GET)
public /* >>>>>>>>>>>>>> this is for testing only
* curl -H "Content-Type: application/json" -X GET -d '{"message":"hello world"}' https://cryptonomica-server.appspot.com/_ah/api/userSearchAndViewAPI/v1/echo
* */
StringWrapperObject echo(@Named("message") String message, @Named("n") @Nullable Integer n) {
StringWrapperObject stringWrapperObject = new StringWrapperObject();
if (n != null && n >= 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(message);
}
stringWrapperObject.setMessage(sb.toString());
}
return stringWrapperObject;
}
Aggregations