Пример #1
0
def usersuite_change_mac():
    """As user, change the MAC address of your device.
    """
    form = ChangeMACForm()
    userinfo = current_user.get_information()

    if form.validate_on_submit():
        password = form.password.data
        mac = form.mac.data

        try:
            current_user.re_authenticate(password)

        except PasswordInvalid:
            flash(gettext("Passwort war inkorrekt!"), "error")
        else:
            current_user.change_mac_address(userinfo['mac']['value'], mac)
            logger.info('Successfully changed MAC address',
                        extra={'data': {'mac': mac}})

            flash(gettext("MAC-Adresse wurde geändert!"), 'success')

            from_mail = "{}@{}".format(current_user.uid,
                                       current_datasource().mail_server)
            support_mail = current_datasource().support_mail

            subject = ("[Usersuite] {} hat seine/ihre MAC-Adresse "
                       "geändert".format(current_user.uid))
            message = (
                "Nutzer {name} ({uid}) hat seine/ihre MAC-Adresse geändert."
                "\nAlte MAC: {old_mac}\nNeue MAC: {new_mac}".format(
                    name=current_user.name,
                    uid=current_user.uid,
                    old_mac=userinfo['mac']['value'],
                    new_mac=mac
                )
            )

            if not send_mail(from_mail, support_mail, subject, message):
                logger.error("Mac notification mail could not be sent")

            return redirect(url_for('.usersuite'))
    elif form.is_submitted():
        flash_formerrors(form)

    form.mac.default = userinfo['mac']['value']

    return render_template('usersuite/change_mac.html', form=form)
Пример #2
0
def usersuite_contact():
    """Contact form for logged in users.
    Currently sends an e-mail to the support mailing list as
    '[Usersuite] Category: Subject' with userid and message.
    """
    form = ContactForm()

    support_mail = current_datasource().support_mail
    from_mail = "{}@{}".format(current_user.uid,
                               current_datasource().mail_server)

    if form.validate_on_submit():
        types = {
            'stoerung': "Störung",
            'finanzen': "Finanzen",
            'eigene-technik': "Eigene Technik"
        }

        cat = types.get(form.type.data, "Allgemein")

        subject = "[Usersuite] {0}: {1}".format(cat, form.subject.data)

        message_text = "Nutzerlogin: {0}\n\n".format(current_user.uid) \
                       + form.message.data

        if send_mail(from_mail, support_mail, subject, message_text):
            flash(gettext("Nachricht wurde versandt."), "success")
        else:
            flash(gettext("Es gab einen Fehler beim Versenden der Nachricht. "
                          "Bitte schicke uns direkt eine E-Mail an {}".format(
                              support_mail)),
                  'error')
        return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    form.email.default = from_mail

    return render_template("usersuite/contact.html", form=form)
Пример #3
0
def usersuite_contact():
    """Contact form for logged in users.
    Currently sends an e-mail to the support mailing list as
    '[Usersuite] Category: Subject' with userid and message.
    """
    form = ContactForm()

    support_mail = current_datasource().support_mail
    from_mail = "{}@{}".format(current_user.uid,
                               current_datasource().mail_server)

    if form.validate_on_submit():
        types = {
            'stoerung': "Störung",
            'finanzen': "Finanzen",
            'eigene-technik': "Eigene Technik"
        }

        cat = types.get(form.type.data, "Allgemein")

        subject = "[Usersuite] {0}: {1}".format(cat, form.subject.data)

        message_text = "Nutzerlogin: {0}\n\n".format(current_user.uid) \
                       + form.message.data

        if send_mail(from_mail, support_mail, subject, message_text):
            flash(gettext("Nachricht wurde versandt."), "success")
        else:
            flash(
                gettext("Es gab einen Fehler beim Versenden der Nachricht. "
                        "Bitte schicke uns direkt eine E-Mail an {}".format(
                            support_mail)), 'error')
        return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    form.email.default = from_mail

    return render_template("usersuite/contact.html", form=form)