Esempio n. 1
0
def handle_user_profile(self, request, form):
    """ Handles the GET and POST login requests. """

    layout = DefaultLayout(self, request)

    collection = UserCollection(request.app.session())
    user = collection.by_username(request.identity.userid)

    if form.submitted(request):
        form.update_model(user)
        request.success(_("Your changes were saved"))
    else:
        form.apply_model(user)

    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("User Profile"), request.link(self))
    ]

    return {
        'layout': layout,
        'title': _("User Profile"),
        'form': form,
        'username': user.username,
        'role': user.role
    }
Esempio n. 2
0
def handle_login(self, request, form):
    """ Handles the login requests. """

    if form.submitted(request):
        response = self.login_to(request=request, **form.login_data)

        if response:
            request.success(_("You have been logged in."))
            return response

        request.alert(_("Wrong e-mail address, password or yubikey."))

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Login"), request.link(self, name='login'))
    ]

    return {
        'layout': layout,
        'password_reset_link': request.link(
            request.app.town, name='request-password'),
        'title': _('Login to ${town}', mapping={
            'town': request.app.town.name
        }),
        'form': form
    }
Esempio n. 3
0
def handle_password_reset_request(self, request, form):
    """ Handles the GET and POST password reset requests. """
    if form.submitted(request):
        user, token = form.get_token(request)
        if user is not None and token is not None:
            url = "{0}?token={1}".format(request.link(self, name="reset-password"), token)
            send_html_mail(
                request=request,
                template="mail_password_reset.pt",
                subject=_("Password reset"),
                receivers=(user.username,),
                content={"model": None, "url": url},
            )
        else:
            log.info("Failed password reset attempt by {}".format(request.client_addr))

        response = morepath.redirect(request.link(self))
        request.success(
            _(
                (
                    u"A password reset link has been sent to ${email}, provided an "
                    u"account exists for this email address."
                ),
                mapping={"email": form.email.data},
            )
        )
        return response

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Reset password"), request.link(self, name="request-password")),
    ]

    return {"layout": layout, "title": _(u"Reset password"), "form": form, "form_width": "small"}
Esempio n. 4
0
def handle_password_reset(self, request, form):
    request.include("common")
    request.include("check_password")

    if form.submitted(request):
        identity = form.get_identity(request)
        if identity is not None:
            response = morepath.redirect(request.link(self))
            morepath.remember_identity(response, request, identity)
            request.success(_("Password changed."))
            return response
        else:
            request.alert(_("Wrong username or password reset link not valid any more."))
            log.info("Failed password reset attempt by {}".format(request.client_addr))

    if "token" in request.params:
        form.token.data = request.params["token"]

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Reset password"), request.link(self, name="request-password")),
    ]

    return {"layout": layout, "title": _(u"Reset password"), "form": form, "form_width": "small"}
Esempio n. 5
0
def handle_settings(self, request, form):
    """ Handles the GET and POST login requests. """

    layout = DefaultLayout(self, request)
    layout.include_editor()

    request.include('check_contrast')

    if form.submitted(request):
        with request.app.update_town() as town:
            town.name = form.name.data
            town.logo_url = form.logo_url.data
            town.theme_options = form.theme_options
            town.meta = {
                'contact': form.contact.data,
                'contact_html': linkify(
                    form.contact.data).replace('\n', '<br>'),
                'contact_url': form.contact_url.data,
                'opening_hours': form.opening_hours.data,
                'opening_hours_html': linkify(
                    form.opening_hours.data).replace('\n', '<br>'),
                'opening_hours_url': form.opening_hours_url.data,
                'reply_to': form.reply_to.data,
                'facebook_url': form.facebook_url.data,
                'twitter_url': form.twitter_url.data,
                'analytics_code': form.analytics_code.data,
                'online_counter_label': form.online_counter_label.data,
                'reservations_label': form.reservations_label.data,
                'sbb_daypass_label': form.sbb_daypass_label.data,
            }

        request.success(_("Your changes were saved"))
    else:
        form.name.data = self.name
        form.logo_url.data = self.logo_url
        form.theme_options = self.theme_options
        form.contact.data = self.meta.get('contact')
        form.contact_url.data = self.meta.get('contact_url')
        form.opening_hours.data = self.meta.get('opening_hours')
        form.opening_hours_url.data = self.meta.get('opening_hours_url')
        form.reply_to.data = self.meta.get('reply_to')
        form.facebook_url.data = self.meta.get('facebook_url')
        form.twitter_url.data = self.meta.get('twitter_url')
        form.analytics_code.data = self.meta.get('analytics_code')
        form.online_counter_label.data = self.meta.get('online_counter_label')
        form.reservations_label.data = self.meta.get('reservations_label')
        form.sbb_daypass_label.data = self.meta.get('sbb_daypass_label')

    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Settings"), request.link(self))
    ]

    return {
        'layout': layout,
        'title': _('Settings'),
        'form': form,
        'form_width': 'large'
    }
Esempio n. 6
0
def view_get_file_collection(self, request):
    request.include("dropzone")

    files = [Link(text=file_.original_name, url=request.link(file_)) for file_ in self.files]

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [Link(_("Homepage"), layout.homepage_url), Link(_("Files"), request.link(self))]

    return {"layout": layout, "title": _("Files"), "files": files}
Esempio n. 7
0
def view_get_image_collection(self, request):
    request.include("dropzone")

    images = [Img(src=request.link(image.thumbnail), url=request.link(image)) for image in self.files]

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [Link(_("Homepage"), layout.homepage_url), Link(_("Images"), request.link(self))]

    return {"layout": layout, "title": _(u"Images"), "images": images}
Esempio n. 8
0
def handle_password_reset_request(self, request, form):
    """ Handles the GET and POST password reset requests. """
    if form.submitted(request):
        user, token = form.get_token(request)
        if user is not None and token is not None:
            url = '{0}?token={1}'.format(
                request.link(self, name='reset-password'), token
            )
            send_html_mail(
                request=request,
                template='mail_password_reset.pt',
                subject=_("Password reset"),
                receivers=(user.username, ),
                content={'model': None, 'url': url}
            )
        else:
            log.info(
                "Failed password reset attempt by {}".format(
                    request.client_addr
                )
            )

        response = morepath.redirect(request.link(self))
        request.success(
            _(('A password reset link has been sent to ${email}, provided an '
               'account exists for this email address.'),
              mapping={'email': form.email.data})
        )
        return response

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Reset password"), request.link(self, name='request-password'))
    ]

    return {
        'layout': layout,
        'title': _('Reset password'),
        'form': form,
        'form_width': 'small'
    }
Esempio n. 9
0
def view_get_image_collection(self, request):
    request.include('dropzone')

    image_groups = [
        [group, [Img(src=request.link(image.thumbnail),
                     url=request.link(image)) for image in images]]
        for group, images in self.grouped_files()
    ]

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Images"), request.link(self))
    ]

    return {
        'layout': layout,
        'title': _('Images'),
        'image_groups': image_groups,
    }
Esempio n. 10
0
def view_ticket_status(self, request):

    if self.state == 'open':
        title = _("Your request has been submitted")
    elif self.state == 'pending':
        title = _("Your request is currently pending")
    elif self.state == 'closed':
        title = _("Your request has been processed")
    else:
        raise NotImplementedError

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Ticket Status"), '#')
    ]

    return {
        'title': title,
        'layout': layout,
        'ticket': self
    }
Esempio n. 11
0
def handle_password_reset(self, request, form):
    request.include('common')
    request.include('check_password')

    if form.submitted(request):
        # do NOT log the user in at this point - only onegov.user.auth does
        # logins - we only ever want one path to be able to login, which makes
        # it easier to do it correctly.
        #
        # XXX move this to onegov.user.auth as well
        if form.update_password(request):
            request.success(_("Password changed."))
            return morepath.redirect(request.link(self))
        else:
            request.alert(
                _("Wrong username or password reset link not valid any more.")
            )
            log.info(
                "Failed password reset attempt by {}".format(
                    request.client_addr
                )
            )

    if 'token' in request.params:
        form.token.data = request.params['token']

    layout = DefaultLayout(self, request)
    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Reset password"), request.link(self, name='request-password'))
    ]

    return {
        'layout': layout,
        'title': _('Reset password'),
        'form': form,
        'form_width': 'small'
    }