Пример #1
0
 @Override
 public String readToken(String email) {
   Registration registration = read(email);
   if (registration != null) {
     return registration.getToken();
   }
   return null;
 }
Пример #2
0
 @Override
 public Registration read(String email) {
   Registration registration = store().get(Registration.class, email);
   if (registration != null) {
     Key key = store().put(registration);
     registration.setToken(KeyFactory.keyToString(key));
   }
   return registration;
 }
Пример #3
0
 @Override
 public User validate(String registrationString) {
   LOG.info("Validating registration: " + registrationString);
   Key key = KeyFactory.stringToKey(registrationString);
   final Registration registration = store().get(Registration.class, key);
   if (registration != null && !checkExpired(registration)) {
     User existing = userService.read(registration.getEmail());
     LOG.info("User for " + registration.getEmail() + " does not exist. Creating new User.");
     if (existing == null) {
       User user = User.createFrom(registration);
       Key userKey = store().put(user);
       if (userKey != null) {
         delete(registration.getEmail());
         return user;
       }
     }
   }
   LOG.info("Validation error");
   return null;
 }
Пример #4
0
 @Override
 public Key update(Registration registration) {
   registration.setModified(new Date());
   return store().put(registration);
 }
Пример #5
0
 public boolean checkExpired(Registration registration) {
   Long expiration = registration.getExpiration().getTime();
   Long now = new Date().getTime();
   return expiration < now;
 }