Esempio n. 1
0
class BaseTest(TestCase):

    def setUpProfile(self):
        from django.contrib.auth.models import User
        from userauth.models import Profile
        self.user = User.objects.create_user('test', '*****@*****.**', 'secret')
        self.user.save()
        self.profile = Profile(user = self.user, visible_name = self.user.username)
        self.profile.save()

    def getAnonymousClient(self):
        return Client()

    def getLoggedInClient(self):
        client = Client()
        client.login(username = "******", password = "******")
        return client
Esempio n. 2
0
        def wrapper(request, *args, **kwargs):
            if request.user.is_authenticated():
                # This is an a fixup for root account
                try:
                    profile = request.user.profile
                except:
                    profile = Profile(
                        user=request.user,
                        photo="",
                        openid_hash="",
                        karma=settings.START_RATING,
                        force=settings.START_RATING
                    )
                    profile.save()

                    try:
                        blog = Blog.objects.get(owner=request.user)
                    except Blog.DoesNotExist:
                        blog = Blog(owner=request.user, name=request.user.username)
                        blog.save()
                    except:
                        pass

                if not profile.visible_name:
                    if request.path not in (reverseURL("userauth.views.profile_edit"), 
                            reverseURL("userauth.views.openid_logout")):
                        return redirect("userauth.views.profile_edit")
            val = view(request, *args, **kwargs)
            if type(val) == type({}):
                val.update({'user': request.user})
                val.update(csrf(request))

                if settings.TEMPLATE_DEBUG:
                    return render_to_response(template, val, mimetype=mimetype)

                return HttpResponse(templates[template].render(Context(val)), mimetype = mimetype)
            else:
                return val
Esempio n. 3
0
def openid_finish(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/")

    form = None
    error = None
    request_args = request.GET

    store = getOpenIDStore("/tmp/taverna_openid", "c_")
    c = consumer.Consumer(request.session, store)

    return_to = getViewURL(request, openid_finish)
    response = c.complete(request_args, return_to)

    if response.status == consumer.SUCCESS:
        openid_hash=sha512(response.getDisplayIdentifier()).hexdigest()
        sreg_response = sreg.SRegResponse.fromSuccessResponse(response)

        try:
            profile = Profile.objects.get(openid_hash=openid_hash)
            username = profile.user.username
            user = authenticate(username=username)
            if user is not None:
                login(request, user)

            return HttpResponseRedirect("/")
        except Profile.DoesNotExist:
            user = User(
                       username=openid_hash[:30],
                       is_staff=False,
                       is_active=True,
                       is_superuser=False
                   )
            user.save()
            profile = Profile(
                          user=user,
                          photo="",
                          openid=response.getDisplayIdentifier(),
                          openid_hash=openid_hash,
                          karma=settings.START_RATING,
                          force=settings.START_RATING
                      )
            profile.save()
            try:
                blog = Blog.objects.get(owner=user)
            except Blog.DoesNotExist:
                blog = Blog(owner=user, name=openid_hash[:30])
                blog.save()

            auth = authenticate(username=user.username)
            if user is not None:
                login(request, auth)

            return HttpResponseRedirect(
                       reverse("userauth.views.profile_edit")
                   )
    else:
        error = "Verification of %s failed: %s" % (
                    response.getDisplayIdentifier(),
                    response.message
                )

    return {'from': form, 'error': error}