diff options
Diffstat (limited to 'djangopypi/views.py')
-rw-r--r-- | djangopypi/views.py | 31 |
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 | |||
10 | from django.http import Http404, HttpResponse, HttpResponseBadRequest | 10 | from django.http import Http404, HttpResponse, HttpResponseBadRequest |
11 | from django.http import QueryDict, HttpResponseForbidden | 11 | from django.http import QueryDict, HttpResponseForbidden |
12 | from django.shortcuts import render_to_response | 12 | from django.shortcuts import render_to_response |
13 | from djangopypi.models import Project, Classifier, Release, UPLOAD_TO | ||
14 | from djangopypi.forms import ProjectForm, ReleaseForm | ||
15 | from django.template import RequestContext | 13 | from django.template import RequestContext |
16 | from django.utils.datastructures import MultiValueDict | 14 | from django.utils.datastructures import MultiValueDict |
17 | from django.utils.translation import ugettext_lazy as _ | 15 | from django.utils.translation import ugettext_lazy as _ |
18 | from django.core.files.uploadedfile import SimpleUploadedFile | 16 | from django.core.files.uploadedfile import SimpleUploadedFile |
19 | from django.contrib.auth import authenticate, login | 17 | from django.contrib.auth import authenticate, login |
20 | from djangopypi.http import HttpResponseNotImplemented | 18 | from registration.backends import get_backend |
21 | from djangopypi.http import HttpResponseUnauthorized | 19 | from registration.forms import RegistrationForm |
20 | |||
21 | from djangopypi.models import Project, Classifier, Release, UPLOAD_TO | ||
22 | from djangopypi.forms import ProjectForm, ReleaseForm | ||
23 | from djangopypi.http import HttpResponseNotImplemented, HttpResponseUnauthorized | ||
22 | from djangopypi.utils import decode_fs | 24 | from 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 | ||
113 | def 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 | |||
111 | ACTIONS = { | 131 | ACTIONS = { |
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 | ||