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)
def login_validation(): user = User() validity = user.auth(request.form['login'], request.form['password']) if validity: session['log'] = user.to_json() return redirect(url_for('chat')) else: return render_template('print.html', title="Login error", values=["An error occurred during your login attempt."])
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)
def login_update(var): user = User() info = json.loads(session['log']) user.dict_to_obj(info) if var == "login": user.login = request.form['login'] message = user.update_login() elif var == "firstname": user.firstname = request.form["firstname"] message = user.update_firstname() elif var == "lastname": user.lastname = request.form['lastname'] message = user.update_lastname() elif var == "password": user.oldpassword = request.form['oldpassword'] user.password = request.form['password'] user.repeatpassword = request.form['repeatpassword'] message = user.update_password() elif var == "email": user.email = request.form['email'] message = user.update_email() elif var == "gender": user.gender = request.form['gender'] message = user.update_gender() elif var == "orientation": user.orientation = request.form['orientation'] message = user.update_orientation() elif var == "bio": user.bio = request.form['bio'] message = user.update_bio() elif var == "birthdate": user.birthdate = request.form['birthdate'] message = user.update_birthdate() else: message = '' session['log'] = user.to_json() return message