예제 #1
0
def add_user():
    username = request.form.get('username')
    password = request.form.get('password')
    is_admin = request.form.get('is_admin')

    with config().db_connection() as db_conn:
        # TODO(tr) Do we need to encode the password as utf-8?
        User.create(db_conn, username, password, is_admin)
    return redirect(url_for('admin.admin_users'))
예제 #2
0
def check_login():
    username = request.form.get('username')
    password = request.form.get('password')
    remember = request.form.get(
        'remember') is not None  # only has a value if ticked

    with config().db_connection() as db_conn:
        user = User.verify(db_conn, username, password)
        if user is not None:
            current_app.logger.info('User {} is logging in.'.format(user.name))
            login_user(user, remember=remember)
            return redirect(url_for('home.index'))

    return render_template('login.html.mako', error="Wrong credentials")
예제 #3
0
 def load_user(id):
     return User.from_db(config.db_connection(), int(id))
예제 #4
0
def admin_sensors():
    with config().db_connection() as db_conn:
        users = User.get_users(db_conn)
        sensors = access.Sensor.get_all(db_conn)
    return render_template('admin_sensors.html.mako', sensors=sensors, users=users)
예제 #5
0
def admin_projects():
    with config().db_connection() as db_conn:
        users = User.get_users(db_conn)
        projects = access.Project.get_all(db_conn)
    return render_template('admin_projects.html.mako', projects=projects, users=users)
예제 #6
0
def delete_user(id):
    with config().db_connection() as db_conn:
        User.delete(db_conn, id)
    return redirect(url_for('admin.admin_users'))
예제 #7
0
def admin_users():
    with config().db_connection() as db_conn:
        users = User.get_users(db_conn)
    return render_template('admin_users.html.mako', users=users)