Exemplo n.º 1
0
def update_account():
    """
        Form to update information of an User.
    """

    form = UpdateAccountForm()
    if form.validate_on_submit():

        # assign new data for user
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        if form.password.data:
            hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            current_user.password = hashed_password
        current_user.username = form.username.data.lower()
        current_user.email = form.email.data
        current_user.phone_number = form.phone_number.data
        current_user.text_notif = form.text_notif.data
        db.session.commit()

        flash('Your account has been updated!', 'success')
        return redirect(url_for('bp_users.profile'))

    elif request.method == 'GET':
        # fill in form
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.phone_number.data = current_user.phone_number
        form.text_notif.data = current_user.text_notif

    image_file = url_for('static', filename='images/avi/' + current_user.image_file)
    return render_page('user/update_account.html', title='Profile Info', image_file=image_file, form=form)
Exemplo n.º 2
0
def register():
    """
        Creates a new user.
    """
    # if user is already logged in redirect them home
    if current_user.is_authenticated:
        return redirect(url_for('bp_main.home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        # generate password hash
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')

        # create user
        user = User(username=form.username.data.lower(), email=form.email.data.lower(),
                    phone_number=clean_phone_number(form.phone_number.data), password=hashed_password, text_notif=form.text_notif.data)
        db.session.add(user)
        db.session.commit()

        # send welcome email
        send_email(subject="Welcome!",
                    msg_body=registerd_msg(user),
                    button=("Create a Session", url_for('bp_posts.new_session')),
                    recipient=user)
        flash('Thanks for signing up! You are now able to log in', 'success')
        return redirect(url_for('bp_users.login'))

    return render_page('public/register.html', title='Register', form=form)
Exemplo n.º 3
0
def session(session_id):
    """
        Session view for user, gives a breakdown of credit costs of each of
        the sound files and a total. User's can remove sounds from session if they
        wish.

        session_id: int
    """
    # get the session by id
    session = Session.query.get_or_404(session_id)

    if current_user != session.user:
        abort(403)  # only the user that's session it should be able to view

    session_credits = 0
    # only have to assign credits once
    if session.sounds[0].credits == 0:
        for sound in session.sounds:
            # assign credit amount to each sound
            credits = get_sound_credits(sound, current_user.id)
            sound.credits = credits
            session_credits += credits

        # assing total credit amount for session
        session.credits = session_credits
        db.session.commit()

    return render_page("user/session.html",
                       session=session,
                       total_credits=session.credits,
                       title='Session')
Exemplo n.º 4
0
def password_reset(token):
    """
        Resets user's password provided the token parameter is a valid token.
    """
    # if user is already logged in redirect them home
    if current_user.is_authenticated:
        return redirect(url_for('bp_main.home'))

    # verify token
    user = User.verify_reset_token(token)
    if not user:  # token in not valid
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('bp_users.reset_request'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        # generate passowrd hash
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')

        # update user's password
        user.password = hashed_password
        db.session.commit()

        flash('Your password has been reset.', 'success')
        return redirect(url_for('bp_users.login'))

    return render_page('public/reset_token.html', title='Reset PW', form=form)
Exemplo n.º 5
0
def new_session():
    """
        Creates a new session, is a dynamic form to add sounds files to session.
    """
    form = SessionForm()
    if form.validate_on_submit():
        # Create session
        new_session = Session()
        new_session.user_id = current_user.id
        new_session.session_name = form.session_name.data
        db.session.add(new_session)

        sound_num = 1  # sound_num is used to name audio files
        for sound in form.sounds.data:
            # Create sound
            new_sound = Sound()
            new_sound.options = sound['options']
            new_sound.machine = sound['machine']
            new_sound.file_name = save_audio_file(sound['file_name'],
                                                  sound_num, new_session.id,
                                                  current_user.id)
            new_session.sounds.append(new_sound)

            sound_num += 1

        db.session.commit()
        return redirect(url_for('bp_posts.session', session_id=new_session.id))

    return render_page("form.html",
                       form=form,
                       title='New Session',
                       include_form_script=True)
Exemplo n.º 6
0
def pricing():
    """
        The pricing page where users can choose which
        credit package to purchase.
    """
    pricing_options = app.config["PRICING_OPTIONS"]
    return render_page("public/pricing.html",
                       title='Pricing',
                       options=pricing_options)
Exemplo n.º 7
0
def profile():
    """
        The current user's profile giving them a list of all
        their sessions and the option to update their information.
    """
    users_sessions = Session.query.filter_by(user_id=current_user.id)
    page = request.args.get('page', 1, type=int)

    sessions_paginated = users_sessions\
        .order_by(Session.date_posted.desc())\
        .paginate(page=page, per_page=6)

    return render_page('user/profile.html', title='Profile',page=page, sessions=sessions_paginated)
Exemplo n.º 8
0
def checkout(num_of_credits):
    """
        Checkout page that has paypal button.
    """
    price = None
    # get pricing oftion with same credits value as num_of_credits
    for option in app.config["PRICING_OPTIONS"]:
        if num_of_credits == option.credits:
            price = option.price
            break

    if price is None:
        return redirect('bp_main.pricing')

    return render_page('user/checkout.html', price=price, num_of_credits=int(num_of_credits), title='Checkout')
Exemplo n.º 9
0
def redeem():
    """
        Form to give creits to a user.
    """

    form = RedeemForm()

    if form.validate_on_submit():
        code_obj = FreeCreditCode.query.filter_by(code=form.code.data).first()
        current_user.credits += code_obj.credits
        db.session.commit()
        db.session.delete(code_obj)
        db.session.commit()

        return redirect(url_for('bp_users.profile'))

    return render_page('user/redeem.html', title='Redeem Code', form=form)
Exemplo n.º 10
0
def reset_request():
    """
        Sends an email to user allowing them to reset their password.
    """
    # if user is already logged in redirect them home
    if current_user.is_authenticated:
        return redirect(url_for('bp_main.home'))

    form = RequestResetForm()
    if form.validate_on_submit():
        # get user by email
        user = User.query.filter_by(email=form.email.data.lower()).first()

        # send user an email with reset token
        send_reset_email(user)

        flash('An email has been sent with instructions to reset your password.', 'info')
        return redirect(url_for('bp_users.login'))

    return render_page('public/reset_request.html', title='Reset PW', form=form)
Exemplo n.º 11
0
def home():
    """
        The home page of TapeFlip.app
    """
    demos = [{
        'type': 'Original Recording',
        'color': '3f5dca',
        'id': '874891348'
    }, {
        'type': 'Tape Recording',
        'color': '9e2b25',
        'id': '874891534'
    }, {
        'type': 'Original Recording',
        'color': '3f5dca',
        'id': '875472067'
    }, {
        'type': 'Tape Recording',
        'color': '9e2b25',
        'id': '875472226'
    }]
    return render_page("public/landing_page.html", demos=demos)
Exemplo n.º 12
0
def login():
    """
        Logs user in.
    """
    # if user is already logged in redirect them home
    if current_user.is_authenticated:
        return redirect(url_for('bp_main.home'))

    form = LoginForm()
    if form.validate_on_submit():
        # get user by email
        user = User.query.filter_by(email=form.email.data.lower()).first()

        # compare given password hash to stored password hash
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=True)
            if user.role == "user":
                return redirect(url_for('bp_main.home'))
            elif user.role == "admin":
                return redirect(url_for('bp_admin.dashboard'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')

    return render_page('public/login.html', title='Login', form=form)
Exemplo n.º 13
0
def roster():
    """
        This page shows all the available tape machines.
    """
    return render_page("public/roster.html", title='Roster')
Exemplo n.º 14
0
def privacy():
    """
        The privacy policy page.
    """
    return render_page("public/privacy.html", title='Privacy')
Exemplo n.º 15
0
def tos():
    """
        The TOS page.
    """
    return render_page("public/tos.html", title='Terms')
Exemplo n.º 16
0
def faq():
    """
        The FAQ page.
    """
    return render_page("public/faq.html", title='FAQ')