Beispiel #1
0
def email(request):
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    return authenticator.response({"email":authenticator.user.email})    
Beispiel #2
0
def email(request):
    authenticator = JSONAuthenticator()
    print 'json auth'
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    return authenticator.response({"email":authenticator.user.email,'id':authenticator.user.id})    
def data(request):
    '''decrypt funf database files, and upload them to your PDS'''
    result = {}
    connection = None
    token = request.GET['bearer_token']

    if request.method == 'GET':
        template = {'token': token}
        return render_to_response('upload.html', template, RequestContext(request))
    pds = None
    scope = AccessRange.objects.get(key="funf_write")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        # Validate the request.
        authenticator.validate(request)
    except AuthenticationException as e:
        # Return an error response.
        print e
        return authenticator.error_response(content="You didn't authenticate.")
    profile = authenticator.user.get_profile()
    funf_password = profile.funf_password
    print "Registry set_funf_data for uuid: %s" % profile.uuid

    for filename, file in request.FILES.items():
        try:
            file_path = upload_dir + file.name
            try:
                key = decrypt.key_from_password(str(funf_password))
                write_file(str(file_path), file)
            except Exception as ex:
                print "failed to write file to "+file_path+".  Please make sure you have write permission to the directory set in settings.SERVER_UPLOAD_DIR"
            dbdecrypt.decrypt_if_not_db_file(file_path, key)
            con = sqlite3.connect(file_path)
            cur = con.cursor()
            cur.execute("select name, value from data")
            inserted = []
            for row in cur:
                name = convert_string(row[0])
                json_insert = clean_keys(json.JSONDecoder().decode(convert_string(row[1])))
                #print json_insert
                # Insert into PDS
                pds_data= {}
                pds_data['time']=json_insert.get('timestamp')
                pds_data['value']=json_insert
                pds_data['key']=name
                insert_pds(profile, token, pds_data)
                #print "inserting row..."
                #print pds_data
                inserted.append(convert_string(json_insert)+'\n')
            result = {'success': True, 'message':''.join(inserted)} 
            #remove_file(file_path)
        except Exception as e:
            print e.message
            print traceback.format_exc()
            result = {'success':False, 'error_message':e.message}
    # It doesn't matter what we return at this point - the phones are just checking the response status
    response_dict = {"status":"success"}
    return HttpResponse(json.dumps(response_dict), content_type='application/json')
Beispiel #4
0
 def wrapped_view(*args, **kwargs):
     request = args[0]
     authenticator = JSONAuthenticator(scope=self.scopes)
     try:
         authenticator.validate(request)
         request.user = authenticator.user
     except AuthenticationException:
         return authenticator.error_response()
     return view_func(*args, **kwargs)
Beispiel #5
0
 def wrapped_view(*args, **kwargs):
     request = args[0]
     authenticator = JSONAuthenticator(scope=self.scopes)
     try:
         authenticator.validate(request)
         request.user = authenticator.user
     except AuthenticationException:
         return authenticator.error_response()
     return view_func(*args, **kwargs)
Beispiel #6
0
def date_joined(request):
    scope = AccessRange.objects.get(key="date_joined")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    return authenticator.response({
        "date_joined":str(authenticator.user.date_joined)})
def email(request):
    print "in email"
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    response = authenticator.response({"email": authenticator.user.email})
    print "returning ", response
    return response
Beispiel #8
0
def last_login(request):
    scope = AccessRange.objects.get(key="last_login")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    data = {"date_joined":str(request.user.date_joined)}
    return authenticator.response({
        "last_login":str(authenticator.user.last_login)})
def email(request):
    print "in email" 
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    response = authenticator.response({"email":authenticator.user.email})    
    print "returning ", response 
    return response
Beispiel #10
0
def profile(request):
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    return authenticator.response(
                {"email": authenticator.user.email,
                 "id": authenticator.user.id,
                 "name": authenticator.user.username,
                 "login": authenticator.user.username 
                })
def last_login(request):
    print "in last_login" 
    scope = AccessRange.objects.get(key="last_login")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    response = authenticator.response({
            "last_login":str(authenticator.user.last_login)})
    print "returning ", response
    return response
def last_login(request):
    print "in last_login"
    scope = AccessRange.objects.get(key="last_login")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()
    response = authenticator.response(
        {"last_login": str(authenticator.user.last_login)})
    print "returning ", response
    return response
Beispiel #13
0
def whoami(request):
    """Test authentication"""
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()

    user = authenticator.access_token.user
    return authenticator.response({
        "user": user.username,
        "url": user.get_profile().get_absolute_url(),
        "image_url": user.get_profile().image_or_default()
    })
def userinfo(request):
    scope = AccessRange.objects.get(key="funf_write")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        # Validate the request.
        authenticator.validate(request)
    except AuthenticationException as e:
        # Return an error response.
        print e
        return authenticator.error_response("You didn't authenticate.")
    profile = authenticator.user.get_profile()
    response_dict = {}
    response_dict['id'] = profile.uuid
    response_dict['email'] = profile.user.email
    response_dict['name'] = profile.user.username
    response_dict['pds_location'] = 'http://'+str(profile.pds_location).replace("http://", "")

    return HttpResponse(json.dumps(response_dict), content_type='application/json')
Beispiel #15
0
def userinfo(request):
    scope = AccessRange.objects.get(key="funf_write")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        # Validate the request.
        authenticator.validate(request)
    except AuthenticationException as e:
        # Return an error response.
        print e
        return authenticator.error_response("You didn't authenticate.")
    profile = authenticator.user.get_profile()
    response_dict = {}
    response_dict['id'] = profile.uuid
    response_dict['email'] = profile.user.email
    response_dict['name'] = profile.user.username
    response_dict['pds_location'] = 'http://'+str(profile.pds_location)

    return HttpResponse(json.dumps(response_dict), content_type='application/json')
