示例#1
0
    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)
示例#2
0
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
    mafiasi.email = '{}@{}'.format(username, settings.MAILCLOAK_DOMAIN)
    mafiasi.real_email = email
    mafiasi.yeargroup = yeargroup
    mafiasi.is_guest = is_guest
    if account:
        mafiasi.account = account

    return mafiasi
示例#3
0
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
示例#4
0
    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 + u'@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)
示例#5
0
文件: views.py 项目: gnomus/mafiasi
def create_account(request, info_token):
    if request.user.is_authenticated():
        return redirect('dashboard_index')

    try:
        info = signing.loads(info_token, max_age=TOKEN_MAX_AGE)
    except signing.SignatureExpired:
        return TemplateResponse(request, 'registration/token_expired.html')
    except signing.BadSignature:
        return TemplateResponse(request, 'registration/token_invalid.html')

    yeargroup = Yeargroup.objects.get(pk=info['yeargroup_pk'])
    if info['account'][0].isdigit():
        username = yeargroup.slug[2] + info['account']
    else:
        username = info['account']

    if Mafiasi.objects.filter(username=username).count():
        return redirect('login')

    if request.method == 'POST':
        form = PasswordForm(request.POST)
        if form.is_valid():
            mafiasi = Mafiasi(username=username)
            mafiasi.set_password(form.cleaned_data['password1'])
            first_name = info.get('first_name')
            last_name = info.get('last_name')
            yeargroup = Yeargroup.objects.get(pk=info['yeargroup_pk'])
            if first_name and last_name:
                mafiasi.first_name = first_name
                mafiasi.last_name = last_name
            else:
                try:
                    passwd = PasswdEntry.objects.get(username=info['account'])
                    name_parsed = HumanName(passwd.full_name)
                    mafiasi.first_name = name_parsed.first
                    mafiasi.last_name = name_parsed.last
                except PasswdEntry.DoesNotExist:
                    # This happens only when someone removed an entry
                    # from our passwd database manually
                    pass
            mafiasi.account = info['account']
            mafiasi.email = u'{0}@{1}'.format(info['account'],
                                              settings.EMAIL_DOMAIN)
            mafiasi.yeargroup = yeargroup
            mafiasi.save()
            mafiasi.backend='django.contrib.auth.backends.ModelBackend'
            login(request, mafiasi)
            return redirect('dashboard_index')
    else:
        form = PasswordForm()

    return TemplateResponse(request, 'registration/create_account.html', {
        'form': form,
        'username': username
    })