コード例 #1
0
def switchboard():
    links = [{
        'url': '/switchboard.html',
        'display': '<i class="material-icons left">home</i>Main</a>'
    }]
    navbar = elements.NavBar(links=links)
    return render_template("switchboard.html", navbar=navbar)
コード例 #2
0
def index():
    links = [{
        'url': '/index.html',
        'display': '<i class="material-icons left">home</i>Main</a>'
    }]
    navbar = elements.NavBar(links=links)
    if current_user.is_authenticated:
        return redirect(url_for("switchboard"))
    return render_template('index.html', navbar=navbar)
コード例 #3
0
def admingetusers():
    links = [{
        'url': '/switchboard.html',
        'display': '<i class="material-icons left">home</i>Main</a>'
    }, {
        'url': '#!',
        'display': 'List User'
    }]
    navbar = elements.NavBar(links=links)
    qusers = users.query.all()
    return render_template("admingetusers.html", users=qusers, navbar=navbar)
コード例 #4
0
def login():
    links = [{
        'url': '/index.html',
        'display': '<i class="material-icons left">home</i>Main</a>'
    }]
    navbar = elements.NavBar(links=links)
    userlogin = UserLoginForm()
    error = False
    errortype = ""
    if current_user.is_authenticated:
        return redirect(url_for("switchboard"))
    if userlogin.validate_on_submit():
        thisuser = users.query.filter(
            users.username.like(
                userlogin.username.data.strip())).one_or_none()
        if thisuser:
            if thisuser.active:
                if hashme(
                        userlogin.password.data) == thisuser.userpasswordhash:
                    thisuser.authenticated = True
                    db.session.add(thisuser)
                    db.session.commit()
                    login_user(thisuser,
                               remember=True,
                               duration=timedelta(minutes=45))
                    logthis(f"User Logged In: {userlogin.username.data}")
                    return redirect(url_for("switchboard"))
                else:
                    logthis(
                        f"Password Login Failed: {userlogin.username.data}")
                    error = True
                    errortype = "password"
            else:
                error = True
                errortype = "activation"
        else:
            logthis(f"User Login Failed: {userlogin.username.data}")
            error = True
            errortype = "username"
    return render_template("login.html",
                           userlogin=userlogin,
                           error=error,
                           errortype=errortype,
                           navbar=navbar)
コード例 #5
0
def adminupdateuser():
    navlinks = [{
        'url': '/switchboard.html',
        'display': '<i class="material-icons left">home</i>Main</a>'
    }, {
        'url': '/admingetusers.html',
        'display': ' List Users'
    }, {
        'url': '#!',
        'display': 'Update User'
    }]
    navbar = elements.NavBar(links=navlinks)
    confirm = False
    confirmlinks = [{
        'url': '/admingetusers.html',
        'display': 'Edit Other Users',
        'color': 'fgSNOW bgORANGE'
    }, {
        'url': '/adminupdateuser.html',
        'display': 'Create New User',
        'color': 'fgSNOW bgBLUE'
    }, {
        'url': '/switchboard.html',
        'display': 'Return',
        'color': 'fgSNOW bgGOLD'
    }]
    userdataupdateform = UserDataUpdateForm()
    if request.values.get("uuid"):
        thisuser = users.query.filter(
            users.uuid == request.values.get("uuid")).one_or_none()
        if request.method == "GET":
            userdataupdateform.username.data = thisuser.username
            userdataupdateform.usertype.data = thisuser.usertype
            userdataupdateform.active.data = thisuser.active
            userdataupdateform.id.data = thisuser.id
            userdataupdateform.uuid.data = thisuser.uuid
            userdataupdateform.notes.data = thisuser.notes
        elif request.method == "POST":
            if userdataupdateform.validate_on_submit():
                confirm = elements.ConfirmBar(links=confirmlinks,
                                              message="User Updated")
                thisuser.username = userdataupdateform.username.data.strip(
                ).lower()
                thisuser.usertype = int(userdataupdateform.usertype.data)
                if userdataupdateform.newpassword.data:
                    thisuser.userpasswordhash = hashme(
                        userdataupdateform.newpassword.data)
                thisuser.active = userdataupdateform.active.data
                thisuser.notes = userdataupdateform.notes.data
                db.session.commit()
                logthis(
                    f"WARN: {current_user.username} Updated User: {request.values.get('uuid')} {thisuser.username} {thisuser.usertype}"
                )
    else:
        if request.method == "POST" and userdataupdateform.validate_on_submit(
        ):
            confirm = elements.ConfirmBar(links=confirmlinks,
                                          message="User Updated")
            username = userdataupdateform.username.data
            usertype = userdataupdateform.usertype.data
            userpasswordhash = hashme(userdataupdateform.newpassword.data)
            usernotes = userdataupdateform.notes.data
            active = userdataupdateform.active.data
            newuser = users(username=username,
                            usertype=usertype,
                            userpasswordhash=userpasswordhash,
                            active=active,
                            notes=usernotes)
            db.session.add(newuser)
            db.session.commit()
            logthis(
                f"WARN: {current_user.username} Created User: {username} {usertype}"
            )
    return render_template("adminupdateuser.html",
                           userdataupdateform=userdataupdateform,
                           confirm=confirm,
                           navbar=navbar)