Ejemplo n.º 1
0
def fb_login():
    if request.method != "POST":
        return "Error", 404
    user = User.get_by_id(request.form["userID"])
    response = {}

    response["status"] = "existing"
    if not user:
        user = User(id=request.form["userID"],
                    userID=request.form["userID"],
                    name=request.form["first_name"] + " " +
                    request.form["last_name"],
                    email=request.form["email"],
                    rating=2.5,
                    number_ratings=1)
        user.put()

        response["status"] = "new"

    if Admin.get_by_id(user.key.id()):
        session["admin"] = True
    else:
        session["admin"] = False
    session['first_name'] = request.form["first_name"]
    session['last_name'] = request.form["last_name"]
    session['email'] = request.form["email"]
    logged_in(user)
    return json.dumps(response)
Ejemplo n.º 2
0
def view_me():

    user = User.get_by_id(session["user_id"])

    if request.method == "POST":
        return render_template("tsktsk.html")
        review = Review(rating=int(request.form["rating"]),
                        reason=request.form["reason"],
                        user=user_id,
                        reviewer=session["user_id"],
                        flagged=False)
        review.put()

        update_user_rating(user_id, int(request.form["rating"]))

    sold_offers = []
    sold_items = Item.query(Item.seller_id == session["user_id"],
                            Item.sold == True)
    for item in sold_items:
        temp_offer = Offer.query(Offer.item == item.key.id()).get()
        sold_offers.append(temp_offer)

    purchased_offers = Offer.query(Offer.confirmed == True,
                                   Offer.bidder == session["user_id"])
    notifications = Notification.query(
        Notification.user == session["user_id"]).order(-Notification.time)
    return render_template("me.html",
                           user=user,
                           sold_offers=sold_offers,
                           purchased_offers=purchased_offers,
                           notifications=notifications)
Ejemplo n.º 3
0
def update_user_rating(user_id, rating):
    user = User.get_by_id(user_id)
    user.number_ratings += 1.0
    user.rating = user.rating / (
        (user.number_ratings - 1.0) /
        user.number_ratings) + rating / (user.number_ratings)
    user.put()
Ejemplo n.º 4
0
def login():
    fields = []
    fields.append(
        Field(name="email",
              title="Email",
              the_type='email',
              identifier='email',
              placeholder="Email"))
    fields.append(
        Field(name='password',
              title="Password",
              the_type="password",
              identifier='password',
              placeholder='Password'))
    title = "Login "
    form = Form(fields=fields, title=title)
    if request.method == 'GET':
        return render_template('login.html', login_form=form)
    try:
        user = User.get_by_id(request.form['email'])
        if user:
            if user.password == request.form['password']:
                print "pop"

                return logged_in(user)
            else:
                form.error = "User or Password was Incorrect"
                return render_template('login.html', login_form=form)
        else:
            form.error = "User or Password was Incorrect"
            return render_template('login.html', login_form=form)
    except KeyError as err:
        form.error = "Email or Password Was Not Filled Out Correctly"
        return render_template('login.html', login_form=form)
Ejemplo n.º 5
0
 def check_login_status(self):
     cookie = self.get_cookie('user_id')
     if cookie and verify_cookie(cookie):
         user_id = int(cookie.split('|')[0])
         user = User.get_by_id(user_id)
     else:
         user = None
     return user
Ejemplo n.º 6
0
 def get(self):
     userid_cookie = self.request.cookies.get('userid')
     if not userid_cookie:
         self.response.write("Welcome Stranger!")
     else:
         userid = int(userid_cookie.split("|")[0])  
         user = User.get_by_id(userid)
         if self.hasher.check_secure_val(userid_cookie):
             self.response.write("Welcome "+user.username+" !")
Ejemplo n.º 7
0
 def get(self):
     userid_cookie = self.request.cookies.get('userid')
     if userid_cookie and len(userid_cookie) > 0:
         userid = int(userid_cookie.split("|")[0])  
         user = User.get_by_id(userid)
         if not user:
             self.response.headers.add_header('Set-Cookie','userid=;Path=/')
             self.response.write("Welcome!")        
         else:
             if self.hasher.check_secure_val(userid_cookie):
                 self.response.write("Welcome "+user.username+" !")
     else:
         self.response.write("Welcome Cookie-less Stranger!")
Ejemplo n.º 8
0
def view_user(user_id):

    user = User.get_by_id(user_id)

    if request.method == "POST":
        if user_id == session["user_id"]:
            return render_template("tsktsk.html")
        review = Review(rating=int(request.form["rating"]),
                        reason=request.form["reason"],
                        user=user_id,
                        reviewer=session["user_id"],
                        flagged=False)
        review.put()

        update_user_rating(user_id, int(request.form["rating"]))

    return render_template("view_user.html", user=user)
