def _create_account(self, jabber_user, username, account): try: passwd = PasswdEntry.objects.get(username=account) name = HumanName(passwd.full_name) first_name = name.first last_name = name.last try: yeargroup = Yeargroup.objects.get(gid=passwd.gid) except Yeargroup.DoesNotExist: yeargroup = None except PasswdEntry.DoesNotExist: first_name = None last_name = None yeargroup = None if yeargroup is None: if username.startswith('x'): slug = 'jx' else: slug = 'j20' + username[:2] try: yeargroup = Yeargroup.objects.get(slug=slug) except Yeargroup.DoesNotExist: raise CommandError('No such yeargroup: ' + slug) mafiasi = Mafiasi(username=username, account=account, yeargroup=yeargroup) if first_name and last_name: mafiasi.first_name = first_name mafiasi.last_name = last_name mafiasi.email = account + '@informatik.uni-hamburg.de' mafiasi.set_password(jabber_user.password) print('Create account', username) print(' Account:', account) print(' Yeargroup:', yeargroup) print(' Name:', mafiasi.first_name, mafiasi.last_name) print('--') mafiasi.save() JabberUserMapping.objects.create(mafiasi_user_id=mafiasi.pk, jabber_user=jabber_user)
def create_mafiasi_account(username, email, first_name, last_name, account=None, yeargroup=None, is_student=False, is_guest=False): mafiasi = Mafiasi(username=username) if first_name and last_name: mafiasi.first_name = first_name mafiasi.last_name = last_name if settings.MAILCLOAK_DOMAIN: mafiasi.email = '{}@{}'.format(username, settings.MAILCLOAK_DOMAIN) else: mafiasi.email = email mafiasi.real_email = email mafiasi.yeargroup = yeargroup mafiasi.is_guest = is_guest if account: mafiasi.account = account return mafiasi