Esempio n. 1
0
def verify(request,id, verify_hash):
    m = hashlib.sha224("some_salt1234"+str(id))
    m.hexdigest()
    if verify_hash == m.hexdigest():
        v_user = User.objects.get(id=id)
        verified_group = Group.objects.get(name='verified')
        v_user.groups.add(verified_group)
        helpers.register_invites(v_user)
        v_user.save()
        return HttpResponseRedirect("/")
Esempio n. 2
0
def facebook(request):
    client_sub_domain = CLIENT_SUB_DOMAIN
    if request.method == 'GET':
        if 'error' in request.GET:
            messages.error(request, 'To use Facebook to log in, please give' +
                    'the IdeaOtter permission to use your details.')
            return redirect('django.contrib.auth.views.login')
        else:
            url = ('https://graph.facebook.com/oauth/access_token?' +
                    'client_id=' + str(FACEBOOK_ID) +
                    '&redirect_uri=http://localhost:8000/accounts/facebook/' +
                    '&client_secret=' + str(FACEBOOK_SECRET) +
                    '&code=' + request.GET['code'])
            request.GET['state']
            fetchedinfo = urllib.urlopen(url)
            access_token = fetchedinfo.read()
            if 'error' in access_token:
                messages.error(request, 'Something went wrong when ' +
                        'activating your account, please try again later'+
                        access_token)
                return redirect('django.contrib.auth.views.login')
            url = 'https://graph.facebook.com/me?'+access_token
            fetchedinfo = urllib.urlopen(url)
            user_info = json.loads(fetchedinfo.read())
            try:
                user = User.objects.get(username = user_info['username'])
            except User.DoesNotExist:
                user = User.objects.create_user(
                        user_info['username'],
                        user_info['email'],
                        ''
                        )
                user.first_name=user_info['first_name']
                user.last_name=user_info['last_name']
                user.save()
            user_profile = user.get_profile()
            user_profile.facebook_access_token = access_token
            user_profile.save()
            verified_group = Group.objects.get(name='verified')
            user.groups.add(verified_group)
            helpers.register_invites(user)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            user.save()
            login(request, user)
            return HttpResponseRedirect("/")