0

I feel a little strange asking this question, but I really have not been able to find an answer after pretty extensive googling.

Right now I'm using the peewee ORM on top of PostgresQL and I'm implementing a password reset. For obvious reasons I don't want to keep the password-reset keys around forever, so I'd like to create the object in postgres and have it expire after a set amount of time.

I can't find any mention of how to do this in the docs or on StackOverflow. This seems like a pretty common use case, but it seems that there isn't anything out there on how to actually do this. My model for reference:

class PostgresModel(Model):

    _id = PrimaryKeyField()

    class Meta:
        database = DATABASE

    @classmethod
    def create_and_commit(cls, **kwargs):
        cls.create(**kwargs)
        DATABASE.commit()

class ForgotPassword(PostgresModel):
    user = ForeignKeyField(BaseUser, related_name='password_reset')
    secret_key = CharField()

Anyone have insight on this?

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144

1 Answers1

0

Add a DateTimeField to your model indicating when the key expires (or when it was created), then use that to determine whether it's valid or not.

coleifer
  • 24,887
  • 6
  • 60
  • 75