示例#1
0
class ResetPasswordConfirmation(object):
    """Confirm a password reset by sending a confirmation email, then acknowledge the
    success/failure of the operation"""
    def __init__(self, user, expiration_delay=timedelta(days=1)):
        self.uid = user if is_string(user) else user.uid
        self.token_generator = TokenGenerator(self._encryption_key(),
                                              expiration_delay)

    def _encryption_key(self):
        secret = 'eOMI5oa6ByATXNIADwloIRgI6EOqqnvb'
        email = self.user.email
        return hashlib.md5(secret + email).hexdigest()

    @property
    def user(self):
        return UserRepository().get_by_uid(self.uid)

    def confirmation_url(self, base_url):
        token = self.token_generator.create_token()
        return '/'.join((base_url, token))

    def confirm_reset_password(self, token):
        return self.token_generator.check_token(token)

    def send_email(self, confirmation_base_url):
        confirmation_url = self.confirmation_url(confirmation_base_url)
        self.user.send_email('mail-password-reset.html',
                             comment=confirmation_url)
示例#2
0
class ResetPasswordConfirmation(object):
    """Confirm a password reset by sending a confirmation email, then acknowledge the
    success/failure of the operation"""

    def __init__(self, user, expiration_delay=timedelta(days=1)):
        self.uid = user if is_string(user) else user.uid
        self.token_generator = TokenGenerator(self._encryption_key(), expiration_delay)

    def _encryption_key(self):
        secret = 'eOMI5oa6ByATXNIADwloIRgI6EOqqnvb'
        email = self.user.email
        return hashlib.md5(secret + email).hexdigest()

    @property
    def user(self):
        return UserRepository().get_by_uid(self.uid)

    def confirmation_url(self, base_url):
        token = self.token_generator.create_token()
        return '/'.join((base_url, token))

    def confirm_reset_password(self, token):
        return self.token_generator.check_token(token)

    def send_email(self, confirmation_base_url):
        confirmation_url = self.confirmation_url(confirmation_base_url)
        self.user.send_email('mail-password-reset.html', comment=confirmation_url)
示例#3
0
 def __init__(self, user, expiration_delay=timedelta(days=1)):
     self.uid = user if is_string(user) else user.uid
     self.token_generator = TokenGenerator(self._encryption_key(),
                                           expiration_delay)
示例#4
0
 def __init__(self, user, expiration_delay=timedelta(days=1)):
     self.uid = user if is_string(user) else user.uid
     self.token_generator = TokenGenerator(self._encryption_key(), expiration_delay)