- return HttpResponseRedirect('index')
- elif request.method == 'POST': # If the form has been submitted...
- form = NewUserForm(request.POST) # A form bound to the POST data
- if form.is_valid(): # All validation rules pass
- username = form.cleaned_data['username']
- first_name = form.cleaned_data['first_name']
- last_name = form.cleaned_data['last_name']
- password = form.cleaned_data['password']
- cpassword = form.cleaned_data['confirm_password']
- email = form.cleaned_data['email']
- if password == cpassword:
- user = User.objects.create_user(username, email, password)
- user.save()
- user.first_name = first_name
- user.last_name = last_name
- user.save()
- return HttpResponseRedirect('index')
+ return render_to_response('loggedin.html', context_instance=RequestContext(request))
+
+ redirect_to = reverse('index')
+# if 'next' in request.GET:
+# redirect_to = request.GET['next']
+
+ if request.method == 'POST':
+ aform = UserCreationForm(data=request.POST)
+ if aform.is_valid():
+ aform.save()
+ x = authenticate(username=aform.cleaned_data['username'], password=aform.cleaned_data['password1'])
+ login(request, x)
+ return render_to_response('usercreated.html', context_instance=RequestContext(request))
+ else:
+ aform = UserCreationForm()
+
+ return render_to_response('newuser.html', {'aform': aform,}, context_instance=RequestContext(request))
+
+@login_required
+def sandwich_user(request, username):
+ user = User.objects.get(username = username)
+ try:
+ ms = Sandwich.objects.filter(user = user)
+ except Sandwich.DoesNotExist:
+ raise Http404
+ return render_to_response('usersandwiches.html', {'allsandwiches': ms,}, context_instance=RequestContext(request))
+
+@login_required
+def edit_user(request, gusername):
+ guser = User.objects.get(username = gusername)
+ if not request.user.is_authenticated():
+ return HttpResponseRedirect(reverse('login'))
+ elif request.user == guser:
+ if request.method == 'POST': # If the form has been submitted...
+ form = NewUserForm(request.POST) # A form bound to the POST data
+ if form.is_valid():
+ username = request.POST['username']
+ first_name = request.POST['first_name']
+ last_name = request.POST['last_name']
+ password = request.POST['password']
+ cpassword = request.POST['confirmpassword']
+ email = request.POST['email']
+ guser.username = username
+ guser.first_name = first_name
+ guser.last_name = last_name
+ if password != '':
+ guser.set_password(password)
+ guser.email = email
+ guser.save()
+ return render_to_response('userchanged.html', context_instance=RequestContext(request))