aboutsummaryrefslogtreecommitdiff
path: root/djangopypi/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'djangopypi/views.py')
-rw-r--r--djangopypi/views.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/djangopypi/views.py b/djangopypi/views.py
index 816a170..597598f 100644
--- a/djangopypi/views.py
+++ b/djangopypi/views.py
@@ -10,15 +10,17 @@ from django.conf import settings
10from django.http import Http404, HttpResponse, HttpResponseBadRequest 10from django.http import Http404, HttpResponse, HttpResponseBadRequest
11from django.http import QueryDict, HttpResponseForbidden 11from django.http import QueryDict, HttpResponseForbidden
12from django.shortcuts import render_to_response 12from django.shortcuts import render_to_response
13from djangopypi.models import Project, Classifier, Release, UPLOAD_TO
14from djangopypi.forms import ProjectForm, ReleaseForm
15from django.template import RequestContext 13from django.template import RequestContext
16from django.utils.datastructures import MultiValueDict 14from django.utils.datastructures import MultiValueDict
17from django.utils.translation import ugettext_lazy as _ 15from django.utils.translation import ugettext_lazy as _
18from django.core.files.uploadedfile import SimpleUploadedFile 16from django.core.files.uploadedfile import SimpleUploadedFile
19from django.contrib.auth import authenticate, login 17from django.contrib.auth import authenticate, login
20from djangopypi.http import HttpResponseNotImplemented 18from registration.backends import get_backend
21from djangopypi.http import HttpResponseUnauthorized 19from registration.forms import RegistrationForm
20
21from djangopypi.models import Project, Classifier, Release, UPLOAD_TO
22from djangopypi.forms import ProjectForm, ReleaseForm
23from djangopypi.http import HttpResponseNotImplemented, HttpResponseUnauthorized
22from djangopypi.utils import decode_fs 24from djangopypi.utils import decode_fs
23 25
24 26
@@ -108,12 +110,33 @@ def register_or_upload(request, post_data, files):
108 110
109 return submit_project_or_release(user, post_data, files) 111 return submit_project_or_release(user, post_data, files)
110 112
113def create_user(request, post_data, files):
114 """Create new user from a distutil client request"""
115 form = RegistrationForm({"username": post_data["name"],
116 "email": post_data["email"],
117 "password1": post_data["password"],
118 "password2": post_data["password"]})
119 if not form.is_valid():
120 # Dist Utils requires error msg in HTTP status: "HTTP/1.1 400 msg"
121 # Which is HTTP/WSGI incompatible, so we're just returning a empty 400.
122 return HttpResponseBadRequest()
123
124 backend = get_backend("registration.backends.default.DefaultBackend")
125 if not backend.registration_allowed(request):
126 return HttpResponseBadRequest()
127 new_user = backend.register(request, **form.cleaned_data)
128 return HttpResponse("OK\n", status=200, mimetype='text/plain')
129
130
111ACTIONS = { 131ACTIONS = {
112 # file_upload is the action used with distutils ``sdist`` command. 132 # file_upload is the action used with distutils ``sdist`` command.
113 "file_upload": register_or_upload, 133 "file_upload": register_or_upload,
114 134
115 # submit is the :action used with distutils ``register`` command. 135 # submit is the :action used with distutils ``register`` command.
116 "submit": register_or_upload, 136 "submit": register_or_upload,
137
138 # user is the action used when registering a new user
139 "user": create_user,
117} 140}
118 141
119 142