Esempio n. 1
0
def change_password_page(user_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    if current_user != user:
        abort(403)
    if request.method == 'GET':
        real_name = UserDatabaseOPS.select_user_detail(user.username)
        return render_template('password_change.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               error=False)
    else:
        current_password = request.form['CurrentPassword']
        new_password = request.form['NewPassword']
        confirm_password = request.form['ConfirmPassword']
        real_name = UserDatabaseOPS.select_user_detail(user.username)
        user = UserDatabaseOPS.select_user_with_id(user_id)
        if current_password != user.password:
            return render_template('password_change.html',
                                   signedin=True,
                                   user=user,
                                   real_name=real_name,
                                   password_error=True)
        elif new_password != confirm_password:
            return render_template('password_change.html',
                                   signedin=True,
                                   user=user,
                                   real_name=real_name,
                                   password_match_error=True)
        else:
            UserDatabaseOPS.update_user(user.username, new_password,
                                        user.profile_pic, user.cover_pic,
                                        user.mail_address)
        return render_template('password_change.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               success=True)
Esempio n. 2
0
def settings_page(user_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    if current_user != user:
        abort(403)
    if request.method == 'GET':

        real_name = UserDatabaseOPS.select_user_detail(user.username)
        return render_template('settings_page.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               error=False)
    else:
        if 'change-mail' in request.form:
            mail = request.form['mail_address']
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            UserDatabaseOPS.update_user(user.username, user.password,
                                        user.profile_pic, user.cover_pic, mail)
            changed_user = UserDatabaseOPS.select_user_with_id(user_id)
        elif 'add-group' in request.form:
            user = UserDatabaseOPS.select_user_with_id(user_id)
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            group_name = request.form['group_name']
            group_profile_pic = request.form['group_picture_url']
            group_description = request.form['group_description']
            group_id = GroupDatabaseOPS.add_group(group_name,
                                                  group_profile_pic,
                                                  group_description)
            GroupDatabaseOPS.add_group_participation(group_id, user_id)
            changed_user = UserDatabaseOPS.select_user_with_id(user_id)

        return render_template('settings_page.html',
                               signedin=True,
                               user=changed_user,
                               real_name=real_name,
                               success=True)
Esempio n. 3
0
 def get_real_name(user_id):
     user = UserDatabaseOPS.select_user_with_id(user_id)
     real_name = UserDatabaseOPS.select_user_detail(user.username)
     return real_name
Esempio n. 4
0
def home_page(user_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    if current_user != user:
        abort(403)
    real_name = UserDatabaseOPS.select_user_detail(user.username)
    if request.method == 'GET':
        my_followings_id = InteractionDatabaseOPS.select_followings_from_user_interaction(
            user.id)
        my_followings_user = []
        my_followings_user.append(user)
        my_followings_knots = []
        my_temp_knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id)
        new_groups = GroupDatabaseOPS.find_groups()
        for counter in my_temp_knot_list:
            my_followings_knots.append(counter)
        for index in my_followings_id:
            my_followings_user.append(
                UserDatabaseOPS.select_user_with_id(index))
            temp_knot_list = KnotDatabaseOPS.select_knots_for_owner(index)
            for element in temp_knot_list:
                my_followings_knots.append(element)
        return render_template('home_page.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               my_followings_knots=my_followings_knots,
                               my_followings_user=my_followings_user,
                               new_groups=new_groups)
    else:
        if 'add_knot' in request.form:
            KnotDatabaseOPS.add_knot(user_id, request.form['new_knot_content'],
                                     0, 0, False,
                                     datetime.now().date().isoformat())
            return redirect(url_for('site.home_page', user_id=user.id))
        elif 'delete' in request.form:
            KnotDatabaseOPS.delete_knot(request.form['delete'])
            return redirect(url_for('site.home_page', user_id=user.id))
        elif 'update_knot' in request.form:
            KnotDatabaseOPS.update_knot(user.id,
                                        request.form['update_knot_content'], 0,
                                        0, False,
                                        datetime.now().date().isoformat(),
                                        request.form['update_knot'])
            return redirect(url_for('site.home_page', user_id=user.id))
        elif 'search' in request.form:
            query = request.form['search_bar']
            print(query)
            return redirect(
                url_for('site.search_page', user_id=user.id, query=query))
        elif 'like' in request.form:
            is_like = NotificationDatabaseOPS.check_like(
                request.form['like'], user.id, True)
            if is_like:
                NotificationDatabaseOPS.delete_relation(
                    request.form['like'], user.id, True)
                NotificationDatabaseOPS.decrease_knot_like(
                    request.form['like'])
            else:
                NotificationDatabaseOPS.insert_relation(
                    request.form['like'], user.id, True)
                NotificationDatabaseOPS.increase_knot_like(
                    request.form['like'])
            return redirect(url_for('site.home_page', user_id=user.id))
        elif 'reknot' in request.form:
            is_reknot = NotificationDatabaseOPS.check_reknot(
                request.form['reknot'], user.id, False)
            if is_reknot:
                NotificationDatabaseOPS.delete_relation(
                    request.form['reknot'], user.id, False)
                NotificationDatabaseOPS.decrease_knot_reknot(
                    request.form['reknot'])
            else:
                NotificationDatabaseOPS.insert_relation(
                    request.form['reknot'], user.id, False)
                NotificationDatabaseOPS.increase_knot_reknot(
                    request.form['reknot'])
            return redirect(url_for('site.home_page', user_id=user.id))
Esempio n. 5
0
def user_profile_page(user_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    if user is -1:
        abort(404)
    user_check = True
    if current_user != user:
        user_check = False
    if request.method == 'GET':
        real_name = UserDatabaseOPS.select_user_detail(user.username)
        my_city = CityDatabaseOPS.select_city(real_name.city,
                                              real_name.country)
        cities = CityDatabaseOPS.select_all_cities()
        knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id)
        like_list = KnotDatabaseOPS.get_likes(user.id)
        followers = UserDatabaseOPS.get_followers(user.id)
        followings = UserDatabaseOPS.get_following(user.id)
        lengths = {
            'knot_len': len(knot_list),
            'like_len': len(like_list),
            'followers_len': len(followers),
            'followings_len': len(followings)
        }
        random_users = UserDatabaseOPS.get_random_users(current_user.id)
        return render_template('user_profile.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               my_city=my_city,
                               cities=cities,
                               knot_list=knot_list,
                               user_check=user_check,
                               likes=like_list,
                               followers=followers,
                               followings=followings,
                               lengths=lengths,
                               random=random_users)
    else:
        if 'changeImage' in request.form:
            user.profile_pic = request.form['imageURL']
            my_name = request.form['my_name']
            my_surname = request.form['my_surname']
            user.cover_pic = request.form['coverURL']
            city_id = request.form['city_id']
            cities = CityDatabaseOPS.select_all_cities()

            real_name = UserDatabaseOPS.select_user_detail(user.username)

            if real_name == -1:
                UserDatabaseOPS.add_user_detail(user.username, my_name,
                                                my_surname, city_id)
            else:
                UserDatabaseOPS.update_user_detail(user.username, my_name,
                                                   my_surname, city_id)

            UserDatabaseOPS.update_user(user.username, user.password,
                                        user.profile_pic, user.cover_pic,
                                        user.mail_address)

            real_name = UserDatabaseOPS.select_user_detail(user.username)
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id)
            like_list = KnotDatabaseOPS.get_likes(user_id)
            followers = UserDatabaseOPS.get_followers(user_id)
            followings = UserDatabaseOPS.get_following(user_id)
            lengths = {
                'knot_len': len(knot_list),
                'like_len': len(like_list),
                'followers_len': len(followers),
                'followings_len': len(followings)
            }
            random_users = UserDatabaseOPS.get_random_users(current_user.id)

        if 'deleteReal' in request.form:
            user = UserDatabaseOPS.select_user_with_id(user_id)
            cities = CityDatabaseOPS.select_all_cities()
            UserDatabaseOPS.delete_user_detail(user.username)
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id)
            like_list = KnotDatabaseOPS.get_likes(user.id)
            followers = UserDatabaseOPS.get_followers(user.id)
            followings = UserDatabaseOPS.get_following(user.id)
            lengths = {
                'knot_len': len(knot_list),
                'like_len': len(like_list),
                'followers_len': len(followers),
                'followings_len': len(followings)
            }
            random_users = UserDatabaseOPS.get_random_users(current_user.id)

        if 'follow' in request.form:
            user = UserDatabaseOPS.select_user_with_id(user_id)
            target_user = request.form['target_user']
            cities = CityDatabaseOPS.select_all_cities()
            UserDatabaseOPS.follow(user_id, target_user)
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id)
            like_list = KnotDatabaseOPS.get_likes(user.id)
            followers = UserDatabaseOPS.get_followers(user.id)
            followings = UserDatabaseOPS.get_following(user.id)
            lengths = {
                'knot_len': len(knot_list),
                'like_len': len(like_list),
                'followers_len': len(followers),
                'followings_len': len(followings)
            }
            random_users = UserDatabaseOPS.get_random_users(current_user.id)

        return render_template('user_profile.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               my_city=my_city,
                               cities=cities,
                               knot_list=knot_list,
                               user_check=user_check,
                               likes=like_list,
                               followers=followers,
                               followings=followings,
                               lengths=lengths,
                               random=random_users)
Esempio n. 6
0
def sales_page(user_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    _isSearched = False
    if current_user != user:
        abort(403)
    if request.method == 'GET':
        real_name = UserDatabaseOPS.select_user_detail(user.username)
        currency_list = CurrencyDatabaseOPS.select_all_currencies()
        my_city = CityDatabaseOPS.select_city(real_name.city,
                                              real_name.country)
        cities = CityDatabaseOPS.select_all_cities()
        my_item_list = SaleDatabaseOPS.select_sales_of_a_user(user.username)

    else:
        _isSearched = True
        if 'add_new_item' in request.form:

            real_name = UserDatabaseOPS.select_user_detail(user.username)
            currency_list = CurrencyDatabaseOPS.select_all_currencies()
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            cities = CityDatabaseOPS.select_all_cities()

            SaleDatabaseOPS.add_item(request.form['item_name_form'],
                                     request.form['item_picture_form'],
                                     request.form['item_price_form'],
                                     request.form['item_description_form'],
                                     request.form['item_change_currency'])

            SaleDatabaseOPS.add_sale(
                user_id,
                SaleDatabaseOPS.select_new_item_id(
                    request.form['item_name_form'],
                    request.form['item_picture_form'],
                    request.form['item_price_form']), my_city.id,
                request.form['sale_end_date'])
            my_item_list = SaleDatabaseOPS.select_sales_of_a_user(
                user.username)

        if 'delete_item' in request.form:
            user = UserDatabaseOPS.select_user_with_id(user_id)
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            currency_list = CurrencyDatabaseOPS.select_all_currencies()
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            cities = CityDatabaseOPS.select_all_cities()

            SaleDatabaseOPS.delete_sale(request.form['delete_this_sale'])

            my_item_list = SaleDatabaseOPS.select_sales_of_a_user(
                user.username)

        if 'search_item' in request.form:
            user = UserDatabaseOPS.select_user_with_id(user_id)
            real_name = UserDatabaseOPS.select_user_detail(user.username)
            currency_list = CurrencyDatabaseOPS.select_all_currencies()
            my_city = CityDatabaseOPS.select_city(real_name.city,
                                                  real_name.country)
            cities = CityDatabaseOPS.select_all_cities()
            my_item_list = 1

            if request.form['choose_search'] == 'username':
                my_item_list = SaleDatabaseOPS.select_sales_of_a_user(
                    request.form['keyword'])
            elif request.form['choose_search'] == 'closest':
                my_item_list = SaleDatabaseOPS.select_closest_items(
                    user.username, my_city.id)
            elif request.form['choose_search'] == 'price':
                my_item_list = SaleDatabaseOPS.select_items_by_price(
                    user.username, request.form['keyword'],
                    request.form['currency_select'])
            elif request.form['choose_search'] == 'currency':
                my_item_list = SaleDatabaseOPS.select_items_by_currency(
                    request.form['currency_select'], user.username)
            elif request.form['choose_search'] == 'place':
                my_item_list = SaleDatabaseOPS.select_items_by_place(
                    request.form['city_select'])
            elif request.form['choose_search'] == 'newest':
                my_item_list = SaleDatabaseOPS.select_newest_items(
                    user.username)

    return render_template('sales_knitter.html',
                           signedin=True,
                           user=user,
                           real_name=real_name,
                           my_city=my_city,
                           cities=cities,
                           currency_list=currency_list,
                           my_item_list=my_item_list,
                           isSearched=_isSearched)
Esempio n. 7
0
def shelf_books_page(user_id, shelf_id):
    user = UserDatabaseOPS.select_user_with_id(user_id)
    if current_user != user:
        abort(403)
    real_name = UserDatabaseOPS.select_user_detail(user.username)
    if request.method == 'GET':
        my_shelves = ShelfDatabaseOPS.select_shelves(user_id)
        my_books = []
        my_quotes = []
        my_books = BookDatabaseOPS.select_books_from_shelf(shelf_id, user_id)
        my_quotes = QuoteDatabaseOPS.select_quotes(user_id)
        return render_template('books_page.html',
                               signedin=True,
                               user=user,
                               real_name=real_name,
                               my_shelves=my_shelves,
                               my_books=my_books,
                               my_quotes=my_quotes)
    else:
        if 'add_shelf' in request.form:
            ShelfDatabaseOPS.add_shelf(request.form['shelf_name'],
                                       request.form['first_shelf'], user_id)
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'delete_shelf' in request.form:
            ShelfDatabaseOPS.delete_shelf(request.form['delete_shelf'])
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'update_shelf' in request.form:
            ShelfDatabaseOPS.update_shelf_name(
                request.form['update_shelf'],
                request.form['updated_shelf_name'])
            ShelfDatabaseOPS.update_main_shelf(
                request.form['update_shelf'],
                request.form['updated_first_shelf'])
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'add_book' in request.form:
            BookDatabaseOPS.add_book(
                request.form['book_title'], request.form['book_cover'],
                request.form['book_writer'], request.form['book_genre'],
                request.form['date_read'], request.form['user_rate'],
                request.form['book_review'], request.form['add_book'], user_id)
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'delete_book' in request.form:
            BookDatabaseOPS.delete_book(request.form['delete_book'])
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'update_book' in request.form:
            BookDatabaseOPS.update_book(request.form['update_book'],
                                        request.form['updated_book_title'],
                                        request.form['updated_book_cover'],
                                        request.form['updated_book_writer'],
                                        request.form['updated_book_genre'],
                                        request.form['updated_date_read'],
                                        request.form['updated_user_rate'],
                                        request.form['updated_book_review'],
                                        request.form['updated_book_shelf'],
                                        user_id)
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'add_quote' in request.form:
            QuoteDatabaseOPS.add_quote(request.form['quote_content'],
                                       request.form['quoted_book'], user_id)
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'delete_quote' in request.form:
            QuoteDatabaseOPS.delete_quote(request.form['delete_quote'])
            return redirect(url_for('site.books_page', user_id=user.id))
        elif 'update_quote' in request.form:
            QuoteDatabaseOPS.update_quote(
                request.form['update_quote'],
                request.form['updated_quote_content'],
                request.form['updated_quote_book'])
            return redirect(url_for('site.books_page', user_id=user.id))