Example #1
0
def send_message(api, friends):
    while True:
        os.system('cls')
        print('Отправить сообщение\n')
        print('1. Выбрать друга')
        print('2. Оправить конткретному пользователю (потребуется ввод id)')
        print('3. Назад')
        choice = input('Выберите: ')

        if choice == '1':  # Отправить другу
            os.system('cls')
            f = friends.select_friend()
            if f != '':
                os.system('cls')
                print('Выбран(а)', f['first_name'], f['last_name'])
                messages.send_msg(api, f['user_id'])
                print('Отправлено!')
                os.system('pause')
        elif choice == '2':  # Отправить пользователю
            uid = users.get_id()
            while users.check_id(uid, api):
                print('Аккаунт удален или не существует!')
                os.system('pause')
                uid = users.get_id()

            user = api.users.get(user_ids=uid)
            user = user[0]
            print('Выбран(а)', user['first_name'], user['last_name'])
            messages.send_msg(api, uid)
            print('Отправлено!')
            os.system('pause')
        elif choice == '3':
            return None
def profile():
    user_id = users.get_id(session.get("username"))
    user_reviews = reviews.select_reviews_user_id(user_id)
    if not user_reviews:
        reviews_count = 0
        last_log = 0
    else:
        reviews_count = user_reviews[0][5]

    # Ladataan eri sivu jos käyttäjä on admin
    if users.privileges(users.get_id(session.get("username"))):
        return render_template("add_book.html", reviews=user_reviews, reviews_count=reviews_count)
    return render_template("profile.html", reviews=user_reviews, reviews_count=reviews_count, last_log=users.last_log(user_id))
def delete_review(id):
    user_id = users.get_id(session.get("username"))
    reviews.delete_review(id)
    user_reviews = reviews.select_reviews_user_id(user_id)
    # Tarkistetaan sisälsikö vastaus tuloksia
    if not user_reviews:
        return render_template("profile.html", reviews=user_reviews, reviews_count=0, last_log=users.last_log(user_id))
    else:
        return render_template("profile.html", reviews=user_reviews, reviews_count=user_reviews[0][5], last_log=users.last_log(user_id))
def search():
    searchterm = request.form["searchterm"].lower()
    message = "Haukutulokset:"
    found_books = books.search_by(searchterm)

    # Luodaan uusi viesti jos haku ei tuota tulosta
    if not found_books:
        message = "Haullesi ei löytynyt tuloksia :("
    if session.get("username", None) != None and users.privileges(users.get_id(session.get("username"))):
        return render_template("delete_book.html", books=found_books, message="Hei admin, poista kirja tästä")
    return render_template("search_results.html", books=found_books, message=message)
Example #5
0
def rate(recipe_id, rating):
    username = users.get_user()
    if username is None:
        return False
    user_id = users.get_id()
    sql = "INSERT INTO Ratings(recipe_id, rating, user_id) VALUES (:recipe_id, :rating, :user_id)"
    db.session.execute(sql, {
        "recipe_id": recipe_id,
        "rating": rating,
        "user_id": user_id
    })
    db.session.commit()
    return True
Example #6
0
def get_rating_status(recipe_id):
    username = users.get_user()
    if username is None:
        return True
    user_id = users.get_id()
    sql = "SELECT COUNT(*) FROM Ratings WHERE recipe_id=:recipe_id AND user_id=:user_id"
    result = db.session.execute(sql, {
        "recipe_id": recipe_id,
        "user_id": user_id
    })
    count = result.fetchone()[0]
    if count:
        return True
    return False
def create():
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]

        # Vielä viimeinen tarkistus onko salasana oikean pituinen
        if len(password) < 4:
            return render_template("create_account.html", message="Salasanan tulee olla vähintään neljä merkkiä")

        if users.register(username, password):
            session["username"] = username
            users.start_session(users.get_id(session.get("username")))
            return render_template("index.html")
        else:
            return render_template("create_account.html", message="Käyttäjänimi otettu")
    else:
        return render_template("create_account.html", message="Luo uusi käyttäjä")
def login():
    username = request.form["username"]
    password = request.form["password"]

    user = users.login(username, password)

    if user == None:
        return render_template("login.html", message="Ei tämänimistä profiilia")
    else:
        hash_value = user[0]
        if check_password_hash(hash_value, password):
            session["username"] = username
            users.start_session(users.get_id(session.get("username")))
            return render_template("index.html")
        else:
            # Tämä pitää korvaa virheilmoituksella index.html-tiedoston omalla virheilmoituksella
            return render_template("login.html", message="Väärä käyttäjätunnus tai salasana")
Example #9
0
def restaurant(id):
	info = restaurants.get_info(id)
	reviews_list = reviews.get_list(id)
	if request.method == "POST":
		check_csfr(request.form["csrf_token"], users.get_csrf())
		if "lisays" in request.form:
			stars = int(request.form["stars"])
			comment = request.form["comment"]
			if len(comment) > 500:
				return render_template("restaurant.html", errormessage="Arvostelun tulee olla alle 500 merkkiä", info=info[0], open=info[1], id=id, reviews=reviews_list)
			user_id = users.get_id()
			reviews.add_review(id, user_id, stars, comment)
		if "poisto" in request.form:
			review_id = request.form["review_id"]
			reviews.remove_review(review_id)
	info = restaurants.get_info(id)
	reviews_list = reviews.get_list(id)
	return render_template("restaurant.html", info=info[0], open=info[1], id=id, reviews=reviews_list)
def delete_profile():
    if not users.delete_account(users.get_id(session.get("username"))):
        return render_template("error.html", message="Adminkäyttäjää ei voi poistaa!")

    del session["username"]
    return redirect("/")