Esempio n. 1
0
def load_user_info():
    """Load info for the current user and put it in 'g'."""
    user_id = session.get('user_id')
    (user_id, username, admin, directory) = users.user_info(user_id)
    g.user_id = user_id
    g.username = username
    g.admin = admin
    g.directory = directory
Esempio n. 2
0
def load_user_info():
    """Load info for the current user and put it in 'g'."""
    user_id = session.get('user_id')
    (user_id, username, admin, directory) = users.user_info(user_id)
    g.user_id = user_id
    g.username = username
    g.admin = admin
    g.directory = directory
Esempio n. 3
0
 def get(self):
     username = None
     user_id = session.get('user_id')
     if user_id is not None:
         (user_id, username, admin, directory) = users.user_info(user_id)
     running = g.job_manager.count_jobs(g.db, 'running')
     waiting = g.job_manager.count_jobs(g.db, 'waiting')
     return {'version': g.version,
             'name': g.config.get('NAME'),
             'username': username,
             'jobs_running': running,
             'jobs_waiting': waiting}
Esempio n. 4
0
 def decorated(*args, **kwargs):
     user_id = session.get('user_id')
     if user_id is None:
         # user is not logged in
         abort(401)
     (user_id, username, admin, directory) = users.user_info(user_id)
     if not admin:
         # user does not have administrator rights
         abort(403)
     g.user_id = user_id
     g.username = username
     g.admin = admin
     g.directory = directory
     return f(*args, **kwargs)
Esempio n. 5
0
 def decorated(*args, **kwargs):
     user_id = session.get('user_id')
     if user_id is None:
         # user is not logged in
         abort(401)
     (user_id, username, admin, directory) = users.user_info(user_id)
     if not admin:
         # user does not have administrator rights
         abort(403)
     g.user_id = user_id
     g.username = username
     g.admin = admin
     g.directory = directory
     return f(*args, **kwargs)
Esempio n. 6
0
def change_pwd(user_id):
    error = None
    if request.method == 'POST':
        password1 = request.form['password1']
        password2 = request.form['password2']
        if password1 != password2:
            error = "Passwords don't match!"
        else:
            users.update_password(user_id, password1)
            return redirect(url_for('.list_users'))
    u = users.user_info(user_id)
    return render_template('admin_change_pwd.html',
                           title="Change Password for %s" % u['username'],
                           user=u,
                           error=error)
Esempio n. 7
0
def edit_user(user_id):
    if request.method == 'POST':
        action = request.form['button']
        if action == 'Delete':
            users.delete_user(user_id)
        else:
            username = request.form['username']
            directory = request.form['directory']
            users.update(user_id, username, directory)
        return redirect(url_for('.list_users'))
    (user_id, username, admin, directory) = users.user_info(user_id)
    return render_template('edit_user.html',
                           title='User %s' % username,
                           user_id=user_id, username=username,
                           admin=admin, directory=directory)
Esempio n. 8
0
def change_pwd(user_id):
    error = None
    if request.method == 'POST':
        password1 = request.form['password1']
        password2 = request.form['password2']
        if password1 != password2:
            error = "Passwords don't match!"
        else:
            users.update_password(user_id, password1)
            return redirect(url_for('.list_users'))
    u = users.user_info(user_id)
    return render_template('admin_change_pwd.html',
                           title="Change Password for %s" % u['username'],
                           user=u,
                           error=error)
Esempio n. 9
0
def edit_user(user_id):
    if request.method == 'POST':
        action = request.form['button']
        if action == 'Delete':
            users.delete_user(user_id)
        else:
            username = request.form['username']
            directory = request.form['directory']
            users.update(user_id, username, directory)
        return redirect(url_for('.list_users'))
    (user_id, username, admin, directory) = users.user_info(user_id)
    return render_template('edit_user.html',
                           title='User %s' % username,
                           user_id=user_id,
                           username=username,
                           admin=admin,
                           directory=directory)
Esempio n. 10
0
def profile(id):
    allow = False
    if users.user_id == 0:
        redirect("/")
    if users.is_user() and users.user_id() == id:
        allow = True
    elif users.is_user():
        sql = "SELECT 1 FROM coaches WHERE trainer_id=:trainer_id AND coach_id=:coach_id AND visible=1"
        result = db.session.execute(sql, {"trainer_id":id, "coach_id":users.user_id()})
        if result.fetchone() != None:
            allow = True
    if not allow:
        return render_template("error.html", message="Ei oikeutta nähdä sivua!")
    
    weight_now = weights.get_last(id)
    user = users.user_info(id)
    bmi = (10000 * weight_now[0] / (user[2]*user[2]))
    bmi_string = float("{:.2f}".format(bmi))
    to_target = float("{:.2f}".format(weight_now[0] - user[1]))
    
    return render_template("profile.html", username=user[0], weight_now=weight_now[0], weight_target=user[1],
        to_target=to_target, bmi=bmi_string)
Esempio n. 11
0
 def setUp(self):
     self.passwd = "$2a$12$CyLyLDPA5NFTY48o3fANQOEsni38JgHBk3FNwdUFd1OwYMBZxN146" 
     db.delete('Users', where='id > 0')
     self.uid = db.insert('Users', uname='kevin', role=1, password=self.passwd)
     self.uinfo = users.user_info()