Commit cb84936b authored by Valentin Samir's avatar Valentin Samir
Browse files

an auth view to validate (username, password, service) by remote service

parent 690c2c3b
......@@ -102,16 +102,18 @@ class User(models.Model):
url = utils.update_url(service, {'ticket':ticket.value})
return url
class BadUsername(Exception):
class ServicePatternException(Exception):
class BadUsername(ServicePatternException):
"""Exception raised then an non allowed username
try to get a ticket for a service"""
class BadFilter(Exception):
class BadFilter(ServicePatternException):
""""Exception raised then a user try
to get a ticket for a service and do not reach a condition"""
class UserFieldNotDefined(Exception):
class UserFieldNotDefined(ServicePatternException):
"""Exception raised then a user try to get a ticket for a service
using as username an attribut not present on this user"""
......@@ -27,5 +27,6 @@ urlpatterns = patterns(
url('^p3/serviceValidate$', views.ValidateService.as_view(allow_proxy_ticket=False), name='p3_serviceValidate'),
url('^p3/proxyValidate$', views.ValidateService.as_view(allow_proxy_ticket=True), name='p3_proxyValidate'),
url('^samlValidate$', views.SamlValidate.as_view(), name='samlValidate'),
url('^auth$', views.Auth.as_view(), name='auth'),
......@@ -281,6 +281,47 @@ class LoginView(View, LogoutMixin):
return self.not_authenticated()
class Auth(View):
"""A simple view to validate username/password/service tuple"""
def dispatch(self, request, *args, **kwargs):
"""dispatch requests based on method GET, POST, ..."""
return super(Auth, self).dispatch(request, *args, **kwargs)
def post(request):
"""methode called on GET request on this view"""
username = request.POST.get('username')
password = request.POST.get('password')
service = request.POST.get('service')
if not username or not password or not service:
print "not username or service or password"
return HttpResponse("no\n", content_type="text/plain")
form = forms.UserCredential(
if form.is_valid():
user = models.User.objects.get(username=form.cleaned_data['username'])
# is the service allowed
service_pattern = models.ServicePattern.validate(service)
# is the current user allowed on this service
# if the user has asked to be warned before any login to a service
return HttpResponse("yes\n", content_type="text/plain")
except (models.ServicePattern.DoesNotExist, models.ServicePatternException) as error:
print "error: %r" % error
return HttpResponse("no\n", content_type="text/plain")
print "bad password"
return HttpResponse("no\n", content_type="text/plain")
class Validate(View):
"""service ticket validation"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment