bgneal@347: import datetime
bgneal@347: import logging
bgneal@347: 
bgneal@347: from django.contrib.auth.models import User
bgneal@347: 
bgneal@347: 
bgneal@347: def create_new_user(pending_user, ip=None, admin_activation=False):
bgneal@347:     """
bgneal@347:     This function contains the code to create a new user from a
bgneal@347:     pending user. The pending user is deleted and the new user
bgneal@347:     is saved. A log message is produced. If admin_activation is false,
bgneal@347:     then ip should be the user's IP they confirmed from, if available.
bgneal@347: 
bgneal@347:     """
bgneal@347:     new_user = User()
bgneal@347: 
bgneal@347:     new_user.username = pending_user.username
bgneal@347:     new_user.first_name = ''
bgneal@347:     new_user.last_name = ''
bgneal@347:     new_user.email = pending_user.email
bgneal@347:     new_user.password = pending_user.password     # already been hashed
bgneal@347:     new_user.is_staff = False
bgneal@347:     new_user.is_active = True
bgneal@347:     new_user.is_superuser = False
bgneal@347:     new_user.last_login = datetime.datetime.now()
bgneal@347:     new_user.date_joined = new_user.last_login
bgneal@347: 
bgneal@347:     new_user.save()
bgneal@347:     pending_user.delete()
bgneal@347: 
bgneal@347:     if admin_activation:
bgneal@347:         msg = 'Accounts registration confirmed by ADMIN for %s' % new_user.username
bgneal@347:     else:
bgneal@347:         msg = 'Accounts registration confirmed by USER for %s from %s' % (
bgneal@347:                 new_user.username, ip)
bgneal@347: 
bgneal@347:     logging.info(msg)