Ejemplo n.º 9
0
def signup():
    return login()
    fields = []
    fields.append(
        Field(name="email",
              title="Email",
              the_type='email',
              identifier='email',
              placeholder="Email"))
    fields.append(
        Field(name="name",
              title="Name",
              the_type='name',
              identifier='name',
              placeholder="Name"))
    fields.append(
        Field(name='password',
              title="Password",
              the_type='password',
              identifier='password',
              placeholder='Password'))
    title = "Signup"

    form = Form(fields=fields, title=title)

    if request.method == 'GET':
        return render_template('signup.html', signup_form=form)

    try:
        exists = User.get_by_id(request.form['email'])
        if exists:
            form.error = "Email Taken"
            return render_template('signup.html', signup_form=form)
        else:
            user = User(email=request.form['email'],
                        id=request.form['email'],
                        password=request.form['password'],
                        name=request.form['name'])
            user.put()
            return signed_up(user)
    except KeyError as err:
        form.error = "Email or Password Was Not Filled Out Correctly"
        return render_template('signup.html', signup_form=form)
Ejemplo n.º 10
0
def browse_item(item_id):
    item_id = int(item_id)
    if not session.get("logged_in"):
        return login()

    if request.method == "GET":
        item = Item.get_by_id(item_id)
        category_id = item.category
        print item.name
        seller = User.get_by_id(item.seller_id)

        previous_offer = Offer.query(Offer.bidder == session["user_id"],
                                     Offer.item == item_id).get()

        was_previous_offer = False
        if previous_offer:
            was_previous_offer = True

        fields = []
        fields.append(
            Field(
                name="message",
                title="Message For Seller",
                the_type='text',
                identifier='message',
                placeholder=
                "A short message for the seller. Perhaps, where you can meet or payment options.",
                tag="textarea"))
        if item.biddable:

            fields.append(
                Field(name='amount',
                      title="Offer Amount",
                      the_type="number",
                      identifier="amount",
                      placeholder="10.95",
                      step=True))

        title = "Make Offer"
        form = Form(fields=fields, title=title)

        tags = Item_Tag.query(Item_Tag.item == item_id)
        notifications = Notification.query(
            Notification.user == session["user_id"]).order(-Notification.time)
        return render_template("browse_item.html",
                               item=item,
                               category_id=category_id,
                               bid_form=form,
                               previous_offer=previous_offer,
                               was_previous_offer=was_previous_offer,
                               offer=previous_offer,
                               notifications=notifications,
                               tags=tags)

    if request.method == "POST":

        item = Item.get_by_id(item_id)

        if not item or item.sold:
            return page_was_not_found(
                "Sorry but the item you tried to bid on has been removed by the seller"
            )

        category_id = item.category
        seller = User.get_by_id(item.seller_id)

        previous_offer = Offer.query(Offer.bidder == session["user_id"],
                                     Offer.item == item_id).get()

        if previous_offer:
            previous_offer.key.delete()

        amount = item.price
        if item.biddable:
            amount = float(request.form["amount"])

        offer = Offer(bidder=session["user_id"],
                      item=item_id,
                      message=request.form["message"],
                      amount=amount,
                      bidder_name=session["first_name"] + " " +
                      session["last_name"],
                      accepted=False,
                      confirmed=False,
                      item_name=item.name)
        offer.put()

        if item.biddable:
            item.update_best_offer(amount)

        notification_body = "Offer made on " + item.name + "for $" + str(
            offer.amount)
        notification = Notification(user=item.seller_id,
                                    body=notification_body,
                                    ntype="item-offer",
                                    item=item.key.id(),
                                    item_category=item.category,
                                    noticed=False,
                                    link="/my_items/" + str(item.key.id()))
        notification.put()

        fields = []
        fields.append(
            Field(
                name="message",
                title="Message For Seller",
                the_type='text',
                identifier='message',
                placeholder=
                "A short message for the seller. Perhaps, where you can meet or payment options.",
                tag="textarea"))
        if item.biddable:

            fields.append(
                Field(name='amount',
                      title="Offer Amount",
                      the_type="number",
                      identifier="amount",
                      placeholder="10.95",
                      step=True))

        title = "Make Offer"
        form = Form(fields=fields, title=title, submit="Make Offer")

        tags = Item_Tag.query(Item_Tag.item == item_id)
        notifications = Notification.query(
            Notification.user == session["user_id"]).order(-Notification.time)
        return render_template("browse_item.html",
                               item=item,
                               category_id=category_id,
                               bid_form=form,
                               offer=offer,
                               was_previous_offer=True,
                               notifications=notifications,
                               tags=tags)