# Path: janrain/api.py
# class JanrainAuthenticationError(Exception):
# def auth_info(token):
# def get_contacts(ident):
# def set_status(ident, status, loc=None, truncate=True):
# def map(ident, pk, overwrite=True):
# def unmap(pk, identifier=None, all_identifiers=False, unlink=False):
# def mappings(pk):
# def activity(ident, activity, trunc=True, loc=None):
# def analytics_access(start, end):
# def set_auth_providers(providers):
# def _api_call(function, **kwargs):
# 
# Path: janrain/models.py
# class JanrainUser(models.Model):
#     user       = models.ForeignKey(User, related_name='janrain_user')
#     username   = models.CharField(max_length=512, blank=False)
#     provider   = models.CharField(max_length=64, blank=False)
#     identifier = models.URLField(max_length=512, blank=False)
#     avatar     = models.URLField(max_length=512, blank=True)
#     url        = models.URLField(max_length=512, blank=True)


from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib import auth
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response
from django.template import RequestContext
from janrain import api
from janrain.models import JanrainUser
from janrain.signals import *
    iFiltr, Simple & Secure Social Shopping.
    Copyright (C) 2012-2013 iFiltr (<https://ifiltr.com>).

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
"""


@csrf_exempt
def login(request):
    pre_login.send(JanrainSignal, request=request)
    try:
        token = request.POST['token']
    except KeyError:
        # TODO: set ERROR to something
        login_failure.send(JanrainSignal, message='Error retreiving token', data=None)
        return HttpResponseRedirect('/')

    try:
        profile = api.auth_info(token)

# Path: janrain/api.py
# class JanrainAuthenticationError(Exception):
# def auth_info(token):
# def get_contacts(ident):
# def set_status(ident, status, loc=None, truncate=True):
# def map(ident, pk, overwrite=True):
# def unmap(pk, identifier=None, all_identifiers=False, unlink=False):
# def mappings(pk):
# def activity(ident, activity, trunc=True, loc=None):
# def analytics_access(start, end):
# def set_auth_providers(providers):
# def _api_call(function, **kwargs):
# 
# Path: janrain/models.py
# class JanrainUser(models.Model):
#     user       = models.ForeignKey(User, related_name='janrain_user')
#     username   = models.CharField(max_length=512, blank=False)
#     provider   = models.CharField(max_length=64, blank=False)
#     identifier = models.URLField(max_length=512, blank=False)
#     avatar     = models.URLField(max_length=512, blank=True)
#     url        = models.URLField(max_length=512, blank=True)


# Path: janrain/views.py
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib import auth
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response
from django.template import RequestContext
from janrain import api
from janrain.models import JanrainUser
from janrain.signals import *

    iFiltr, Simple & Secure Social Shopping.
    Copyright (C) 2012-2013 iFiltr (<https://ifiltr.com>).

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
"""


@csrf_exempt
def login(request):
    pre_login.send(JanrainSignal, request=request)
    try:
        token = request.POST['token']
    except KeyError:
        # TODO: set ERROR to something
        login_failure.send(JanrainSignal, message='Error retreiving token', data=None)
        return HttpResponseRedirect('/')

    try:
        profile = api.auth_info(token)

    except api.JanrainAuthenticationError: