Esempio n. 1
0
File: main.py Progetto: zoyoe/ectool
def register(request):
  if (request.method == "POST"):
    if('email' in request.POST and 'password' in request.POST):
      email = request.POST['email']
      password = request.POST['password']
      user = zuser.registerUser(request,email,password)
      if user:
        if ('requesturl' in request.GET):
          requesturl = request.GET['requesturl']
          return HttpResponseRedirect(zuser.decrypt('url',requesturl));
        else:
          return HttpResponseRedirect("/");
## Need to provide more information of register 
#        return error.ZoyoeSuccess("Success")
######
      else:
        return error.ZoyoeError("User already exist.")
    return error.ZoyoeError("email or password not provided")
  else:
    user = zuser.getCurrentUser(request)
    if not user:
      if ('requesturl' in request.GET):
        context = {}
        context['requesturl'] = request.GET['requesturl']
      return (render_to_response("zoyoe/register.html",context,context_instance=RequestContext(request)))
    else:
      if ('requesturl' in request.GET):
        requesturl = request.GET['requesturl']
        return HttpResponseRedirect(zuser.decrypt('url',requesturl));
      else:
        return HttpResponseRedirect("/");
Esempio n. 2
0
def getItemHistory(request):
    user = zuser.getCurrentUser(request)
    rslt = []
    if user:
        history = user.history
        if not history:
            history = "{}"
        history = json.loads(history)
        if 'items' in history:
            items = history['items']
        else:
            items = []
        for rid in items:
            item = getItem(rid)
            if item:
                rslt.append(item)
    return rslt
Esempio n. 3
0
def getItemHistory(request):
  user = zuser.getCurrentUser(request)
  rslt = []
  if user:
    history = user.history
    if not history:
      history = "{}"
    history = json.loads(history)
    if 'items' in history:
      items = history['items']
    else:
      items = []
    for rid in items:
      item = getItem(rid)
      if item:
        rslt.append(item)
  return rslt
Esempio n. 4
0
def recordItemHistory(request, item):
    user = zuser.getCurrentUser(request)
    if user:
        history = user.history
        if not history:
            history = "{}"
        history = json.loads(history)
        if 'items' in history:
            items = history['items']
        else:
            items = []
        if item.refid in items:
            items.remove(item.refid)
        items = [item.refid] + items
        if (len(items) > 10):
            items.pop()
        history['items'] = items
        user.history = json.dumps(history)
        user.put()
Esempio n. 5
0
def recordItemHistory(request,item):
  user = zuser.getCurrentUser(request)
  if user:
    history = user.history
    if not history:
      history = "{}"
    history = json.loads(history)
    if 'items' in history:
      items = history['items']
    else:
      items = []
    if item.refid in items:
      items.remove(item.refid)
    items = [item.refid] + items
    if (len(items) > 10):
      items.pop()
    history['items'] = items
    user.history = json.dumps(history)
    user.put()
Esempio n. 6
0
def register(request):
    if (request.method == "POST"):
        if ('email' in request.POST and 'password' in request.POST):
            email = request.POST['email']
            password = request.POST['password']
            user = zuser.registerUser(request, email, password)
            if user:
                if ('requesturl' in request.GET):
                    requesturl = request.GET['requesturl']
                    return HttpResponseRedirect(
                        zuser.decrypt('url', requesturl))
                else:
                    return HttpResponseRedirect("/")


## Need to provide more information of register
#        return error.ZoyoeSuccess("Success")
######
            else:
                return error.ZoyoeError("User already exist.")
        return error.ZoyoeError("email or password not provided")
    else:
        user = zuser.getCurrentUser(request)
        if not user:
            if ('requesturl' in request.GET):
                context = {}
                context['requesturl'] = request.GET['requesturl']
            return (render_to_response(
                "zoyoe/register.html",
                context,
                context_instance=RequestContext(request)))
        else:
            if ('requesturl' in request.GET):
                requesturl = request.GET['requesturl']
                return HttpResponseRedirect(zuser.decrypt('url', requesturl))
            else:
                return HttpResponseRedirect("/")
Esempio n. 7
0
File: ebay.py Progetto: zoyoe/ectool
def getToken(request):
  if (not 'ebayinfo' in request.session) or (not request.session['ebayinfo']):
    request.session['ebayinfo'] =  {}
  ebayinfo = request.session.get('ebayinfo',{})
  user = zuser.getCurrentUser(request)

