Esempio n. 1
0
def other_profile(username):
    user = User()
    logged = json.loads(session['log'])
    my_id = logged['id']
    if not user.exists(username):
        return render_template('print.html', title='Error', values=['This user does not exist'])
    if username != logged['login']:
        vis = Visit(my_id)
        vis.add_visit(username)
    user.dict_to_obj(logged)
    session["log"] = user.to_json()
    logged = json.loads(session['log'])
    session["user_id"] = ''
    res = user.query('''SELECT users.id, login, gender, email, pic_id, popularity, firstname, lastname, longitude, latitude, bio, \
            orientation, birthdate, city FROM users
            WHERE login = ?''', (username,))
    profile_pic = user.query('''SELECT * FROM pics WHERE id = ?''', (res[0][4],))
    pics = user.query('''SELECT * FROM pics WHERE user_id = ? AND id != ?''', (res[0][0], res[0][4]))
    info = {'id': res[0][0], 'login': res[0][1], 'gender': res[0][2], 'email': res[0][3], 'pic_id': res[0][4],
            'popularity': res[0][5], 'firstname': res[0][6], 'lastname': res[0][7], 'longitude': res[0][8],
            'latitude': res[0][9], 'bio': res[0][10], 'orientation': res[0][11], "birthdate": res[0][12],
            "city": res[0][13], "pics": pics, "likes": user.does_like(my_id, username),
            "blocks": user.does_block(my_id, username)}
    if len(profile_pic) > 0:
        info.update({'profile_pic': profile_pic[0]})
    return render_template('profil.html', info=info, user=logged)
Esempio n. 2
0
def report_user():
    us = User()
    user_id = request.args.get('id')
    info = json.loads(session['log'])
    ct = us.count_query('''DELETE FROM reports WHERE to_id = ? AND from_id = ?''', (user_id, info['id']))
    if ct == 0:
        us.query('''INSERT INTO reports(to_id, from_id) VALUES(?, ?)''', (user_id, info['id']))
    return jsonify(result=[])
Esempio n. 3
0
def block_user():
    us = User()
    user_id = request.args.get('id')
    info = json.loads(session['log'])
    res = False
    ct = us.count_query('''DELETE FROM blocks WHERE to_id = ? AND from_id = ?''', (user_id, info['id']))
    if ct == 0:
        res = True
        us.query('''INSERT INTO blocks(to_id, from_id) VALUES(?, ?)''', (user_id, info['id']))
    return jsonify(result=res)
Esempio n. 4
0
def profile():
    user = User()
    info = json.loads(session['log'])
    user.dict_to_obj(info)
    session['log'] = user.to_json()
    info = json.loads(session['log'])
    profile_pic = user.query('''SELECT * FROM pics WHERE id = ?''', (info['pic_id'],))
    pics = user.query('''SELECT * FROM pics WHERE user_id = ? AND id != ?''', (info['id'], info['pic_id']))
    info['pics'] = pics
    if len(profile_pic) > 0:
        info['profile_pic'] = profile_pic[0]
    return render_template('profil.html', info=info)