def update(self, request, matricula): aluno = buscar_aluno(matricula) impressao_digital = request.data.get('digital', None) if aluno is not None and impressao_digital is not None: basic_authentication = HttpBasicAuthentication() if not basic_authentication.is_authenticated(request): return basic_authentication.challenge() aluno.set_impressao_digital(psycopg2.Binary(str(impressao_digital)))
def update(self, request, matricula): aluno = buscar_aluno(matricula) basic_authentication = HttpBasicAuthentication() if not basic_authentication.is_authenticated(request): return basic_authentication.challenge() if aluno != None: if aluno_nao_comeu(aluno): try: RefeicaoMensalDoAluno.deduzir_refeicao_do_aluno(aluno, mes_corrente(), ANO_LETIVO) aluno.consumir_refeicao() except RefeicaoEsgotada: return HttpResponseForbidden() else: return HttpResponseForbidden() else: return HttpResponseForbidden()
def get_url_pattens(app_list): """Gets app list returns urls patterns""" models = get_all_models(app_list, from_django=True) urlpatterns = [] models_list = [] for model in models: urlpatterns.append(url(r"^"+get_resource_name_for_model(model),\ create_resource(model))) InfoHandler.set_models(models) urlinfo = url(r"^info", Resource(InfoHandler, HttpBasicAuthentication())) urlpatterns.append(urlinfo) return patterns("", * urlpatterns)
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from archlinux.aur.api.handlers import PackageInfoHandler auth = HttpBasicAuthentication(realm='AUR API') package_info_handler = Resource(handler=PackageInfoHandler, authentication=auth) urlpatterns = patterns( '', url(r'^packages\.(?P<emitter_format>[a-zA-Z]+)$', package_info_handler), url(r'^packages$', package_info_handler, {'emitter_format': 'json'}), url(r'^package/(?P<object_id>[\w_-]+)\.(?P<emitter_format>[a-zA-Z]+)$', package_info_handler), url(r'^package/(?P<object_id>[\w_-]+)$', package_info_handler, {'emitter_format': 'json'}), )
# # muspy 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 muspy. If not, see <http://www.gnu.org/licenses/>. from django.conf.urls.defaults import * from piston.authentication import HttpBasicAuthentication from api.handlers import * auth = {'authentication': HttpBasicAuthentication(realm="api")} artist_handler = ApiResource(handler=ArtistHandler) artists_handler = ApiResource(handler=ArtistsHandler, **auth) release_handler = ApiResource(handler=ReleaseHandler) releases_handler = ApiResource(handler=ReleasesHandler) user_handler = ApiResource(handler=UserHandler, **auth) urlpatterns = patterns( '', (r'artist/(?P<mbid>[0-9a-f\-]{36})', artist_handler), (r'artists/(?P<userid>[0-9a-z]{30})(/(?P<mbid>[0-9a-f\-]{36}))?', artists_handler), (r'release/(?P<mbid>[0-9a-f\-]{36})', release_handler), (r'releases(/(?P<userid>[0-9a-z]{30}))?', releases_handler), (r'user(/(?P<userid>[0-9a-z]{30}))?', user_handler),
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from cm.api.handlers import * auth = HttpBasicAuthentication(realm='Comt API') text_handler = Resource(handler=TextHandler, authentication=auth) textversion_handler = Resource(handler=TextVersionHandler, authentication=auth) text_list_handler = Resource(handler=TextListHandler, authentication=auth) text_delete_handler = Resource(handler=TextDeleteHandler, authentication=auth) text_pre_edit_handler = Resource(handler=TextPreEditHandler, authentication=auth) text_edit_handler = Resource(handler=TextEditHandler, authentication=auth) text_feed_handler = Resource(handler=TextFeedHandler, authentication=auth) tv_revert_handler = Resource(handler=TextVersionRevertHandler, authentication=auth) tv_delete_handler = Resource(handler=TextVersionDeleteHandler, authentication=auth) text_export_handler = Resource(handler=TextExportHandler, authentication=auth) import_handler = Resource(handler=ImportHandler, authentication=auth) comments_handler = Resource(handler=CommentsHandler, authentication=auth) convert_handler = Resource(handler=ConvertHandler, authentication=auth) client_handler = Resource(handler=ClientHandler, authentication=auth)
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from jflow.db.instdata import api as dataapi from jflow.db.trade import api as tradeapi auth = HttpBasicAuthentication(realm='JFLOW API') apis = dataapi.urls(auth) + tradeapi.urls(auth) urlpatterns = patterns('', *apis)
from django.conf.urls.defaults import * from piston.authentication import HttpBasicAuthentication from piston.resource import Resource from serie.handlers import SerieListHandler, SerieHandler, SeasonListHandler, SeasonHandler, EpisodeHandler auth = HttpBasicAuthentication(realm="Liberateca API - Autenticacion") ad = { 'authentication': auth } serielist_resource = Resource(handler=SerieListHandler, **ad) serie_resource = Resource(handler=SerieHandler, **ad) seasonlist_resource = Resource(handler=SeasonListHandler, **ad) season_resource = Resource(handler=SeasonHandler, **ad) episode_resource = Resource(handler=EpisodeHandler, **ad) urlpatterns = patterns('', url(r'^/serie$', serielist_resource), url(r'^/serie/(?P<serie_id>\d+)$', serie_resource, name='API_serie_detail'), url(r'^/serie/(?P<serie_id>\d+)/seasons$', seasonlist_resource), url(r'^/serie/(?P<serie_id>\d+)/(?P<season>\d+)$', season_resource, name='API_season_detail'), url(r'^/serie/(?P<serie_id>\d+)/(?P<season>\d+)/(?P<episode>\d+)$', episode_resource, name='API_episode_detail'), )
# -*- coding: utf-8 -*- from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from proyecto.app.api.handlers import ServicioValidadorHandler from proyecto.app.api.handlers import PeriodoEvaluacionHandler from proyecto.app.api.handlers import PeriodoAcademicoHandler from proyecto.app.api.handlers import ResultadosHandler from proyecto.app.api.handlers import ParametrosHandler from proyecto.app.api.handlers import UsuarioHandler authapi = HttpBasicAuthentication(realm='seddrealm') periodo_academico_handler = Resource(PeriodoAcademicoHandler) periodo_evaluacion_handler = Resource(PeriodoEvaluacionHandler, authentication=authapi) servicio_validador_handler = Resource(ServicioValidadorHandler, authentication=authapi) resultados_handler = Resource(ResultadosHandler, authentication=authapi) parametros_handler = Resource(ParametrosHandler) usuario_handler = Resource(UsuarioHandler, authentication=authapi) urlpatterns = patterns( '', url(r'^periodos_academicos/', periodo_academico_handler), url(r'^periodos_evaluacion/', periodo_evaluacion_handler), url(r'^verificar/(?P<id_periodo_evaluacion>\d{1,2})/(?P<dni>\w{7,})/', servicio_validador_handler), url(r'^resultados/(?P<id_periodo_evaluacion>\d{1,2})/(?P<dni>\w{7,})/', resultados_handler),
''' mds.tasks.urls :author: Sana Development Team :version: 2.0 :copyright: Sana 2012, released under BSD New License(http://sana.mit.edu/license) ''' from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from mds.api.authentication import DjangoAuthentication, MultiAuthentication from .handlers import * basic_auth = HttpBasicAuthentication(realm="BasicAuth") django_auth = DjangoAuthentication() auth = MultiAuthentication([basic_auth, django_auth]) etask_rsrc = Resource(EncounterTaskHandler, authentication=auth) otask_rsrc = Resource(ObservationTaskHandler, authentication=auth) status_rsrc = Resource(StatusHandler, authentication=auth)
from django.conf.urls.defaults import * from piston.resource import Resource from lb_rest_inf.api.handlers import JSONRequestHandler, MonitoringHandler, LoginHandler, ServerHandler, ServiceHandler, VirtServerHandler, VirtServerServiceHandler, VirtServerPolicyHandler from piston.authentication import HttpBasicAuthentication # Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover() import netscaler auth = HttpBasicAuthentication(realm="LB API") jsonrequest_handler = Resource(JSONRequestHandler, authentication=auth) login_handler = Resource(LoginHandler, authentication=auth) server_handler = Resource(ServerHandler, authentication=auth) service_handler = Resource(ServiceHandler, authentication=auth) virtserver_handler = Resource(VirtServerHandler, authentication=auth) virtserverservice_handler = Resource(VirtServerServiceHandler, authentication=auth) virtserverpolicy_handler = Resource(VirtServerPolicyHandler, authentication=auth) monitoring_handler = Resource(MonitoringHandler) urlpatterns = patterns( '', # Example: # (r'^lb_rest_inf/', include('lb_rest_inf.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation:
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from api.provisioning import ProviderHandler, NodeHandler, ImageHandler auth = HttpBasicAuthentication(realm="overmind") ad = {'authentication': auth} class CsrfExemptResource(Resource): '''Django 1.2 CSRF protection can interfere''' def __init__(self, handler, authentication=None): super(CsrfExemptResource, self).__init__(handler, authentication) self.csrf_exempt = getattr(self.handler, 'csrf_exempt', True) provider_resource = CsrfExemptResource(ProviderHandler, **ad) image_resource = CsrfExemptResource(ImageHandler, **ad) node_resource = CsrfExemptResource(NodeHandler, **ad) urlpatterns = patterns( '', url(r'^providers/(?P<provider_id>\d+)/images/$', image_resource), url(r'^providers/(?P<provider_id>\d+)/images/(?P<id>\d+)$', image_resource), url(r'^providers/$', provider_resource), url(r'^providers/(?P<id>\d+)$', provider_resource), url(r'^nodes/$', node_resource), url(r'^nodes/(?P<id>\d+)$', node_resource), )
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication auth = HttpBasicAuthentication(realm="My Realm") ad = { 'authentication': auth } blogpost_resource = Resource(handler=BlogPostHandler, **ad) arbitrary_resource = Resource(handler=ArbitraryDataHandler, **ad) urlpatterns += patterns('', url(r'^posts/(?P<post_slug>[^/]+)/$', blogpost_resource), url(r'^other/(?P<username>[^/]+)/(?P<data>.+)/$', arbitrary_resource),
from __future__ import absolute_import from django.conf.urls.defaults import * from blogserver.api.handlers import BlogpostHandler from piston.authentication import HttpBasicAuthentication from piston.doc import documentation_view from piston.resource import Resource auth = HttpBasicAuthentication(realm="My sample API") blogposts = Resource(handler=BlogpostHandler, authentication=auth) urlpatterns = patterns( "", url(r"^posts/$", blogposts), url(r"^posts/(?P<emitter_format>.+)/$", blogposts), url(r"^posts\.(?P<emitter_format>.+)", blogposts, name="blogposts"), # automated documentation url(r"^$", documentation_view), )
from django_roa_server.handlers import RemotePageHandler, \ RemotePageWithManyFieldsHandler, RemotePageWithBooleanFieldsHandler, \ RemotePageWithCustomSlugHandler, RemotePageWithOverriddenUrlsHandler, \ RemotePageWithRelationsHandler, UserHandler, MessageHandler, \ PermissionHandler, GroupHandler, RemotePageCountHandler, \ RemotePageWithManyFieldsCountHandler, RemotePageWithBooleanFieldsCountHandler, \ RemotePageWithCustomSlugCountHandler, RemotePageWithOverriddenUrlsCountHandler, \ RemotePageWithRelationsHandler, RemotePageWithNamedRelationsHandler, \ RemotePageWithNamedRelationsCountHandler, RemotePageWithRelationsThroughHandler, \ RemotePageWithCustomPrimaryKeyHandler, RemotePageWithCustomPrimaryKeyCountHandler, \ RemotePageWithCustomPrimaryKeyCount2Handler # Enable HTTP authentication through django-piston ad = { 'authentication': HttpBasicAuthentication( realm="django-roa-server", auth_func = lambda username, password: username == 'django-roa' and password == 'roa' )} # Disable authentication through django-piston #ad = { 'authentication': None} remote_pages = Resource(handler=RemotePageHandler, **ad) remote_pages_count = Resource(handler=RemotePageCountHandler, **ad) remote_pages_with_many_fields = Resource(handler=RemotePageWithManyFieldsHandler, **ad) remote_pages_with_many_fields_count = Resource(handler=RemotePageWithManyFieldsCountHandler, **ad) remote_pages_with_boolean_fields = Resource(handler=RemotePageWithBooleanFieldsHandler, **ad) remote_pages_with_boolean_fields_count = Resource(handler=RemotePageWithBooleanFieldsCountHandler, **ad) remote_pages_with_custom_slug = Resource(handler=RemotePageWithCustomSlugHandler, **ad) remote_pages_with_custom_slug_count = Resource(handler=RemotePageWithCustomSlugCountHandler, **ad)
from django.conf.urls.defaults import patterns, url from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from om.api.handlers import PersonHandler, InstitutionHandler auth = HttpBasicAuthentication(realm="openmunicipio API") ad = {'authentication': auth} person_resource = Resource(handler=PersonHandler, **ad) institution_resource = Resource(handler=InstitutionHandler, **ad) urlpatterns = patterns( '', url(r'^persons/$', person_resource), url(r'^persons/(?P<id>\d+)/$', person_resource), url(r'^persons_lookup/(?P<last_name>[^/]*)/$', person_resource), url(r'^persons_lookup/(?P<first_name>[^/]*)/(?P<last_name>[^/]*)/$', person_resource), url( r'^persons_lookup/(?P<first_name>[^/]*?)/(?P<last_name>[^/]*?)/(?P<birth_date>[-\d]*)/$', person_resource), url( r'^persons_lookup/(?P<first_name>[^/]*?)/(?P<last_name>[^/]*?)/(?P<birth_date>[-\d]*?)/(?P<birth_location>.*)/$', person_resource), url(r'^institutions/$', institution_resource), url(r'^institutions/(?P<id>\d+)/$', institution_resource), )
""" Returns a 401 response with a small bit on what OAuth is, and where to learn more about it. When this was written, browsers did not understand OAuth authentication on the browser side, and hence the helpful template we render. Maybe some day in the future, browsers will take care of this stuff for us and understand the 401 with the realm we give it. """ response = HttpResponse() response.status_code = 401 for k, v in oauth.build_authenticate_header(realm=self.realm).iteritems(): response[k] = v response.content = """ Unable to authenticate. Make sure you use oAuth 1.0 authentication and a valid consumer key. """ return response auth_engine_name = getattr(settings, 'HARDTREE_API_AUTH_ENGINE', 'oauth') if auth_engine_name == 'oauth': auth_engine = OAuthAuthentication() else: from piston.authentication import HttpBasicAuthentication auth_engine = HttpBasicAuthentication(realm='My sample API')
# -*- mode: python; coding: utf-8; -*- from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication #from piston.doc import documentation_view from fsb.billing.api.handlers import AccountHandler auth = HttpBasicAuthentication(realm='FreeSWITCH Admin API') account = Resource(handler=AccountHandler, authentication=auth) urlpatterns = patterns('', url(r'^$', account, name='account'), url(r'^(?P<account>.+)/$', account), )
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from notes.handlers import AnnotationHandler, SearchHandler auth = HttpBasicAuthentication(realm="Annotator") ad = {'authentication': auth} annotation_resource = Resource(handler=AnnotationHandler, **ad) search_resource = Resource(handler=SearchHandler) urlpatterns = patterns( '', url(r'^$', annotation_resource), url(r'^search$', search_resource), url(r'^(?P<id>.*)$', annotation_resource), )
from django.conf.urls.defaults import patterns, include, url from django.contrib import admin from mvp.models import Resource from piston.authentication import HttpBasicAuthentication from api import * authentication = {'authentication': HttpBasicAuthentication(realm='fanmento')} urlpatterns = patterns( '', (r'venue$', Resource(handler=VenueHandler, **authentication)), (r'ad/(?P<ad_id>[^/]+)/image$', 'fanmento.fantemplate.views.ad_image'), (r'ad/(?P<template_id>[^/]+)/?$', Resource(handler=AdvertisementHandler, **authentication)), (r'category$', Resource(handler=CategoryHandler, **authentication)), (r'background/(?P<bg_id>[^/]+)/image', 'fanmento.fantemplate.views.background_image'), (r'template/(?P<template_id>[^/]+)/image', 'fanmento.fantemplate.views.template_image'), (r'template/(?P<code>[^/]+)', Resource(handler=TemplateByCodeHandler, **authentication)), (r'template', Resource(handler=TemplateByQueryHandler, **authentication)), )
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from tasks_api.handlers import TasksHandler auth = HttpBasicAuthentication(realm="Pinax realm") tasks_resource = Resource(TasksHandler, authentication=auth) urlpatterns = patterns( '', url(r'^tasks/(?P<task_id>\d*)$', tasks_resource), )
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication, HttpBasicSimple from piston.authentication.oauth import OAuthAuthentication from test_project.apps.testapp.handlers import EntryHandler, ExpressiveHandler, AbstractHandler, EchoHandler, PlainOldObjectHandler, Issue58Handler, ListFieldsHandler auth = HttpBasicAuthentication(realm='TestApplication') entries = Resource(handler=EntryHandler, authentication=auth) expressive = Resource(handler=ExpressiveHandler, authentication=auth) abstract = Resource(handler=AbstractHandler, authentication=auth) echo = Resource(handler=EchoHandler) popo = Resource(handler=PlainOldObjectHandler) list_fields = Resource(handler=ListFieldsHandler) issue58 = Resource(handler=Issue58Handler) AUTHENTICATORS = [auth,] SIMPLE_USERS = (('admin', 'secr3t'), ('admin', 'user'), ('admin', 'allwork'), ('admin', 'thisisneat')) for username, password in SIMPLE_USERS: AUTHENTICATORS.append(HttpBasicSimple(realm='Test', username=username, password=password)) multiauth = Resource(handler=PlainOldObjectHandler, authentication=AUTHENTICATORS) ouath_two_legged_api = Resource(handler=EchoHandler, authentication=OAuthAuthentication(realm='TestApplication', two_legged=True))
from django.conf.urls.defaults import * from django.http import HttpResponse from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from piston.utils import Mimer from txtalert.apps.api.handlers import (SMSHandler, PCMHandler, SMSReceiptHandler, PatientHandler, ChangeRequestHandler, CallRequestHandler) # make sure Piston also accepts text/xml with charset=utf-8 Mimer.register(lambda *a: None, ('text/xml; charset=utf-8',)) http_basic_authentication = HttpBasicAuthentication() sms_receipt_handler = Resource(SMSReceiptHandler, http_basic_authentication) sms_handler = Resource(SMSHandler, http_basic_authentication) pcm_handler = Resource(PCMHandler, http_basic_authentication) patient_handler = Resource(PatientHandler) change_request_handler = Resource(ChangeRequestHandler, http_basic_authentication) call_request_handler = Resource(CallRequestHandler, http_basic_authentication) # SMS api urlpatterns = patterns('', url(r'^sms/receipt\.(?P<emitter_format>.+)$', sms_receipt_handler, {}, 'api-sms-receipt'), url(r'^sms/(?P<identifier>.+)/(?P<msisdn>[0-9]+)\.(?P<emitter_format>.+)$', sms_handler, {}, 'api-sms'), url(r'^sms\.(?P<emitter_format>.+)$', sms_handler, {}, 'api-sms'), url(r'^patient\.(?P<emitter_format>.+)$', patient_handler, {}, 'api-patient'), url(r'^request/change\.(?P<emitter_format>.+)$', change_request_handler, {}, 'api-req-change'), url(r'^request/call\.(?P<emitter_format>.+)$', call_request_handler, {}, 'api-req-call'), )
from re import match from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from django.conf.urls.defaults import * from .handlers import GetUserProfile, GetReportSurvey, Report auth = HttpBasicAuthentication(realm="EIP") ad = {'authentication': auth} resources = [ (GetUserProfile, ('uid', )), (GetReportSurvey, ('language', )), (Report, ( 'uid', 'reports', )), ] with_attrs = [ url(r'^%s/%s' % (handler.__name__, "/".join( [r'(?P<%s>[^/]+)' % attr for attr in attrs])), Resource(handler=handler, **ad) #, {'emitter_format': 'json'} ) for handler, attrs in resources ] without_attrs = [ url(r'^%s' % handler.__name__, Resource(handler=handler, **ad)
from django.conf.urls.defaults import patterns, include, url from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from api import handlers #Auth BASIC auth = HttpBasicAuthentication(realm="Test Auth") ad = {'authentication': auth} blog_handler = Resource(handler=handlers.BlogHandler, **ad) tag_handler = Resource(handler=handlers.TagHandler, **ad) urlpatterns = patterns( '', # Blog url(r'^blog/(?P<blog_id>[^/]+)/$', blog_handler), url(r'^blog/$', blog_handler), # Tag url(r'^tag/(?P<tag_id>[^/]+)/$', tag_handler), url(r'^tag/$', tag_handler), )
def read(self, request): basic_authentication = HttpBasicAuthentication() if not basic_authentication.is_authenticated(request): return basic_authentication.challenge()
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from steamer.api.handlers import * from steamer.api.auth import DjangoAuthentication from steamer.api.auth import MultiAuthentication auth = { 'authentication': MultiAuthentication([HttpBasicAuthentication(), DjangoAuthentication()])} service_h = Resource(ServiceHandler, **auth) services_forhost = Resource(ListServiceHandler, **auth) host_h = Resource(HostHandler, **auth) service_actions = Resource(ServiceActions, **auth) manage_host_services = Resource(ManageHostServices, **auth) urlpatterns = patterns('', url(r'^service/actions/(?P<actionname>\w+)/(?P<serviceid>\w+)/(?P<extra>.*)/$', service_actions, None, 'service_actions',), url(r'^service/forhost/(?P<hostid>\w+)/$', services_forhost), url(r'^service/managehosts/(?P<serviceid>\w+)/$', manage_host_services), url(r'^service/managehosts/$', manage_host_services), url(r'^service/(?P<id>[^/]+)/', service_h), url(r'^service/', service_h), url(r'^host/templates/$', host_h, {'register': False,}), url(r'^host/(?P<hostid>\w+)/$', host_h), url(r'^host/$', host_h), )
#coding=utf-8 from piston.handler import BaseHandler from piston.resource import Resource from piston.authentication import HttpBasicAuthentication, NoAuthentication from piston.doc import documentation_view from piston.utils import rc from django.db import models from dbapp.datautils import QueryData, get_field_verbosename import datetime import sys from mysite.urls import tmpDir, tmp_url from django.utils.translation import ugettext_lazy as _ from django.template import loader, Context import json from django.conf import settings auth = HttpBasicAuthentication(realm='ZK-ECO API') from base.middleware import threadlocals from base.models_logentry import LogEntry, EXPORT from django.contrib.contenttypes.models import ContentType import os def get_auth(request): if request.user.is_authenticated(): return NoAuthentication() else: return auth class ExportGridHandler(BaseHandler): def read(self, request, data_key):
from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from api.handlers import ProjectHandler, IterationHandler, StoryHandler, NewsfeedHandler auth = HttpBasicAuthentication(realm="ScrumDo Test Auth") ad = {'authentication': auth} project_handler = Resource(ProjectHandler, **ad) iteration_handler = Resource(IterationHandler, **ad) story_handler = Resource(StoryHandler, **ad) newsfeed_handler = Resource(NewsfeedHandler, **ad) urlpatterns = patterns( '', url(r'^projects/mine', project_handler, {"user": True}), url(r'^projects/organization/(?P<slug>[^/]+)/', project_handler, {"org": True}), url(r'^projects/', project_handler), url(r'^project/(?P<slug>[^/]+)/iterations', iteration_handler), url(r'^project/(?P<slug>[^/]+)/iteration/(?P<iteration_id>[^/]+)/stories', story_handler), url(r'^project/(?P<slug>[^/]+)/story/create', story_handler), url(r'^project/(?P<slug>[^/]+)/story/(?P<story_id>[^/]+)/delete', story_handler), url(r'^project/(?P<slug>[^/]+)/story/(?P<story_id>[^/]+)/comment', story_handler), url(r'^project/(?P<slug>[^/]+)/', project_handler), url(r'^newsfeed/(?P<num>[^/]+)', newsfeed_handler), url(r'^newsfeed/', newsfeed_handler),
from django.conf.urls.defaults import * from piston.authentication import HttpBasicAuthentication from piston.resource import Resource from snipt.api.handlers import * from snipt.api.views import * auth = HttpBasicAuthentication(realm="Snipt API") ad = {'authentication': auth} tag_handler = Resource(TagHandler) tags_handler = Resource(TagsHandler) user_handler = Resource(UserHandler) snipt_handler = Resource(SniptHandler) urlpatterns = patterns( '', (r'^/?$', home), url(r'^tags\.(?P<emitter_format>.+)$', tags_handler), url(r'^tags/(?P<tag_id>\d+)\.(?P<emitter_format>.+)$', tag_handler), url(r'^users/(?P<username>.+)\.(?P<emitter_format>.+)$', user_handler), url(r'^snipts/(?P<snipt_id>.+)\.(?P<emitter_format>.+)$', snipt_handler), )
#from django.conf.urls import patterns, include, url # # #user_api = Api() #user_api.register(UserResource()) # #urlpatterns = patterns('', # (r'^user/', include(user_api.urls)), ## (r'^login/', include(login.urls)), # ) from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from api.handlers import TimesheetHandler, UserHandler, LeaveHandler auth = HttpBasicAuthentication() ad = {'authentication': auth} class CsrfExemptResource(Resource): """A Custom Resource that is csrf exempt""" def __init__(self, handler, authentication=None): super(CsrfExemptResource, self).__init__(handler, authentication) self.csrf_exempt = getattr(self.handler, 'csrf_exempt', True) timesheet = CsrfExemptResource(handler=TimesheetHandler) user = CsrfExemptResource(handler=UserHandler) leave = CsrfExemptResource(handler=LeaveHandler) urlpatterns = patterns(
def uri(method): @classmethod def wrapper(cls, obj): ret = method(cls, obj) return ret and reverse(ret[0], args=ret[1]) or ret return wrapper def auth_func(username=None, password=None): try: user = SaaSUser.objects.get(username=username) if user.check_password(password): return user except SaaSUser.DoesNotExist, e: pass AUTHORIZED = [HttpBasicAuthentication(auth_func=auth_func)] ANONYMOUS = [NoAuthentication()] typemapper = TypeMapper() class Resource(PistonResource): @classmethod def register_anonymous(cls, handler): authorized = type(handler.__name__ + "Anon", (handler,), { 'is_anonymous':False, 'anonymous':handler, }) return cls(authorized, AUTHORIZED) @classmethod def register(cls, handler):
from django.contrib import admin admin.autodiscover() from django.conf.urls.defaults import patterns, url, include from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from .handlers import * basic_auth = HttpBasicAuthentication(realm="Tasks") etask_handler = Resource(EncounterTaskHandler, authentication=basic_auth) otask_handler = Resource(ObservationTaskHandler, authentication=basic_auth) urlpatterns = patterns( 'tasks', url(r'^encounter/$', etask_handler, name='encounter-task-list'), url(r'^encounter/(?P<uuid>[^/]+)/$', etask_handler, name='encounter-task'), url(r'^observation/$', otask_handler, name='observation-task-list'), url(r'^observation/(?P<uuid>[^/]+)/$', otask_handler, name='observation-task'), )