Beispiel #1
0
 def process_PUT(self):
     guest = self.request.user
     
     if guest.is_authenticated():
         if guest.username == self.username:
             form = {}
             form['fname'] = self.request.POST.get('first_name', None)
             form['lname'] = self.request.POST.get('last_name', None)
             form['email'] = self.request.POST.get('email', None)
             picture = self.request.FILES.get('pic', None)
             password = self.request.POST.get('password', None)
             cpassword = self.request.POST.get('cpassword', None)
             
             try:
                 DataChecker.check_first_name(form['fname'])
                 DataChecker.check_last_name(form['lname'])
                 DataChecker.check_email(form['email'])
                 
                 guest.first_name = form['fname']
                 guest.last_name = form['lname']
                 guest.email = form['email']
                 
                 if picture is not None:
                     print "picture is not None"
                     guest.pic = picture
                 
                 if DataChecker.defined(password):
                     print "password: %s" % password
                     DataChecker.check_password(password, \
                             cpassword)
                     guest.set_password(password)
                 
                 guest.save()
                 
                 messages.success(self.request, UserMsgs.USER_EDITED)
                 return HttpResponseRedirect('/profile/%s/' % self.username)
             except DataError, error:
                 messages.error(self.request, error.msg)
                 
                 return render_to_response('profile_edit_form.html', \
                         {'guest': guest, 'form': form,}, \
                         context_instance=RequestContext(self.request))
         else:
             return HttpResponseRedirect('/profile/%s/' % self.username)
 def process_POST(self):
     form = {}
     form['uname'] = self.request.POST.get('username', None)
     form['fname'] = self.request.POST.get('first_name', None)
     form['lname'] = self.request.POST.get('last_name', None)
     form['email'] = self.request.POST.get('email', None)
     picture = self.request.FILES.get('pic', None)
     password = self.request.POST.get('password', None)
     cpassword = self.request.POST.get('cpassword', None)
     
     try:
         DataChecker.check_username(form['uname'])
         DataChecker.user_exists(form['uname'])
         DataChecker.check_first_name(form['fname'])
         DataChecker.check_last_name(form['lname'])
         DataChecker.check_email(form['email'])
         DataChecker.check_password(password, cpassword)
         
         user = Profile()
         user.username = form['uname']
         user.first_name = form['fname']
         user.last_name = form['lname']
         user.email = form['email']
         user.set_password(password)
         
         if picture:
             user.pic = picture
         
         user.save()
         
         # User is logged in without typing again its data
         user = authenticate(username=form['uname'], password=password)
         login(self.request, user)
         
         messages.success(self.request, UserMsgs.USER_CREATED)
         return HttpResponseRedirect('/profile/%s/' % user.username)
     except DataError, error:
         messages.error(self.request, error.msg)
         
         return render_to_response('profile_creation_form.html', \
                 {'form': form,}, \
                 context_instance=RequestContext(self.request))