# we are going to fetch the token if it does not exist yet
  token = ""
  if (('token' in ebayinfo) and (ebayinfo['token'])):
    token = ebayinfo['token']
  else:
    if ('session' in ebayinfo): 
      token = FetchToken(request,ebayinfo['session'])
      xml_doc = etree.parse(StringIO(token))
      ack = xml_doc.xpath("//xs:Ack",
        namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
      if('Success' in ack.text):
        token = xml_doc.xpath("//xs:eBayAuthToken",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
        token = token.text
      else:
        msg = xml_doc.xpath("//xs:LongMessage",
        namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
        ebayerror = msg.text
        ebayinfo['error'] = ebayerror
        # should not update ebayinfo in request.session
        # request.session['ebayinfo'] = ebayinfo
        logging.info("Can not get token from ebay id:" + token)
    if (not token): # can not get token from session
      if user:
        usr = user
        if (usr and usr.ebaytoken):
          token = usr.ebaytoken
  # By the above computation we have tried to get the token
  if (token):
    ebayinfo['token'] = token
  else:
    logging.info("Can not get session for ebay auth")
    return None

  # so far we might need to update the token of the current user 
  if user:
    usr = user
    if (usr):
      usr.ebaytoken = token
      usr.put()

  logging.info("ebayinfo:" + json.dumps(ebayinfo))
  if ('token' in ebayinfo) and ebayinfo['token']: 
    request.session['ebayinfo'] = ebayinfo

# here we try to get as much info as possible from a ebay token
    if((not 'id' in ebayinfo) or (not 'email' in ebayinfo)):
      user = GetUserInfo(token)
      user_doc = etree.parse(StringIO(user))
      ack = user_doc.xpath("//xs:Ack",
        namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
      if ('Success' in ack.text):
        email = user_doc.xpath("//xs:Email",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
        ebayinfo['email'] = email.text
        uid = user_doc.xpath("//xs:UserID",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
        ebayinfo['id'] = uid.text
      else:
        request.session['ebayinfo'] = {}
        logging.info("Can not find email address in ebayinfo")
        return None
    if((not 'store' in ebayinfo) or (not 'logo' in ebayinfo) or (not 'category' in ebayinfo)):
      store = GetStore(token)
      store_doc = etree.parse(StringIO(store))
      ack = store_doc.xpath("//xs:Ack",
        namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
      if ('Success' in ack.text):
        name = store_doc.xpath("//xs:Store/xs:Name",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
        ebayinfo['store'] = name.text
        logo = store_doc.xpath("//xs:Store/xs:Logo/xs:URL",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})
        if logo:
          ebayinfo['logo'] = logo[0].text
        else:
          ebayinfo['logo'] = None
        cgs = {}
        categories = store_doc.xpath("//xs:Store/xs:CustomCategories/xs:CustomCategory",
          namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})
        a = etree.tostring(categories[0])
        for category in categories:
          name = category.xpath("./xs:Name",
            namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0].text
          id = category.xpath("./xs:CategoryID",
            namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0].text
          cgs[id] = {'name':name,'children':{}}
          childcategories = category.xpath("./xs:ChildCategory",
            namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})
          for child in childcategories:
            name = child.xpath("./xs:Name",
              namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0].text
            cid = child.xpath("./xs:CategoryID",
              namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0].text
            cgs[id]['children'][cid] = {'name':name}
        ebayinfo['categories'] = cgs
      else:
        request.session['ebayinfo'] = {}
        logging.info("Can not find shopinfo in ebayinfo:" + store)
        return None
    request.session['ebayinfo'] = ebayinfo
    currentSite().setebayinfo(json.dumps(ebayinfo))
    return ebayinfo['token']
  else:
    return None  
Esempio n. 8
0
def registerAdminAction(request, action, target):
    user = zuser.getCurrentUser(request)
    action = AdminAction(action=action, target=target, parent=user)
    action.put()
Esempio n. 9
0
File: user.py Progetto: zoyoe/ectool
def user(request):
  user = zuser.getCurrentUser(request)
  return {'user':user}
Esempio n. 10
0
def registerAdminAction(request,action,target):
  user = zuser.getCurrentUser(request)
  action = AdminAction(action = action,target=target,parent=user)
  action.put()
Esempio n. 11
0
def user(request):
    user = zuser.getCurrentUser(request)
    return {'user': user}
Esempio n. 12
0
def getToken(request):
    if (not 'ebayinfo'
            in request.session) or (not request.session['ebayinfo']):
        request.session['ebayinfo'] = {}
    ebayinfo = request.session.get('ebayinfo', {})
    user = zuser.getCurrentUser(request)

    # we are going to fetch the token if it does not exist yet
    token = ""
    if (('token' in ebayinfo) and (ebayinfo['token'])):
        token = ebayinfo['token']
    else:
        if ('session' in ebayinfo):
            token = FetchToken(request, ebayinfo['session'])
            xml_doc = etree.parse(StringIO(token))
            ack = xml_doc.xpath(
                "//xs:Ack",
                namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
            if ('Success' in ack.text):
                token = xml_doc.xpath(
                    "//xs:eBayAuthToken",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
                token = token.text
            else:
                msg = xml_doc.xpath(
                    "//xs:LongMessage",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
                ebayerror = msg.text
                ebayinfo['error'] = ebayerror
                # should not update ebayinfo in request.session
                # request.session['ebayinfo'] = ebayinfo
                logging.info("Can not get token from ebay id:" + token)
        if (not token):  # can not get token from session
            if user:
                usr = user
                if (usr and usr.ebaytoken):
                    token = usr.ebaytoken
    # By the above computation we have tried to get the token
    if (token):
        ebayinfo['token'] = token
    else:
        logging.info("Can not get session for ebay auth")
        return None

    # so far we might need to update the token of the current user
    if user:
        usr = user
        if (usr):
            usr.ebaytoken = token
            usr.put()

    logging.info("ebayinfo:" + json.dumps(ebayinfo))
    if ('token' in ebayinfo) and ebayinfo['token']:
        request.session['ebayinfo'] = ebayinfo

        # here we try to get as much info as possible from a ebay token
        if ((not 'id' in ebayinfo) or (not 'email' in ebayinfo)):
            user = GetUserInfo(token)
            user_doc = etree.parse(StringIO(user))
            ack = user_doc.xpath(
                "//xs:Ack",
                namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
            if ('Success' in ack.text):
                email = user_doc.xpath(
                    "//xs:Email",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
                ebayinfo['email'] = email.text
                uid = user_doc.xpath(
                    "//xs:UserID",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
                ebayinfo['id'] = uid.text
            else:
                request.session['ebayinfo'] = {}
                logging.info("Can not find email address in ebayinfo")
                return None
        if ((not 'store' in ebayinfo) or (not 'logo' in ebayinfo)
                or (not 'category' in ebayinfo)):
            store = GetStore(token)
            store_doc = etree.parse(StringIO(store))
            ack = store_doc.xpath(
                "//xs:Ack",
                namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
            if ('Success' in ack.text):
                name = store_doc.xpath(
                    "//xs:Store/xs:Name",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0]
                ebayinfo['store'] = name.text
                logo = store_doc.xpath(
                    "//xs:Store/xs:Logo/xs:URL",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})
                if logo:
                    ebayinfo['logo'] = logo[0].text
                else:
                    ebayinfo['logo'] = None
                cgs = {}
                categories = store_doc.xpath(
                    "//xs:Store/xs:CustomCategories/xs:CustomCategory",
                    namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})
                a = etree.tostring(categories[0])
                for category in categories:
                    name = category.xpath(
                        "./xs:Name",
                        namespaces={'xs':
                                    "urn:ebay:apis:eBLBaseComponents"})[0].text
                    id = category.xpath(
                        "./xs:CategoryID",
                        namespaces={'xs':
                                    "urn:ebay:apis:eBLBaseComponents"})[0].text
                    cgs[id] = {'name': name, 'children': {}}
                    childcategories = category.xpath(
                        "./xs:ChildCategory",
                        namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})
                    for child in childcategories:
                        name = child.xpath(
                            "./xs:Name",
                            namespaces={
                                'xs': "urn:ebay:apis:eBLBaseComponents"
                            })[0].text
                        cid = child.xpath("./xs:CategoryID",
                                          namespaces={
                                              'xs':
                                              "urn:ebay:apis:eBLBaseComponents"
                                          })[0].text
                        cgs[id]['children'][cid] = {'name': name}
                ebayinfo['categories'] = cgs
            else:
                request.session['ebayinfo'] = {}
                logging.info("Can not find shopinfo in ebayinfo:" + store)
                return None
        request.session['ebayinfo'] = ebayinfo
        currentSite().setebayinfo(json.dumps(ebayinfo))
        return ebayinfo['token']
    else:
        return None