Exemple #1
0
def forgot_password(request):
    FORM_TITLE = _('Password Recovery')
    main = get_renderer(BASE_TEMPLATE).implementation()
    localizer = get_localizer(request)
    forgot_password_form = ForgotPasswordForm.get_form(localizer)

    if request.method == 'POST':
        if 'btn_cancel' in request.POST:
            return HTTPFound(location=request.route_path('users.login'))

        controls = request.POST.items()
        try:
            appstruct = forgot_password_form.validate(controls)
        except deform.ValidationFailure, e:
            return {'content':e.render(),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }

        del(appstruct['__LOCALE__'])
        try:
            user = request.rel_db_session.query(users.User).filter_by(username=appstruct['username']).one()
        except NoResultFound:
            request.session.flash(_("Username doesn't exist."))
            return {'content':forgot_password_form.render(appstruct),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }

        account = users.AccountRecovery(user)
        request.rel_db_session.add(account)

        try:
            request.rel_db_session.commit()
        except:
            request.rel_db_session.rollback()
            request.session.flash(_('Problems occured when trying to redefine the user password. Please try again.'))
            return {'content':forgot_password_form.render(appstruct),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }
        else:
            AccountRecoveryManager.send_recovery_mail(user, request)

        request.session.flash(_('You will receive an email with instructions on how to reset your account password.'))
        return HTTPFound(location=request.route_path('users.forgot_password'))
Exemple #2
0
def recover_password(request):
    FORM_TITLE = _('Password Recovery')
    main = get_renderer(BASE_TEMPLATE).implementation()
    localizer = get_localizer(request)
    recovery_form = RecoverPasswordForm.get_form(localizer)

    recovery_key = request.params.get('key', None)
    if recovery_key is None:
        raise exceptions.NotFound()
    
    if request.method == 'POST':
        controls = request.POST.items()
        try:
            appstruct = recovery_form.validate(controls)
        except deform.ValidationFailure, e:            
            return {'content':e.render(), 
                    'main':main, 
                    'form_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }

        del(appstruct['__LOCALE__'])
        try:
            user = AccountRecoveryManager.redefine_password(appstruct['recovery_key'], appstruct['new_password'], request)
            request.session.flash(_('Password successfully redefined.'))
        except InvalidActivationKey:
            raise exceptions.NotFound()
        except ActivationError:
            request.session.flash(_('Problems occured when trying to redefine the user password. Please try again.'))

        return HTTPFound(location=request.route_url('users.login'))
Exemple #3
0
def recover_password(request):
    FORM_TITLE = _('Password Recovery')
    main = get_renderer(BASE_TEMPLATE).implementation()
    localizer = get_localizer(request)
    recovery_form = RecoverPasswordForm.get_form(localizer)

    recovery_key = request.params.get('key', None)
    if recovery_key is None:
        raise exceptions.NotFound()

    if request.method == 'POST':
        controls = request.POST.items()
        try:
            appstruct = recovery_form.validate(controls)
        except deform.ValidationFailure, e:
            return {'content':e.render(),
                    'main':main,
                    'general_stuff':{'form_title':FORM_TITLE},
                    'user':get_logged_user(request),
                    }

        del(appstruct['__LOCALE__'])
        try:
            user = AccountRecoveryManager.redefine_password(appstruct['recovery_key'], appstruct['new_password'], request)
            request.session.flash(_('Password successfully redefined.'))
        except InvalidActivationKey:
            raise exceptions.NotFound()
        except ActivationError:
            request.session.flash(_('Problems occured when trying to redefine the user password. Please try again.'))

        return HTTPFound(location=request.route_path('users.login'))