<commit_before>from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext

from oauth_access.consumer import OAuthAccess



def oauth_login(request, service):
    access = OAuthAccess(service)
    token = access.unauthorized_token()
    request.session["%s_unauth_token" % service] = token.to_string()
    return HttpResponseRedirect(access.authorization_url(token))


def oauth_callback(request, service):
    ctx = RequestContext(request)
    access = OAuthAccess(service)
    unauth_token = request.session.get("%s_unauth_token" % service, None)
    if unauth_token is None:
        ctx.update({"error": "token_missing"})
    else:
        auth_token = access.check_token(unauth_token, request.GET)
        if auth_token:
            request.session["%s_token" % service] = str(auth_token)
            return HttpResponseRedirect(reverse("import_contacts"))
        else:
            ctx.update({"error": "token_mismatch"})
    return render_to_response("oauth_access/oauth_error.html", ctx)<commit_msg>note to self for future improvement<commit_after>from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext

from oauth_access.consumer import OAuthAccess



def oauth_login(request, service):
    access = OAuthAccess(service)
    token = access.unauthorized_token()
    request.session["%s_unauth_token" % service] = token.to_string()
    return HttpResponseRedirect(access.authorization_url(token))


def oauth_callback(request, service):
    ctx = RequestContext(request)
    access = OAuthAccess(service)
    unauth_token = request.session.get("%s_unauth_token" % service, None)
    if unauth_token is None:
        ctx.update({"error": "token_missing"})
    else:
        auth_token = access.check_token(unauth_token, request.GET)
        if auth_token:
            request.session["%s_token" % service] = str(auth_token)
            # @@@ allow other and custom operations here
            return HttpResponseRedirect(reverse("import_contacts"))
        else:
            ctx.update({"error": "token_mismatch"})
    return render_to_response("oauth_access/oauth_error.html", ctx)
{'fraction_non_alphanumeric': 0.09710467706013363, 'fraction_numerical': 0.0, 'mean_word_length': 4.199074074074074, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '620816', 'n_tokens_mistral': 655, 'n_tokens_neox': 639, 'n_words': 134}