def profile_page(request, view_user): if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('forum.views.main_index',)) else: if request.user.username == view_user: if request.method == 'POST': #print request.FILES form_profile = ProfileUpdate(request.POST, request.FILES) if form_profile.is_valid(): # process data cd = form_profile.cleaned_data user_update = ForumUser.objects.get(user=request.user) success_reply = [] if request.FILES: f = request.FILES['avatar_img'] destination = open('%s/avatars/%s' % (settings.MEDIA_ROOT, f.name), 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() user_update.avatar_img = "avatars/%s" % f.name user_update.save() # uploadedImage = cd['avatar_img'] # user_update = (request.FILES) if(cd['password1']): user_update.user.set_password(cd['password1']) user_update.user.save() success_reply.append('Password') if(cd['email1'] != user_update.user.email and cd['email1'] != ''): user_update.user.email = cd['email1'] user_update.user.save() success_reply.append('Email') return render_to_response('profile_page.html', {'form_profile' : form_profile, 'success_reply': success_reply, 'forum_user': user_update, 'site_root': reverse('forum.views.main_index'), }, context_instance=RequestContext(request)) else: default_data = { 'email1': request.user.email, 'email2': request.user.email, } form_profile = ProfileUpdate(default_data) try: forum_user = ForumUser.objects.get(user=request.user) except: forum_user = ForumUser(user=request.user) forum_user.save() return render_to_response('profile_page.html', {'form_profile' : form_profile, 'forum_user' : forum_user, 'site_root': reverse('forum.views.main_index',),}, context_instance=RequestContext(request)) else: return HttpResponseRedirect(reverse('forum.views.main_index',))
def register_view(request): if request.user.is_authenticated(): # send them to the main page if already logged in return HttpResponseRedirect(reverse('forum.views.main_index',)) else: # do work in here if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data new_user = User.objects.create_user(cd['username'], cd['email1'], cd['password1']) new_user.save() forum_user = ForumUser(user=new_user) forum_user.save() # automatically log them in... user = authenticate(username=cd['username'], password=cd['password1']) if user.is_active: # login equals great success login(request, user) return HttpResponseRedirect(reverse('forum.views.main_index',)) else: # account is disabled # ADD: message that it is disabled return HttpResponseRedirect(reverse('forum.views.login_page',)) # end automatically log them in... #request.user.message_set.create(message="Welcome to the forum %s!" % (cd['username'],)) return HttpResponseRedirect(reverse('forum.views.main_index',)) else: # the for is not valid form = RegisterForm(request.POST) return render_to_response('register.html', {'form': form, 'site_root': reverse('forum.views.main_index'),}, context_instance=RequestContext(request)) else: form = RegisterForm() return render_to_response('register.html', {'form': form, 'site_root': reverse('forum.views.main_index'),}, context_instance=RequestContext(request))