示例#1
0
def admin_user_area():
    """
    Show the user area of the admin user
    :return: the private area of the user if credentials are valid, otherwise it returns the home page
    """
    session_id = request.args.get('session-id', None)
    user_id = request.args.get('user-id', None)
    edit = request.args.get('edit', None)
    today = datetime.date.today()
    reservations_list = get_user_reservations_list(user_id)
    cars_reservations_list = get_cars_user_reservations_list(reservations_list)
    reservations_status_list = get_reservations_status_list(reservations_list)
    if edit == "true":
        edit_mode = True
    else:
        edit_mode = False
    user = get_user_by_id(user_id)
    if check_authentication(session_id, user_id) and is_admin_user(user_id):
        return render_template('user_area.html', user=user_id, session_id=session_id, edit_mode=edit_mode,
                               surname=user.surname, name=user.name, birthdate=user.birthdate, today=today,
                               reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                               reservations_status_list=reservations_status_list, admin=True)
    else:
        return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False,
                               preview_length=get_cars_preview().__len__(), del_session_cookie=True)
示例#2
0
def change_user_password():
    """
    Change the user's password
    :return: the private area of the user if credentials are valid (with an error message if an error occurred),
    otherwise it returns the home page
    """
    session_id = request.args.get('session-id', None)
    user_id = request.args.get('user-id', None)
    user = get_user_by_id(user_id)
    if request.method == 'POST':
        old_password = request.form['old-password']
        new_password = request.form['new-password']
        confirm_password = request.form['confirm-password']
        today = datetime.date.today()
        reservations_list = get_user_reservations_list(user_id)
        cars_reservations_list = get_cars_user_reservations_list(reservations_list)
        reservations_status_list = get_reservations_status_list(reservations_list)
        if check_authentication(session_id, user_id):
            is_password_updated = update_user_password(user_id, old_password, new_password, confirm_password)
        else:
            return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False,
                                   preview_length=get_cars_preview().__len__(), del_session_cookie=True)
        if is_password_updated == "OK":
            return render_template('user_area.html', user=user.id, session_id=session_id, edit_mode=False,
                                   surname=user.surname, name=user.name, birthdate=user.birthdate,
                                   feedback_msg="Password successfully updated!", today=today,
                                   reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                                   reservations_status_list=reservations_status_list)
        else:
            return render_template('user_area.html', user=user.id, session_id=session_id, edit_mode=False,
                                   surname=user.surname, name=user.name, birthdate=user.birthdate,
                                   feedback_msg=is_password_updated, today=today,
                                   reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                                   reservations_status_list=reservations_status_list)
示例#3
0
def edit_user_information():
    """
    Save the new user's information
    :return: the private area of the user if credentials are valid (with an error message if an error occurred),
    otherwise it returns the home page
    """
    session_id = request.args.get('session-id', None)
    old_username = request.args.get('user-id', None)
    user = get_user_by_id(old_username)
    if request.method == 'POST':
        surname = request.form['surname']
        name = request.form['name']
        birthdate = request.form['birthdate']
        new_username = request.form['username']
        today = datetime.date.today()
        reservations_list = get_user_reservations_list(old_username)
        cars_reservations_list = get_cars_user_reservations_list(reservations_list)
        reservations_status_list = get_reservations_status_list(reservations_list)
        if check_authentication(session_id, old_username):
            are_changes_valid = edit_user_info(name, surname, birthdate, old_username, new_username)
        else:
            return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False,
                                   preview_length=get_cars_preview().__len__(), del_session_cookie=True)
        if are_changes_valid == "OK":
            edit_session(session_id, new_username)
            return render_template('user_area.html', user=new_username, session_id=session_id, edit_mode=False,
                                   surname=surname, name=name, birthdate=birthdate, today=today,
                                   reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                                   reservations_status_list=reservations_status_list)
        else:
            return render_template('user_area.html', user=user.id, session_id=session_id, edit_mode=True,
                                   surname=user.surname, name=user.name, birthdate=user.birthdate,
                                   feedback_msg=are_changes_valid, today=today,
                                   reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                                   reservations_status_list=reservations_status_list)
示例#4
0
def get_users_list_for_reservations_list(reservations_list):
    """
    Get the list of users that have a reservation in reservations_list
    :param reservations_list: the list of reservations
    :return: a list containing objects of type User
    """
    users_list = []
    for reservation in reservations_list:
        users_list.append(get_user_by_id(reservation.id_user))
    return users_list
示例#5
0
def detele_car_reservation():
    """
    Delete the car reservation
    :return: the private area of the user if credentials are valid, otherwise it returns the home page
    """
    session_id = request.args.get('session-id', None)
    user_id = request.args.get('user-id', None)
    reservation_id = request.args.get('reservation-id', None)
    today = datetime.date.today()
    if check_authentication(session_id, user_id) and is_reservation_of_the_user(reservation_id, user_id):
        delete_reservation(reservation_id)
        reservations_list = get_user_reservations_list(user_id)
        cars_reservations_list = get_cars_user_reservations_list(reservations_list)
        reservations_status_list = get_reservations_status_list(reservations_list)
        user = get_user_by_id(user_id)
        return render_template('user_area.html', user=user_id, session_id=session_id, edit_mode=False,
                               surname=user.surname, name=user.name, birthdate=user.birthdate, today=today,
                               reservations_list=reservations_list, cars_reservations_list=cars_reservations_list,
                               reservations_status_list=reservations_status_list)
    else:
        return render_template('home.html', cars_list=get_cars_preview(), news_list=get_news_list(), authjs=False,
                               preview_length=get_cars_preview().__len__(), del_session_cookie=True)