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'))
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")
def load_user(id): return User.from_db(config.db_connection(), int(id))
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)
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)
def delete_user(id): with config().db_connection() as db_conn: User.delete(db_conn, id) return redirect(url_for('admin.admin_users'))
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)