<commit_before>from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
from django.http import HttpResponse, Http404
from apps.oauth.models import AccessToken
import json
import os
import urllib


# Helper functions
def generate_token(user):
    while True:
        uid = os.urandom(10).encode('hex')
        if len(AccessToken.objects.filter(uid=uid)) == 0:
            token = AccessToken(uid=uid, user=user)
            token.save()
            return uid


@login_required
def require(request):
    uid = generate_token(request.user)
    callback = request.GET.get('callback', '')
    args = {
        'uid': uid,
    }
    return redirect(callback + '?' + urllib.urlencode(args))


def info(request):
    uid = request.GET.get('uid', '')
    token = AccessToken.objects.filter(uid=uid).first()
    if token is None:
        raise Http404()

    user = token.user
    token.delete()

    resp = {}
    resp['username'] = user.username
    return HttpResponse(json.dumps(resp), content_type='application/json')<commit_msg>modify oauth info method to return more infos<commit_after>from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
from django.http import HttpResponse, Http404
from apps.oauth.models import AccessToken
import json
import os
import urllib


# Helper functions
def generate_token(user):
    while True:
        uid = os.urandom(10).encode('hex')
        if len(AccessToken.objects.filter(uid=uid)) == 0:
            token = AccessToken(uid=uid, user=user)
            token.save()
            return uid


@login_required
def require(request):
    uid = generate_token(request.user)
    callback = request.GET.get('callback', '')
    args = {
        'uid': uid,
    }
    return redirect(callback + '?' + urllib.urlencode(args))


def info(request):
    uid = request.GET.get('uid', '')
    token = AccessToken.objects.filter(uid=uid).first()
    if token is None:
        raise Http404()

    user = token.user
    profile = user.user_profile
    token.delete()

    resp = {}
    resp['username'] = user.username
    resp['email'] = user.email
    resp['first_name'] = user.first_name
    resp['last_name'] = user.last_name
    resp['gender'] = profile.gender
    resp['birthday'] = profile.birthday

    return HttpResponse(json.dumps(resp), content_type='application/json')
{'fraction_non_alphanumeric': 0.12090680100755667, 'fraction_numerical': 0.007556675062972292, 'mean_word_length': 3.262969588550984, 'pattern_counts': {'":': 0, '<': 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': '5857761', 'n_tokens_mistral': 727, 'n_tokens_neox': 699, 'n_words': 166}