I am building custom accounts system, where when a user creates an account I save it to Datastore but with the 'verified' field default set to false (one cannot login with an Account until its verified field is set to true.)
username = ndb.StringProperty(required = True)
password = ndb.StringProperty(required = True)
email = ndb.StringProperty(required = True)
verified = ndb.BooleanProperty(default = False)
created = ndb.DateTimeProperty(auto_now_add = True)
acc = Account( id=username,
username = username,
password = password,
email = email)
urlString = rev_key.urlsafe()
The keys will only work on your app, the
app-id is actually part of the full key; but as you imagined, anyone could construct a key for different usernames and thus validate them, even if they didn't got the email. As noted in the comment by @Paul, you shouldn't trust that the key hasn't been tampered with.
I advise you to handle verification separately, for example:
import hashlib import os class Verification(ndb.Model): account = ndb.KeyProperty() @classmethod def create(cls, account): verification = cls( id=hashlib.sha1(os.urandom(16)).hexdigest(), account=account.key, ).put() return verification.id() @classmethod def validate(cls, verification_id): verification = cls.get_by_id(verification_id) account = verification.account.get() account.verified = True account.put()
What we did here is create a different model, Verification, to handle this feature; when created, this entity gets an obscure id, that you can then use to validate the right account. You could build on this to handle app-specific features.