Esempio n. 1
0
def change_mac():
    """As user, change the MAC address of your device.
    """
    form = ChangeMACForm()

    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.mac = mac
            logger.info('Successfully changed MAC address',
                        extra={'data': {'mac': mac},
                               'tags': {'rate_critical': True}})

            flash(gettext("MAC-Adresse wurde geändert!"), 'success')
            flash(gettext("Es kann bis zu 10 Minuten dauern, "
                          "bis die Änderung wirksam ist."), 'info')

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

    form.mac.default = current_user.mac.value

    return render_template('usersuite/change_mac.html', form=form)
Esempio n. 2
0
def usersuite_delete_mail():
    """Resets the users forwarding mail attribute
    in his LDAP entry.
    """
    form = DeleteMailForm()

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

        try:
            current_user.re_authenticate(password)
            # password is needed for the ldap bind
            current_user.change_mail(password, "")
        except UserNotFound:
            flash(gettext("Nutzer nicht gefunden!"), "error")
        except PasswordInvalid:
            flash(gettext("Passwort war inkorrekt!"), "error")
        except LDAPConnectionError:
            flash(gettext("Nicht genügend LDAP-Rechte!"), "error")
        else:
            flash(gettext("E-Mail-Adresse wurde zurückgesetzt"), "success")
            return redirect(url_for('.usersuite'))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template('usersuite/delete_mail.html', form=form)
Esempio n. 3
0
def usersuite_change_mail():
    """Changes the users forwarding mail attribute
    in his LDAP entry.

    TODO: LDAP schema forbids add/replace 'mail' attribute
    """
    form = ChangeMailForm()

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

        try:
            current_user.re_authenticate(password)
            current_user.change_mail(password, email)
        except UserNotFound:
            flash(gettext("Nutzer nicht gefunden!"), "error")
        except PasswordInvalid:
            flash(gettext("Passwort war inkorrekt!"), "error")
        except LDAPConnectionError:
            flash(gettext("Nicht genügend LDAP-Rechte!"), "error")
        else:
            flash(gettext("E-Mail-Adresse wurde geändert"), "success")
            return redirect(url_for('.usersuite'))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template('usersuite/change_mail.html', form=form)
Esempio n. 4
0
def usersuite_change_password():
    """Lets the user change his password.
    Requests the old password once (in case someone forgot to logout for
    example) and the new password two times.

    If the new password was entered correctly twice, LDAP performs a bind
    with the old credentials at the users DN and submits the passwords to
    modify_password(). This way each user can edit only his own data.

    Error code "-1" is an incorrect old or empty password.

    TODO: set a minimum character limit for new passwords.
    """
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)
Esempio n. 5
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)
Esempio n. 6
0
def usersuite_change_password():
    """Frontend page to change the user's password"""
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)
Esempio n. 7
0
def usersuite_change_password():
    """Frontend page to change the user's password"""
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)
Esempio n. 8
0
def change_mac():
    """As user, change the MAC address of your device.
    """
    form = ChangeMACForm()

    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.mac = mac
            logger.info('Successfully changed MAC address',
                        extra={
                            'data': {
                                'mac': mac
                            },
                            'tags': {
                                'rate_critical': True
                            }
                        })

            flash(gettext("MAC-Adresse wurde geändert!"), 'success')
            flash(
                gettext("Es kann bis zu 10 Minuten dauern, "
                        "bis die Änderung wirksam ist."), 'info')

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

    form.mac.default = current_user.mac.value

    return render_template('usersuite/change_mac.html', form=form)