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