Exemple #1
0
def getAdminContent(self, **params):
    """
    Deliver admin content of module user

    :param params: use given parameters of request
    :return: rendered template as string
    """
    if request.method == 'POST':
        if request.form.get('action').startswith('edituser_'):
            actionuser = User.getUsers(int(request.form.get('action').split('_')[-1]))
            params.update({'actionuser': actionuser, 'userlevels': [(0, 'userlevel.notset'), (1, 'userlevel.admin'), (2, 'userlevel.user')]})
            return render_template('admin.user_actions.html', **params)

        elif request.form.get('action') == 'createuser':  # add new user
            params.update({'actionuser': User('', '', '', 2, '', active=False), 'userlevels': [(0, 'userlevel.notset'), (1, 'userlevel.admin'), (2, 'userlevel.user')]})
            return render_template('admin.user_actions.html', **params)

        elif request.form.get('action').startswith('deleteuser_'):  # delet user
            db.session.delete(User.getUsers(request.form.get('action').split('_')[-1]))
            db.session.commit()

        elif request.form.get('action') == 'updateuser':  # update user
            if request.form.get('user_id') == 'None':  # add new user
                actionuser = User(request.form.get('edit_username'), current_app.config.get('DEFAULTPASSWORD', 'ABC'), '', 2, '', active=False)
                db.session.add(actionuser)
            else:
                actionuser = User.getUsers(int(request.form.get('user_id')))
            actionuser.email = request.form.get('edit_email')
            actionuser.level = request.form.get('edit_level')
            actionuser.active = request.form.get('edit_active', '0') == '1'
            db.session.commit()

    params.update({'users': User.getUsers(), 'userlevels': [(0, 'userlevel.notset'), (1, 'userlevel.admin'), (2, 'userlevel.user')]})
    return render_template('admin.user.html', **params)
def frontendContent(module=u""):
    """
    Frontend area is reachable under *http://[servername]:[port]/[module]*

    :param module: module name as string
    :return: renderd HTML-outpu of module or startpage
    """
    if module != "":
        if module == "none":
            return render_template("frontend.area.html")
        try:
            current_mod = [
                frontend.modules[m]
                for m in frontend.modules
                if frontend.modules[m].info["path"] == module.split("/")[0]
            ][0]
        except IndexError:
            current_mod = frontend.modules["startpages"]
        return current_mod.getFrontendContent()
    current_mod = frontend.modules["startpages"]
    return render_template(
        "frontendframe.html",
        user=User.getUsers(login.current_user.get_id() or -1),
        current_mod=current_mod,
        modules=frontend.modules,
        app_name=current_app.config.get("PROJECT"),
        app_version=current_app.config.get("APP_VERSION"),
        areas=Settings.getFrontendSettings(),
    )
Exemple #3
0
def frontendContent(module=u''):
    """
    Frontend area is reachable under *http://[servername]:[port]/[module]*

    :param module: module name as string
    :return: renderd HTML-outpu of module or startpage
    """
    if module != "":
        if module == 'none':
            return render_template('frontend.area.html')
        try:
            current_mod = [
                frontend.modules[m] for m in frontend.modules
                if frontend.modules[m].info['path'] == module.split('/')[0]
            ][0]
        except IndexError:
            current_mod = frontend.modules['startpages']
        return current_mod.getFrontendContent()
    current_mod = frontend.modules['startpages']
    return render_template('frontendframe.html',
                           user=User.getUsers(login.current_user.get_id()
                                              or -1),
                           current_mod=current_mod,
                           modules=frontend.modules,
                           app_name=current_app.config.get('PROJECT'),
                           app_version=current_app.config.get('APP_VERSION'),
                           areas=Settings.getFrontendSettings())
Exemple #4
0
def usersettings():
    """
    Register url */user* for user settings

    :return: rendered template */emonitor/login/templates/login_settings.html*
    """
    if request.method == "POST":
        user = User.getUsers(flask_login.current_user.get_id() or -1)
        if not user.check_password(request.form.get('curpwd')):
            flash('login.currpwdwrong')
        elif request.form.get('newpwd') != request.form.get('newpwdcheck'):
            flash('login.pwdnomatch')
        else:
            user._set_password(request.form.get('newpwdcheck'))
            db.session.commit()
            return redirect("/")

    return render_template('login_settings.html', user=User.getUsers(flask_login.current_user.get_id() or -1), app_name=current_app.config.get('PROJECT'), app_version=current_app.config.get('APP_VERSION'))
