Ejemplo n.º 1
0
def usertour(resp, usrid, pathinfo):
    if os.environ["REQUEST_METHOD"] != "GET":
        resp.message = "Method not supported."
    elif len(pathinfo) == 0:
        resp.message = "Not enough path to go on."
    else:
        op = pathinfo.pop()
        if op == "name":
            if len(pathinfo) > 0:
                name = pathinfo.pop()

                theUser = dao.getuser(usrid, util.authsecret())
                if theUser != None:
                    theTour = dataobjects.Tour(name)
                    theTour.user = theUser.ident

                    item = dao.gettourbyname(theTour)

                    resp.message = "ok"
                    resp.item = item
                    resp.link = util.autolink() + "/%d" % theTour.ident
                else:
                    resp.message = "%s is not a valid user, or authorization is incorrect." % usrid
            else:
                resp.message = "To get a tour by name, please supply the name."
        elif op == "all":
            theUser = dao.getuser(usrid, util.authsecret())
            if theUser != None:
                theTours = dao.gettoursbyuser(usrid)

                resp.message = "ok"
                resp.listkey = "tours"
                resp.item = theTours
            else:
                resp.message = "%d is not a valid user, or the authorization is incorrect." % usrid
        else:
            tourid = 0
            try:
                tourid = int(op)
            except ValueError:
                pass

            if tourid != 0:
                if len(pathinfo) > 0:  # op on the tour's items
                    usertoursearch(resp, usrid, tourid, pathinfo)
                else:
                    # op on the tour itself
                    theUser = dao.getuser(usrid, util.authsecret())
                    if theUser != None:
                        theTour = dao.gettourbyid(usrid, tourid)

                        resp.item = theTour
                        resp.message = "ok"
                    else:
                        resp.message = "%d is not a valid user, or the authorization is incorrect." % usrid
            else:
                resp.message = "'%s' is not a supported operation." % op
Ejemplo n.º 2
0
    pathinfo = os.environ["PATH_INFO"].split("/")
    pathinfo.reverse()
    pathinfo.pop()  # ''

    op = pathinfo.pop()
    if op == "login":
        if form.has_key("user") and form.has_key("password"):
            theUser = dataobjects.User(form["user"].value, util.encrypt(form["password"].value))

            num = dao.loginuser(theUser)

            if num != None:
                theUser.ident = num[0]
                resp.message = "ok"
                resp.item = theUser
                resp.item.uri = util.autolink() + "/%d" % theUser.ident
            else:
                resp.message = "Invalid login"
        else:
            resp.message = "No user or password specified."
    elif op == "register":
        if method == "POST":
            try:
                if form.has_key("user") and form.has_key("password") and form.has_key("email"):
                    theUser = dataobjects.User(form["user"].value, util.encrypt(form["password"].value))
                    theUser.email = form["email"].value

                    # todo: validate input of input strings

                    num = dao.loginuser(theUser)