Пример #1
0
def ya_oauth_response(request, type_of_oauth):
    if request.method != 'GET':
        return HttpResponseForbidden()

    user = request.user
    OAUTH = ''
    PASSWORD = ''

    if type_of_oauth == 'contest':
        OAUTH = settings.CONTEST_OAUTH_ID
        PASSWORD = settings.CONTEST_OAUTH_PASSWORD
    elif type_of_oauth == 'passport':
        OAUTH = settings.PASSPORT_OAUTH_ID
        PASSWORD = settings.PASSPORT_OAUTH_PASSWORD

    ya_oauth = yandex_oauth.OAuthYandex(OAUTH, PASSWORD)
    ya_response = ya_oauth.get_token(int(request.GET['code']))
    ya_passport_response = requests.get(
        'https://login.yandex.ru/info?json&oauth_token=' +
        ya_response['access_token'])

    request.session["ya_oauth_login"] = ya_passport_response.json()['login']

    if type_of_oauth == 'contest':
        return ya_oauth_contest(user, ya_response, ya_passport_response.json())
    elif type_of_oauth == 'passport':
        return ya_oauth_passport(user, ya_response,
                                 ya_passport_response.json())

    return HttpResponseForbidden()
Пример #2
0
def ya_oauth_request(request, type_of_oauth):
    if type_of_oauth == 'contest':
        OAUTH = settings.CONTEST_OAUTH_ID
        PASSWORD = settings.CONTEST_OAUTH_PASSWORD
    elif type_of_oauth == 'passport':
        OAUTH = settings.PASSPORT_OAUTH_ID
        PASSWORD = settings.PASSPORT_OAUTH_PASSWORD

    ya_oauth = yandex_oauth.OAuthYandex(OAUTH, PASSWORD)

    return redirect(ya_oauth.get_code())