def usersuite(): """Usersuite landing page with user account information and traffic overview. """ try: user_info = dict(current_user.get_information()) traffic_data = current_user.get_traffic_data() except DBQueryEmpty as e: logger.error('Userinfo DB query could not be finished', extra={'data': {'exception_args': e.args}, 'stack': True}) flash(gettext("Es gab einen Fehler bei der Datenbankanfrage!"), "error") return redirect(url_for('generic.index')) user_info.update({prop: unsupported_property() for prop in current_user.unsupported(display=True)}) descriptions = OrderedDict([ ('id', gettext("Nutzer-ID")), ('uid', gettext("Accountname")), ('status', gettext("Accountstatus")), ('address', gettext("Aktuelles Zimmer")), ('ip', gettext("Aktuelle IP-Adresse")), ('mac', gettext("Aktuelle MAC-Adresse")), ('mail', gettext("E-Mail-Weiterleitung")), ('hostname', gettext("Hostname")), ('hostalias', gettext("Hostalias")), ('userdb', gettext("MySQL Datenbank")), ]) ordered_user_info = OrderedDict() for key, description in descriptions.items(): if key in user_info: ordered_user_info[key] = user_info[key] ordered_user_info[key]['description'] = descriptions[key] # set {mail,mac,userdb}_{change,delete} urls if 'mail_change' in current_user.supported(): ordered_user_info['mail']['action_links'] = { ACTIONS.EDIT: url_for('.usersuite_change_mail'), ACTIONS.DELETE: url_for('.usersuite_delete_mail') } if 'mac_change' in current_user.supported(): ordered_user_info['mac']['action_links'] = { ACTIONS.EDIT: url_for('.usersuite_change_mac') } if 'userdb_change' in current_user.supported(): ordered_user_info['userdb']['action_links'] = { ACTIONS.EDIT: url_for('.usersuite_hosting') } return render_template("usersuite/index.html", userinfo=ordered_user_info, usertraffic=traffic_data)
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)