summaryrefslogtreecommitdiff
path: root/devel/views.py
diff options
context:
space:
mode:
authorDusty Phillips <buchuki@gmail.com>2009-08-10 15:47:02 -0400
committerDusty Phillips <buchuki@gmail.com>2009-08-10 15:47:02 -0400
commit0d2560fa55689d920bc7431fae3f2995bd1b0d71 (patch)
tree98db0e069181ba75133ab7340732d3f9b0e592f3 /devel/views.py
parentc3ecb485ae3eca5ba6dca96a22615dc11c6df7ee (diff)
Add a page to aid Aaron in user creation.
Diffstat (limited to 'devel/views.py')
-rw-r--r--devel/views.py53
1 files changed, 52 insertions, 1 deletions
diff --git a/devel/views.py b/devel/views.py
index 5e5e9c40..16867346 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -6,6 +6,10 @@ from django.template import RequestContext
from archweb_dev.main.models import Package, Todolist
from archweb_dev.main.models import Arch, Repo
from archweb_dev.main.models import UserProfile, News
+import random
+from string import letters, digits
+pwletters = letters + digits
+
def index(request):
'''the Developer dashboard'''
@@ -68,5 +72,52 @@ def siteindex(request):
RequestContext(request,
{'news_updates': news, 'pkg_updates': pkgs, 'repos': repos}))
-# vim: set ts=4 sw=4 et:
+class NewUserForm(forms.ModelForm):
+ class Meta:
+ model = UserProfile
+ exclude = ('picture', 'user')
+ username = forms.CharField(max_length=30)
+ email = forms.EmailField()
+ first_name = forms.CharField(required=False)
+ last_name = forms.CharField(required=False)
+
+ def save(self):
+ profile = forms.ModelForm.save(self, False)
+ pw = ''.join([random.choice(pwletters) for i in xrange(8)])
+ user = User.objects.create(username=self.cleaned_data['username'],
+ email=self.cleaned_data['email'], password=pw)
+ user.first_name = self.cleaned_data['first_name']
+ user.last_name = self.cleaned_data['last_name']
+ user.save()
+ profile.user = user
+ profile.save()
+
+ send_mail("Your new archweb account",
+ """You can now log into:
+http://dev.archlinux.org/
+with these login details:
+Username: %s
+Password: %s""" % (user.username, pw),
+ 'Arch Website Notification <nobody@archlinux.org>',
+ [user.email],
+ fail_silently=False)
+
+def new_user_form(request):
+ if not request.user.is_superuser:
+ return HttpResponseRedirect('/login/')
+ if request.POST:
+ form = NewUserForm(request.POST)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect('/admin/')
+ else:
+ form = NewUserForm()
+ return render_to_response('general_form.html', RequestContext(
+ request, {'description': '''A new user will be created with the
+ following properties in their profile. A random password will be
+ generated and the user will be e-mailed with their account details
+ n plaintext.''',
+ 'form': form, 'title': 'Create User', 'submit_text': 'Create User'}))
+
+# vim: set ts=4 sw=4 et: