예제 #1
0
class ResetPassword(LoginBase):
    class IResetPasswordForm(interface.Interface):
        password = schema.Password(title=_(u"Password"))
        confirm_password = schema.Password(title=_(u"Confirm Password"))
        key = schema.TextLine(required=False)

    form_fields = form.Fields(IResetPasswordForm)
    form_fields["key"].custom_widget = widgets.HiddenTextWidget
    form_name = _(u"Reset Password")
    status = ""

    def __init__(self, *args, **kwargs):
        super(ResetPassword, self).__init__(*args, **kwargs)
        key = self.request.get("key", self.request.get("form.key", ""))
        self.link = Session().query(PasswordRestoreLink).filter(
            PasswordRestoreLink.hash == key).first()

    def __call__(self):
        if not self.link:
            self.status = _(u"Wrong key!")
        if self.link and self.link.expired():
            self.status = _(u"Key expired!")
        return super(ResetPassword, self).__call__()

    @form.action(_(u"Reset"), name="reset")
    def handle_reset(self, action, data):
        password = data.get("password", "")
        confirm_password = data.get("confirm_password", "")

        if password.__class__ is not object:
            if password != confirm_password:
                self.status = _(u"Password confirmation failed!")
                return

        if password and password == confirm_password and self.link:
            if not self.link.expired():
                user = self.link.user
                user._password = password
                self.link.expiration_date = datetime.datetime.now()
                self.status = _(u"Password successfully reset!")
예제 #2
0
class ResetPassword(LoginBase):
    class IResetPasswordForm(interface.Interface):
        password = schema.Password(title=_(u"Password"))
        confirm_password = schema.Password(title=_(u"Confirm Password"))
        key = schema.TextLine(required=False)
    form_fields = form.Fields(IResetPasswordForm)
    form_fields["key"].custom_widget = widgets.HiddenTextWidget
    form_name = _(u"Reset Password")
    status = ""
    
    def __init__(self, *args, **kwargs):
        super(ResetPassword, self).__init__(*args, **kwargs)
        key = self.request.get("key", self.request.get("form.key",""))
        self.link = Session().query(PasswordRestoreLink
                        ).filter(PasswordRestoreLink.hash==key).first()
    
    def __call__(self):
        if not self.link:
            self.status = _(u"Wrong key!")
        if self.link and self.link.expired():
            self.status = _(u"Key expired!")
        return super(ResetPassword, self).__call__()
    
    @form.action(_(u"Reset"), name="reset")
    def handle_reset(self, action, data):
        password = data.get("password", "")
        confirm_password = data.get("confirm_password", "")
        
        if password.__class__ is not object:
            if password != confirm_password:
                self.status = _(u"Password confirmation failed!")
                return
            
        if password and password == confirm_password and self.link:
            if not self.link.expired():
                user = self.link.user
                user._password = password
                self.link.expiration_date = datetime.datetime.now()
                self.status = _(u"Password successfully reset!")