use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class PGPPublicKeyAPI method uploadNewPGPPublicKey.
// end of getPGPPublicKeyByFingerprint()
@ApiMethod(name = "uploadNewPGPPublicKey", path = "uploadNewPGPPublicKey", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public PGPPublicKeyUploadReturn uploadNewPGPPublicKey(// final HttpServletRequest httpServletRequest,
final User googleUser, final PGPPublicKeyUploadForm pgpPublicKeyUploadForm) throws Exception {
// authorization
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
if (pgpPublicKeyUploadForm == null || pgpPublicKeyUploadForm.getAsciiArmored() == null || pgpPublicKeyUploadForm.getAsciiArmored().length() == 0) {
throw new Exception("ASCII-armored key is empty");
}
// --- LOG request form: (after check if not null)
LOG.warning(GSON.toJson(pgpPublicKeyUploadForm));
String asciiArmored = pgpPublicKeyUploadForm.getAsciiArmored();
PGPPublicKey pgpPublicKey = PGPTools.readPublicKeyFromString(asciiArmored);
// -> throws IOException, PGPException
LOG.warning(GSON.toJson(pgpPublicKey));
PGPPublicKeyData pgpPublicKeyData = PGPTools.checkPublicKey(pgpPublicKey, asciiArmored, cryptonomicaUser);
pgpPublicKeyData.setUserBirthday(cryptonomicaUser.getBirthday());
// -- add @Parent value: ---
pgpPublicKeyData.setCryptonomicaUserKey(Key.create(CryptonomicaUser.class, googleUser.getUserId()));
// save key
Key<PGPPublicKeyData> pgpPublicKeyDataKey = ofy().save().entity(pgpPublicKeyData).now();
// load key from DB and and create return object
String messageToUser = "Key " + pgpPublicKeyData.getFingerprint() + " saved in data base";
PGPPublicKeyGeneralView pgpPublicKeyGeneralView = new PGPPublicKeyGeneralView(ofy().load().key(pgpPublicKeyDataKey).now());
PGPPublicKeyUploadReturn pgpPublicKeyUploadReturn = new PGPPublicKeyUploadReturn(messageToUser, pgpPublicKeyGeneralView);
return pgpPublicKeyUploadReturn;
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class PGPPublicKeyAPI method getMyKeys.
@ApiMethod(name = "getMyKeys", path = "getMyKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn getMyKeys(// final HttpServletRequest httpServletRequest,
final User googleUser) throws Exception {
// authorization
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
List<PGPPublicKeyData> result = ofy().load().type(PGPPublicKeyData.class).ancestor(cryptonomicaUserKey).list();
SearchPGPPublicKeysReturn searchPGPPublicKeysReturn;
if (result.size() > 0) {
searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this is list of your keys, if any:", new ArrayList<>(result));
} else {
searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("You have no keys, yet.", new ArrayList<>(result));
}
return searchPGPPublicKeysReturn;
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class UploadAPI method getCsUploadURL.
@ApiMethod(name = "getCsUploadURL", path = "getCsUploadURL", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public GetCSuploadURLreturn getCsUploadURL(User googleUser) throws Exception {
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
String imageUploadUrl = BlobstoreServiceFactory.getBlobstoreService().createUploadUrl(// upload handler servlet address
"/cs-user-image-upload", UploadOptions.Builder.withGoogleStorageBucketName(// Cloud Storage bucket name (f.e. "cryptonomica-test.appspot.com")
Constants.GAE_PROJECT_DOMAIN));
String imageUploadKey = randomAlphanumeric(9);
//
cryptonomicaUser.setImageUploadLink(imageUploadUrl);
cryptonomicaUser.setImageUploadKey(imageUploadKey);
//
Key<CryptonomicaUser> cryptonomicaUserKey = ofy().save().entity(cryptonomicaUser).now();
LOG.warning("Upload URL: " + imageUploadUrl);
LOG.warning("Saved for user: " + cryptonomicaUserKey.getName());
LOG.warning("With imageUploadKey: " + imageUploadKey);
return new GetCSuploadURLreturn(imageUploadUrl, imageUploadKey, null);
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class VerificationAPI method getVerificationByID.
/* --- Get verification info by verification ID: */
@ApiMethod(name = "getVerificationByID", path = "getVerificationByID", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByID(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationID") final String verificationID) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Check input: */
if (verificationID == null || verificationID.equals("")) {
throw new BadRequestException("Verification ID missing");
}
/* --- Load verification entity from DS: */
Verification verification = ofy().load().key(Key.create(Verification.class, verificationID)).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 net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class VisitorAPI method showAllNotaries.
@ApiMethod(name = "searchForNotaries", path = "searchForNotaries", httpMethod = ApiMethod.HttpMethod.POST)
public ArrayList<NotaryGeneralView> showAllNotaries(final User googleUser) throws Exception {
// ensure authorization
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
List<Notary> notaryList = ofy().load().type(Notary.class).list();
//
ArrayList<NotaryGeneralView> notaryGeneralViewArrayList = new ArrayList<>();
if (notaryList != null) {
for (Notary notary : notaryList) {
Key<CryptonomicaUser> notaryCUkey = Key.create(CryptonomicaUser.class, notary.getId());
//
CryptonomicaUser notaryCryptonomicaUser = ofy().load().key(notaryCUkey).now();
//
UserProfileGeneralView notaryUserProfileGeneralView = new UserProfileGeneralView(notaryCryptonomicaUser);
//
notaryGeneralViewArrayList.add(new NotaryGeneralView(notaryUserProfileGeneralView, notary));
}
}
//
LOG.warning("notaryGeneralViewArrayList: " + new Gson().toJson(notaryGeneralViewArrayList));
//
return notaryGeneralViewArrayList;
}
Aggregations