Пример #1
0
def auth(request):
    code = request.GET.get("code")
    if code:
        token = oauth.get_token(code)
        user = utils.save_token(token)
        request.session["user"] = user.user_id
        return redirect("/")
    return render(request, 'error.html')
Пример #2
0
def get_users(domain='us'):
    ACCESS_TOKEN = oauth.get_token(domain)['access_token']
    BASE_URL = 'https://' + ('data'
                             if domain == 'us' else domain) + '.castoredc.com'
    USER = '******'

    headers = {'Authorization': 'Bearer ' + ACCESS_TOKEN}

    response = requests.get(url=BASE_URL + USER, headers=headers)

    users = response.json()

    return users
Пример #3
0
def get_study_user(study_id, user_id, domain='us'):
    ACCESS_TOKEN = oauth.get_token(domain)['access_token']
    BASE_URL = 'https://' + ('data'
                             if domain == 'us' else domain) + '.castoredc.com'
    PATH = '/api/study/' + study_id + '/user/'

    headers = {'Authorization': 'Bearer ' + ACCESS_TOKEN}

    response = requests.get(url=BASE_URL + PATH + user_id, headers=headers)

    user = response.json()

    return user
def get_study_records(studyID, domain='us'):
    ACCESS_TOKEN = oauth.get_token(domain)['access_token']
    BASE_URL = 'https://' + ('data'
                             if domain == 'us' else domain) + '.castoredc.com'
    RECORDS = '/api/study/' + studyID + '/record'

    headers = {'Authorization': 'Bearer ' + ACCESS_TOKEN}

    response = requests.get(url=BASE_URL + RECORDS, headers=headers)

    records = response.json()

    return records
Пример #5
0
def auth_douban_callback():
    if request.method == 'GET':
        code = request.args.get('code', '')
        token = get_token(douban, code)
        info_res = get_info(douban, token)
        info_json = json.loads(info_res)
        profile = {
                'email': 'douban' + info_json['uid'],
                'username': info_json['name'],
                'image_url': info_json['avatar'],
                'password': '******'
                }
        return auth_register(profile)
Пример #6
0
def get_study(id, domain='us'):
    ACCESS_TOKEN = oauth.get_token(domain)['access_token']
    BASE_URL = 'https://' + ('data'
                             if domain == 'us' else domain) + '.castoredc.com'
    STUDY = '/api/study/'

    headers = {'Authorization': 'Bearer ' + ACCESS_TOKEN}

    response = requests.get(url=BASE_URL + STUDY + id, headers=headers)

    study = response.json()

    return study
Пример #7
0
def auth_douban_callback():
    if request.method == 'GET':
        code = request.args.get('code', '')
        token = get_token(douban, code)
        info_res = get_info(douban, token)
        info_json = json.loads(info_res)
        profile = {
            'email': 'douban' + info_json['uid'],
            'username': info_json['name'],
            'image_url': info_json['avatar'],
            'password': '******'
        }
        return auth_register(profile)
Пример #8
0
def get_study_institutes(studyID, domain='us'):
    ACCESS_TOKEN = oauth.get_token(domain)['access_token']
    BASE_URL = 'https://' + ('data'
                             if domain == 'us' else domain) + '.castoredc.com'
    PATH = '/api/study/' + studyID + '/institute'

    headers = {'Authorization': 'Bearer ' + ACCESS_TOKEN}

    response = requests.get(url=BASE_URL + PATH, headers=headers)

    institutes = response.json()

    return institutes
Пример #9
0
def get_report_data_point_collection(studyID, domain='us'):
  ACCESS_TOKEN = oauth.get_token(domain)['access_token']
  BASE_URL = 'https://' + ('data' if domain == 'us' else domain) + '.castoredc.com'
  PATH = '/api/study/' + studyID + '/data-point-collection/report-instance'

  headers = {
    'Authorization': 'Bearer ' + ACCESS_TOKEN
  }

  response = requests.get(url = BASE_URL + PATH, headers = headers)

  collection = response.json()

  return collection  
def export_study_data(studyID, domain='us'):
  ACCESS_TOKEN = oauth.get_token(domain)['access_token']
  BASE_URL = 'https://' + ('data' if domain == 'us' else domain) + '.castoredc.com'
  PATH = '/api/study/' + studyID + '/export/data'

  headers = {
    'Authorization': 'Bearer ' + ACCESS_TOKEN
  }
  print(BASE_URL + PATH)
  response = requests.get(url = BASE_URL + PATH, headers = headers)

  data = response.json()
  
  return data
Пример #11
0
def reddit_callback():
    error = request.args.get('error', '')
    if error:
        return "Error: " + error
    state = request.args.get('state', '')
    if not oauth.is_valid_state(state):
        # Uh-oh, this request wasn't started by us!
        return status.HTTP_403_FORBIDDEN
    code = request.args.get('code')
    access_token = oauth.get_token(code)
    # Note: In most cases, you'll want to store the access token, in, say,
    # a session for use in other parts of your web app.
    session['username'] = oauth.get_username(
        access_token)  # set username for session
    return redirect("/", code=302)  # redirect to main voting page
Пример #12
0
def auth_google_callback():
    if request.method == 'GET':
        code = request.args.get('code', '')
        token = get_token(google, code)
        info_res = get_info(google, token)
        info_json = json.loads(info_res)
        plus_name = info_json['displayName']
        image = info_json['image']['url']
        emails = info_json['emails']
        for i in emails:
            if i['type'] == 'account':
                email = i['value']
                break
        profile = {
                'email': email,
                'username': plus_name,
                'image_url': image,
                'password': '******'
                }
        return auth_register(profile)
Пример #13
0
def auth_google_callback():
    if request.method == 'GET':
        code = request.args.get('code', '')
        token = get_token(google, code)
        info_res = get_info(google, token)
        info_json = json.loads(info_res)
        plus_name = info_json['displayName']
        image = info_json['image']['url']
        emails = info_json['emails']
        for i in emails:
            if i['type'] == 'account':
                email = i['value']
                break
        profile = {
            'email': email,
            'username': plus_name,
            'image_url': image,
            'password': '******'
        }
        return auth_register(profile)