Ejemplo n.º 1
0
def ajax_keystore(request,path): # TODO SUPPORT JSON WILL TAKJE CARE BY POST>?>>>>
    if not KEYSTORE: return CustomHttpResponse(BuildError('KEYSTORE object canot be null',help="Did you start mongodb server ?")); # Please remve this chek in prod
    res= {}
    path = processPath(path)
    try:
        if  True: #request.is_ajax():
           data ={}
           #pdb.set_trace()
           if 'application/json' in request.META.get('CONTENT_TYPE'):
              data = json.loads(request.body)
           else:
              if request.method == 'GET':
                data = dict([ (k,v[0])for k,v in dict(request.GET).items()])
              if request.method == 'POST':
                data = dict([ (k,v[0])for k,v in dict(request.POST).items()])
              
           if request.method == 'GET': # get
              res = KEYSTORE.getOrSearch(path,data)
           if request.method == 'POST': # Create
              res = KEYSTORE.creteOrUpdate(path,data)
           if request.method == 'DELETE': # Create
              res = KEYSTORE.deleteEntryOrTable(path,data)
        else:
           return utils.CustomHttpResponse(utils.BuildError('This request must send by ajax',help="write a ajax call from JavaScript"));   
    except Exception,e:
        d = Log(e)
        res ={'status':'error','fname':str(e),'stack':d};          
Ejemplo n.º 2
0
def ajax_auth(request,path): # TODO SUPPORT JSON WILL TAKJE CARE BY POST>?>>>>
    if not KEYSTORE: return CustomHttpResponse(BuildError('KEYSTORE object canot be null',help="Did you start mongodb server ?")); # Please remve this chek in prod      
    res= {}
    try:
        if request.method == 'POST': # We alows have a post method for this.
            if 'application/json' in request.META.get('CONTENT_TYPE'):
                data = json.loads(request.body)
            else:
                data = dict([ (k,v[0])for k,v in dict(request.POST).items()])
            #pdb.set_trace()
            if not data.get('email'): 
               return CustomHttpResponse(BuildError('Request must contian email',help="use {'email':'something'}"));
               
            if path == 'auths':
              res = SocialAuth.createOrAuthUserBySocial(data,request)
            elif path == 'authp':
              pass
            elif path == 'send_activate':
              res = SocialAuth.sendMailToActivateUser(data,request)
            elif path == 'activate':
                res = SocialAuth.activateUser(data,request)
              
            elif path == 'authp':
              pass
            else:
              return CustomHttpResponse(BuildError('Unknown path. see the code. ',help="use /auths or /authp ?")); 
        else:
           return utils.CustomHttpResponse(utils.BuildError('Auth only Accept POST',help="Use POST METHOD"));   
    except Exception,e:
        d = Log(e)
        res ={'status':'error','fname':str(e),'stack':d};          
Ejemplo n.º 3
0
def processPath(path):
   res={}
   res['table'] =None;res['id']=None; res['attr']=None
   path = path.split('/')
   path = [ p for p in path if len(p) > 0 ]
   if len(path) == 0:
      return utils.BuildError('table_name should not be empty',None,'The request should be look like /api/ks/<table_name>/<id>/<attr>')
   res['table'] = path[0]
   if(len(path ) >1): res['id']= path[1]
   if(len(path ) >2): res['attr']= '/'.join(path[2:])
   #if res['id'] and not res['id'].isdigit():  return utils.BuildError('Id must be integer',None,'The request should be look like /api/ks/<table_name>/<id(Some number)>/<attr>') << Mongo id contains char
   return res
Ejemplo n.º 4
0
def ajax_github(request):     
    res= {}
    try:
        if request.method == 'POST': # We alows have a post method for this.
            if 'application/json' in request.META.get('CONTENT_TYPE'):
                data = json.loads(request.body)
            else:
                data = dict([ (k,v[0])for k,v in dict(request.POST).items()])
                
            if data.get('action') == 'pull':
                g = GitHub(repo=data.get('repo'),uname=data.get('uname'),passwd=data.get('passwd'))
                res = g.getFile(path=data.get('path'))
            elif data.get('action')== 'push':
                g = GitHub(repo=data.get('repo'),uname=data.get('uname'),passwd=data.get('passwd'))
                res = g.saveFile(path=data.get('path'),data=data.get('data'),cname=data.get('cname'),cemail=data.get('cemail'),cmsg=data.get('cmsg'));
            else:
                return CustomHttpResponse(BuildError('You must have [action=pull | push ]',help="use {'action':'pull|push'}")); 
        else:
           return utils.CustomHttpResponse(utils.BuildError('gitHub only Accept POST',help="Use POST METHOD"));   
    except Exception,e:
        d = Log(e)
        res ={'status':'error','fname':str(e),'stack':d};