Beispiel #16
0
def whoami(request):
    """Test authentication"""
    authenticator = JSONAuthenticator()
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()

    user = authenticator.access_token.user
    return authenticator.response({
        "user":
        user.username,
        "url":
        user.get_profile().get_absolute_url(),
        "email":
        user.email,
        "image_url":
        user.get_profile().image_or_default()
    })
Beispiel #17
0
def userinfo(request):
    authenticator = JSONAuthenticator()  # XXX: Scope?
    try:
        authenticator.validate(request)
    except AuthenticationException:
        return authenticator.error_response()

    return authenticator.response({
        "email":
        authenticator.user.email,
        "username":
        authenticator.user.username,
        "first_name":
        authenticator.user.first_name,
        "last_name":
        authenticator.user.last_name,
        "is_staff":
        authenticator.user.is_staff,
        "is_active":
        authenticator.user.is_active,
        "is_superuser":
        authenticator.user.is_superuser
    })
Beispiel #18
0
def data(request):
    '''decrypt funf database files, and upload them to your PDS'''
    result = {}
    connection = None
    token = request.GET['bearer_token']

    if request.method == 'GET':
        template = {'token': token}
        return render_to_response('upload.html', template,
                                  RequestContext(request))
    pds = None
    scope = AccessRange.objects.get(key="funf_write")
    authenticator = JSONAuthenticator(scope=scope)
    try:
        # Validate the request.
        authenticator.validate(request)
    except AuthenticationException as e:
        # Return an error response.
        print e
        return authenticator.error_response(content="You didn't authenticate.")
    profile = authenticator.user.get_profile()
    funf_password = profile.funf_password
    print "Registry set_funf_data for uuid: %s" % profile.uuid

    for filename, file in request.FILES.items():
        try:
            file_path = upload_dir + file.name
            try:
                key = decrypt.key_from_password(str(funf_password))
                write_file(str(file_path), file)
            except Exception as ex:
                print "failed to write file to " + file_path + ".  Please make sure you have write permission to the directory set in settings.SERVER_UPLOAD_DIR"
            dbdecrypt.decrypt_if_not_db_file(file_path, key)
            con = sqlite3.connect(file_path)
            cur = con.cursor()
            cur.execute("select name, value from data")
            inserted = []
            for row in cur:
                name = convert_string(row[0])
                json_insert = clean_keys(json.JSONDecoder().decode(
                    convert_string(row[1])))
                #print json_insert
                # Insert into PDS
                pds_data = {}
                pds_data['time'] = json_insert.get('timestamp')
                pds_data['value'] = json_insert
                pds_data['key'] = name
                insert_pds(profile, token, pds_data)
                #print "inserting row..."
                #print pds_data
                inserted.append(convert_string(json_insert) + '\n')
            result = {'success': True, 'message': ''.join(inserted)}
            #remove_file(file_path)
        except Exception as e:
            print e.message
            print traceback.format_exc()
            result = {'success': False, 'error_message': e.message}
    # It doesn't matter what we return at this point - the phones are just checking the response status
    response_dict = {"status": "success"}
    return HttpResponse(json.dumps(response_dict),
                        content_type='application/json')
Beispiel #19
0
def automatic_error_json(request):
    authenticator = JSONAuthenticator()
    return authenticator.error_response()
def data(request):
    '''decrypt funf database files, and upload them to your PDS'''
    result = {}
    connection = None

    for filename, file in request.FILES.items():
        logging.debug(filename)
    if request.method == 'GET':
	template = {'token':request.GET['bearer_token']}
    	return render_to_response('upload.html',
        template,
        RequestContext(request))
    pds = None
    scope = AccessRange.objects.get(key="funf_write")
#    authenticator = Authenticator(scope=scope)
    authenticator = JSONAuthenticator(scope=scope)
    try:
        # Validate the request.
        authenticator.validate(request)
    except AuthenticationException as e:
        # Return an error response.
	print e
        return authenticator.error_response(content="You didn't authenticate.")
    profile = authenticator.user.get_profile()
    funf_password = profile.funf_password	

    try:
	    
        scope = 'funf_write'
	token = request.GET['bearer_token']

	try:
            key = decrypt.key_from_password(str(funf_password))
	    print key
            file_path = upload_dir + file.name
            write_file(str(file_path), file)
	except Exception as ex:
	    print "failed to write file to "+file_path+".  Please make sure you have write permission to the directory set in settings.SERVER_UPLOAD_DIR"
        dbdecrypt.decrypt_if_not_db_file(file_path, key)
        con = sqlite3.connect(file_path)
        cur = con.cursor()
        cur.execute("select value from data")
	inserted = []
        for row in cur:
	    json_insert = clean_keys(json.JSONDecoder().decode(convert_string(row)))
	    print json_insert
            # Insert into PDS
	    pds_data= {}
	    pds_data['time']=json_insert.get('timestamp')
	    pds_data['value']=json_insert
	    pds_data['key']=json_insert.get('probe')
	    insert_pds(profile, token, pds_data)
	    print "inserting row..."
	    print pds_data
	    inserted.append(convert_string(json_insert)+'\n')
	result = {'success': True, 'message':''.join(inserted)} 
			
    except Exception as e:
        result = {'success':False, 'error_message':e.message}

    finally:
        response_dict = {"status":"success"}
        return HttpResponse(json.dumps(response_dict), content_type='application/json')
Beispiel #21
0
def automatic_error_json(request):
    authenticator = JSONAuthenticator()
    return authenticator.error_response()