Ejemplo n.º 1
0
def add_funds():
    """
    Allows the user to add funds to their account.
    """
    if 'username' not in session:
        return redirect(url_for('login'))
    else:
        if session['type_of_user'] == "user":
            cc = str(User.get_user_info(session['username'])["credit_card"])
            cc = "******" + cc[-4:]

            balance = 0
            if session['type_of_user'] == "developer":
                balance = Developer.get_info(session['username'])["balance"]
            else:
                balance = Client.get_info(session['username'])["balance"]

            form = AddFundsForm()

            if request.method == "GET":
                return render_template("addFunds.html",
                                       cc=cc,
                                       form=form,
                                       balance=balance,
                                       added=False)
            elif request.method == "POST":
                if form.amount.validate(form):
                    if session['type_of_user'] == "developer":
                        Developer.add_earnings(session['username'],
                                               form.amount.data)
                        balance = Developer.get_info(
                            session['username'])["balance"]
                    else:
                        Client.add_to_balance(session['username'],
                                              form.amount.data)
                        balance = Client.get_info(
                            session['username'])["balance"]
                    return render_template("addFunds.html",
                                           cc=cc,
                                           form=form,
                                           balance=balance,
                                           added=True)
                else:
                    return render_template("addFunds.html",
                                           cc=cc,
                                           form=form,
                                           balance=balance,
                                           added=False)
        else:
            return render_template("access_denied.html")
Ejemplo n.º 2
0
def rating(demand_id, recipient):
    """
    The '/bid/<demand_id>/rating/<recipient>' route is where the user can rate another user 
    for a demand they were involved in.
    """
    if 'username' not in session:
        return redirect(url_for('login'))

    demand_info = Demand.get_info(demand_id)

    # make sure the user is authorized to rate the recipient
    if session['role'] == 'developer':
        # developer rates the client, so client is recipient
        if session['username'] != demand_info['chosen_developer_username']:
            return render_template('access_denied.html')
    elif session['role'] == 'client':
        # client rates the developer, so developer is recipient
        if session['username'] != demand_info['client_username']:
            return render_template('access_denied.html')

    if Rating.check_if_valid_rating_form(int(demand_id), recipient,
                                         session['username']):
        form = RatingForm()

        if request.method == "GET":
            return render_template("rating.html",
                                   form=form,
                                   recipient=recipient,
                                   demand_id=demand_id)
        elif request.method == "POST":
            # low rating
            if form.rating.data <= 2:
                session['rating' + demand_id] = form.rating.data
                return redirect(
                    url_for('ratingMessage',
                            demand_id=demand_id,
                            recipient=recipient))
            elif form.rating.data == None:
                return render_template('rating.html',
                                       form=form,
                                       recipient=recipient,
                                       demand_id=demand_id)
            else:
                # add to form data
                Rating(demand_id, recipient, session['username'],
                       form.rating.data)

                # if the client gave a good rating to a developer (<= 3)
                # the remaining half of the bid amount gets transferred over to the developer
                if session['role'] == 'client':
                    bid_amount = Demand.get_info(
                        demand_id)['chosen_bid_amount']
                    Transaction(recipient, session['username'],
                                round(bid_amount / 2, 2))

                    # update developer's earnings
                    Developer.add_earnings(recipient, bid_amount)

                return render_template('ratingFinished.html',
                                       recipient=recipient)
    return render_template('access_denied.html')