コード例 #1
0
ファイル: views.py プロジェクト: msradam/healthsites
    def post(self, request, *args):
        if not request.user.is_authenticated():
            return HttpResponseForbidden()
        data = request.data
        request.user.first_name = data.get('first-name', None)
        request.user.last_name = data.get('last-name', None)
        request.user.email = data.get('email', None)
        request.user.save()

        org_name = data.get('organisation-name', None)
        site_url = data.get('site-url', None)
        if org_name and site_url:
            if site_url:
                site, created = Site.objects.get_or_create(domain=site_url,
                                                           name=site_url)
                organisation, created = Organisation.objects.get_or_create(
                    name=org_name, site=site)
                trusted_user, created = TrustedUser.objects.get_or_create(
                    user=request.user)
                OrganisationSupported.objects.get_or_create(
                    user=trusted_user, organisation=organisation)

        UserApiKey.get_user_api_key(self.request.user, autogenerate=True)

        return HttpResponseRedirect(
            reverse('profile', kwargs={'username': request.user.username}))
コード例 #2
0
ファイル: authentication.py プロジェクト: msradam/healthsites
    def authenticate(self, request):
        api_key = request.GET.get('api-key', None)
        if not api_key:
            raise exceptions.AuthenticationFailed('api-key is needed')
        user = UserApiKey.get_user_from_api_key(api_key)
        if not user:
            raise exceptions.AuthenticationFailed('api-key is invalid')

        return (user, None)
コード例 #3
0
    def authenticate(self, request):
        api_key = request.GET.get('api-key', None)
        if not api_key:
            raise exceptions.AuthenticationFailed('api-key is needed')
        key = UserApiKey.get_key_from_api_key(api_key)
        user = key.user
        if not user:
            raise exceptions.AuthenticationFailed('api-key is invalid')
        if request.method != 'GET' and not key.allow_write:
            raise exceptions.AuthenticationFailed('this api-key is not allowed to post data')

        return (user, None)
コード例 #4
0
ファイル: views.py プロジェクト: jnicho02/healthsites
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        user = get_object_or_404(User, username=kwargs['username'])
        user = get_profile(user)
        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['user'] = user

        context['api_keys'] = None
        if self.request.user == user:
            autogenerate_api_key = False
            if user.is_superuser:
                autogenerate_api_key = True
            context['api_keys'] = UserApiKey.get_user_api_key(
                self.request.user, autogenerate=autogenerate_api_key)
        return context
コード例 #5
0
ファイル: views.py プロジェクト: healthsites/healthsites
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        user = get_object_or_404(User, username=kwargs['username'])
        user = get_profile(user)
        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['user'] = user

        context['api_keys'] = None
        if self.request.user == user:
            autogenerate_api_key = False
            if user.is_superuser:
                autogenerate_api_key = True
            context['api_keys'] = UserApiKey.get_user_api_key(
                self.request.user, autogenerate=autogenerate_api_key)
        return context
コード例 #6
0
ファイル: views.py プロジェクト: tyrasd/healthsites
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['api_keys'] = None
        try:
            user = User.objects.get(username=kwargs['username'])
            user = get_profile(user, self.request)
            osm_user = False

            if self.request.user == user:
                # this is for checking availability old data
                old_data = Locality.objects.filter(
                    changeset__social_user__username=user, migrated=False)

                if old_data:
                    context['old_data_available'] = True

                pathname = \
                    os.path.join(
                        settings.CACHE_DIR, 'data-migration-progress')
                progress_file = \
                    os.path.join(pathname, '{}.txt'.format(user))
                found = os.path.exists(progress_file)

                if found:
                    context['data_migration_in_progress'] = True

                autogenerate_api_key = False
                if user.is_superuser:
                    autogenerate_api_key = True
                context['api_keys'] = UserApiKey.get_user_api_key(
                    self.request.user, autogenerate=autogenerate_api_key)
        except User.DoesNotExist:
            user = {'username': kwargs['username']}
            osm_user = True

        context['user'] = user
        context['osm_user'] = osm_user
        context['osm_API'] = settings.OSM_API_URL
        return context