def delete_hashtag(): user = User() info = json.loads(session['log']) user.dict_to_obj(info) my_hash = request.form['hashtag'] user.delete_hashtag(my_hash) return jsonify(result=[])
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 get_hashtags(): user = User() if 'login' not in request.args: info = json.loads(session['log']) user.dict_to_obj(info) else: user.dict_to_obj({'id': request.args.get('login')}) val = user.get_hashtags() val = json.dumps(val) return val
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 treatlocation(): user = User() info = json.loads(session['log']) user.dict_to_obj(info) longitude = request.form['longitude'] latitude = request.form['latitude'] response = requests.get("https://nominatim.openstreetmap.org/reverse?format=json&zoom=10&" + "lat=" + latitude + "&lon=" + longitude) result = response.json() city = result["address"]["city"] user.updatelocation(longitude, latitude) user.update_city(city) return ""
def register_check_input(): user = User() user.dict_to_obj(request.form) error = user.check_password() error.update(user.check_username()) error.update(user.check_email()) liste = list() if True in error.values(): for key, value in error.items(): if value is True: liste.append(key) else: user.register() liste.append("You were successfully registered.") liste.append("An email was sent for account confirmation.") return render_template('print.html', title="User Creation", values=liste)
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
def update(): user = User() info = json.loads(session['log']) user.dict_to_obj(info) return render_template('update.html', info=info)