Exemplo n.º 1
0
 @Override
 public String readToken(String email) {
   Registration registration = read(email);
   if (registration != null) {
     return registration.getToken();
   }
   return null;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 4
0
 @Override
 public Key update(Registration registration) {
   registration.setModified(new Date());
   return store().put(registration);
 }
Exemplo n.º 5
0
 public boolean checkExpired(Registration registration) {
   Long expiration = registration.getExpiration().getTime();
   Long now = new Date().getTime();
   return expiration < now;
 }