Example #1
0
def create_user(request, form):
  data = form.cleaned_data
  
  # use an md5 of the email as a username
  m = md5()
  m.update(data["email"])

  # if it's ok, register the user
  user = User.objects.create_user(m.hexdigest()[0:30],
                                  data['email'],
                                  data['password'])

  # set the user's first/last names
  user.first_name = data['first_name']
  user.last_name = data['last_name']

  # save the user
  user.save()

  #Add additional info
  info = UserInfo(user=user, mentor=False)
  info.save()

  #Add email information
  m = EmailAddress(address=data['email'], user=user)
  m.save()

  # search past events for the user's email
  for event in Event.objects.filter(author_email__iexact = user.email,
                                    author = None):
    event.author = user
    event.save()

  # search past events for the user's first and last name
  name = user.get_full_name()
  for event in Event.objects.filter(author_name__iexact = name, author = None):
    event.author = user
    event.save()

  # search contributors for the user's name and email
  for contrib in Contributor.objects.filter(email__iexact = user.email,
                                            user = None):
    contrib.user = user
    contrib.save()

  for contrib in Contributor.objects.filter(name__iexact = name, user = None):
    contrib.user = user
    contrib.save()
  
  # log the user in (since we can't send emails for validation AFAIK)
  user = auth.authenticate(username = user.username,
                           password = data['password'])
  auth.login(request, user)
  
  return HttpResponseRedirect(request.POST['next'])
Example #2
0
 def get_country_user_usernames(api_link, country):
       """Get all the Mozillians username of the country"""
       mozilians = requests.get(api_link).json()
       if mozilians["next"] != None:
          for profile in mozilians["results"]:
              u = UserInfo(username=profile["username"], country=country, url=profile["_url"])
              u.save()
          get_country_user_usernames(mozilians["next"], country)
       else:
          for profile in mozilians["results"]:
              u = UserInfo(username=profile["username"], country=country, url=profile["_url"])
              u.save()
       return "Completed", country