old_contents: import os
  import json
  import binascii
  import subprocess
  
  from django.http import HttpResponseRedirect
  from django.core.urlresolvers import reverse
  from django.shortcuts import render
  from django.contrib.auth import login
  from django.contrib.auth.decorators import login_required
  from starbowmodweb.user.forms import RegistrationForm
  from starbowmodweb.user.models import User
  from django.conf import settings
  
  
  def create_forum_account(user, password):
      """ Takes email address and username; returns a uid """
      if settings.MYBB_BRIDGE_PATH:
          cmd = ['php', settings.MYBB_BRIDGE_PATH, user.email, user.username, password]
          output = subprocess.check_output(cmd)
          data = json.loads(output.decode('utf8'))
          if data['status'] == 'failure':
              # Alert the administrators
              return None
          else:
              profile = user.profile
              profile.mybb_uid = data['data']['uid']
              profile.mybb_loginkey = data['data']['loginkey']
              profile.save()
  
  
  def user_register(request):
      if request.method == 'POST':
          form = RegistrationForm(request.POST)
          if form.is_valid():
              username = form.cleaned_data['username']
              email = form.cleaned_data['email']
              password = binascii.b2a_hex(os.urandom(15))
              user = User.objects.create_user(username, email, password)
              create_forum_account(user, password)
              return render(request, 'register_success.html', dict(email=email, username=username))
      else:
          form = RegistrationForm()
  
      return render(request, 'register.html', dict(form=form))
  
  
  @login_required
  def user_home(request):
      return render(request, 'home.html')
  
new_contents: import os
  import json
  import binascii
  import subprocess
  
  from django.shortcuts import render
  from django.contrib.auth.decorators import login_required
  from starbowmodweb.user.forms import RegistrationForm
  from starbowmodweb.user.models import User
  from django.conf import settings
  from django.db import transaction
  
  # import the logging library
  import logging
  
  # Get an instance of a logger
  logger = logging.getLogger(__name__)
  
  
  class MyBBError(Exception):
      pass
  
  
  def create_forum_account(user, password):
      """ Takes email address and username; returns a uid """
      if settings.MYBB_BRIDGE_PATH:
          cmd = ['php', settings.MYBB_BRIDGE_PATH, user.email, user.username, password]
          output = subprocess.check_output(cmd)
          return json.loads(output.decode('utf8'))
  
  
  def user_register(request):
      if request.method == 'POST':
          form = RegistrationForm(request.POST)
          if form.is_valid():
              username = form.cleaned_data['username']
              email = form.cleaned_data['email']
              password = binascii.b2a_hex(os.urandom(15))
  
              try:
                  with transaction.atomic():
                      user = User.objects.create_user(username, email, password)
                      forum_data = create_forum_account(user, password)
                      if forum_data['status'] == 'failure':
                          raise MyBBError(forum_data['data'])
                      else:
                          profile = user.profile
                          profile.mybb_uid = forum_data['data']['uid']
                          profile.mybb_loginkey = forum_data['data']['loginkey']
                          profile.save()
                          return render(request, 'register_success.html', dict(
                              email=email,
                              username=username
                          ))
              except MyBBError as e:
                  # Alert the administrators
                  logger.error("MyBB account creation failure: {}".format(e))
                  return render(request, 'reqister_failure.html', dict(
                      email=email,
                      username=username,
                      messages=str(e),
                  ))
  
      else:
          form = RegistrationForm()
  
      return render(request, 'register.html', dict(form=form))
  
  
  @login_required
  def user_home(request):
      return render(request, 'home.html')
  
subject: Use transaction and catch forum account errors.