Exemple #5
0
def adminContent(module=''):
    """
    Admin area is reachable under *http://[servername]:[port]/admin/[module]*

    *module* will execute the *getAdminContent* method of registered module. If no nodule is given, the startpage of
    the admin area will be used

    :param module: module name as string
    :return: rendered HTML-output of module or startpage
    """
    if module == 'upgradedb':  # create new db-revision name given by revisionname
        msg = ""
        if request.args.get('revisionname', '') != '':
            msg = alembic.revision(request.args.get('revisionname'))
        return render_template(
            'admin.dbrevision.html',
            modules=[],
            current_mod='upgradedb',
            user=User.getUsers(login.current_user.get_id() or -1),
            app_name=current_app.config.get('PROJECT'),
            app_version=current_app.config.get('APP_VERSION'),
            path='/admin/' + module,
            revisionname=request.args.get('revisionname', ''),
            msg=msg)
    try:
        current_mod = [
            admin.modules[m] for m in admin.modules
            if admin.modules[m].info['path'] == module.split('/')[0]
        ][0]
    except IndexError:
        current_mod = admin.modules['startpages']
    return current_mod.getAdminContent(
        modules=admin.modules,
        current_mod=current_mod,
        user=User.getUsers(login.current_user.get_id() or -1),
        app_name=current_app.config.get('PROJECT'),
        app_version=current_app.config.get('APP_VERSION'),
        path='/admin/' + module,
        help='')
Exemple #6
0
def frontendContent(module=u''):
    """
    Frontend area is reachable under *http://[servername]:[port]/[module]*

    :param module: module name as string
    :return: renderd HTML-outpu of module or startpage
    """
    if module != "":
        if module == 'none':
            return render_template('frontend.area.html')
        try:
            current_mod = [frontend.modules[m] for m in frontend.modules if frontend.modules[m].info['path'] == module.split('/')[0]][0]
        except IndexError:
            current_mod = frontend.modules['startpages']
        return current_mod.getFrontendContent()
    current_mod = frontend.modules['startpages']
    return render_template('frontendframe.html', user=User.getUsers(login.current_user.get_id() or -1), current_mod=current_mod, modules=frontend.modules, app_name=current_app.config.get('PROJECT'), app_version=current_app.config.get('APP_VERSION'), areas=Settings.getFrontendSettings())
Exemple #7
0
def loginform():
    """
    Create login form under url */login* with username and password field.

    :return: rendered template */emonitor/login/templates/login.html*
    """
    if request.method == "POST":
        user = User.getUserByName(request.form.get('username'))

        if user and user.check_password(request.form.get('password')):
            if request.form.get('remember', '') == '1':
                flask_login.login_user(user, remember=True)
            else:
                flask_login.login_user(user, remember=False)
            return redirect(request.form.get("next") or "/")
        else:
            flash('admin.loginerror', 'error')
    return render_template('login.html', next=request.args.get('next', ''), app_name=current_app.config.get('PROJECT'), app_version=current_app.config.get('APP_VERSION'))
Exemple #8
0
def adminContent(module=''):
    """
    Admin area is reachable under *http://[servername]:[port]/admin/[module]*

    *module* will execute the *getAdminContent* method of registered module. If no nodule is given, the startpage of
    the admin area will be used

    :param module: module name as string
    :return: rendered HTML-output of module or startpage
    """
    if module == 'upgradedb':  # create new db-revision name given by revisionname
        msg = ""
        if request.args.get('revisionname', '') != '':
            msg = alembic.revision(request.args.get('revisionname'))
        return render_template('admin.dbrevision.html', modules=[], current_mod='upgradedb', user=User.getUsers(login.current_user.get_id() or -1), app_name=current_app.config.get('PROJECT'), app_version=current_app.config.get('APP_VERSION'), path='/admin/' + module, revisionname=request.args.get('revisionname', ''), msg=msg)
    try:
        current_mod = [admin.modules[m] for m in admin.modules if admin.modules[m].info['path'] == module.split('/')[0]][0]
    except IndexError:
        current_mod = admin.modules['startpages']
    return current_mod.getAdminContent(modules=admin.modules, current_mod=current_mod, user=User.getUsers(login.current_user.get_id() or -1), app_name=current_app.config.get('PROJECT'), app_version=current_app.config.get('APP_VERSION'), path='/admin/' + module, help='')