Personal wiki notebook (not under development)

Password_reset.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from Persistent import Persistent, quote
  2. class Password_reset( Persistent ):
  3. """
  4. A request for a password reset.
  5. """
  6. def __init__( self, object_id, revision = None, email_address = None, redeemed = False ):
  7. """
  8. Create a password reset request with the given id.
  9. @type object_id: unicode
  10. @param object_id: id of the password reset
  11. @type revision: datetime or NoneType
  12. @param revision: revision timestamp of the object (optional, defaults to now)
  13. @type email_address: unicode or NoneType
  14. @param email_address: where the reset confirmation was emailed (optional)
  15. @type redeemed: bool or NoneType
  16. @param redeemed: whether this password reset has been redeemed yet (optional, defaults to False)
  17. @rtype: Password_reset
  18. @return: newly constructed password reset
  19. """
  20. Persistent.__init__( self, object_id, revision )
  21. self.__email_address = email_address
  22. self.__redeemed = redeemed
  23. @staticmethod
  24. def create( object_id, email_address = None ):
  25. """
  26. Convenience constructor for creating a new password reset.
  27. @type email_address: unicode
  28. @param email_address: where the reset confirmation was emailed
  29. @rtype: Password_reset
  30. @return: newly constructed password reset
  31. """
  32. return Password_reset( object_id, email_address = email_address )
  33. @staticmethod
  34. def sql_load( object_id, revision = None ):
  35. # password resets don't store old revisions
  36. if revision:
  37. raise NotImplementedError()
  38. return "select id, revision, email_address, redeemed from password_reset where id = %s;" % quote( object_id )
  39. @staticmethod
  40. def sql_id_exists( object_id, revision = None ):
  41. if revision:
  42. raise NotImplementedError()
  43. return "select id from password_reset where id = %s;" % quote( object_id )
  44. def sql_exists( self ):
  45. return Password_reset.sql_id_exists( self.object_id )
  46. def sql_create( self ):
  47. return "insert into password_reset ( id, revision, email_address, redeemed ) values ( %s, %s, %s, %s );" % \
  48. ( quote( self.object_id ), quote( self.revision ), quote( self.__email_address ), quote( self.__redeemed and "t" or "f" ) )
  49. def sql_update( self ):
  50. return "update password_reset set revision = %s, email_address = %s, redeemed = %s where id = %s;" % \
  51. ( quote( self.revision ), quote( self.__email_address ), quote( self.__redeemed and "t" or "f" ), quote( self.object_id ) )
  52. def __set_redeemed( self, redeemed ):
  53. if redeemed != self.__redeemed:
  54. self.update_revision()
  55. self.__redeemed = redeemed
  56. email_address = property( lambda self: self.__email_address )
  57. redeemed = property( lambda self: self.__redeemed, __set_redeemed )