Ejemplo n.º 1
0
def now(request):
    WZ = Z.SetWhoZwho(request)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid(): 
            check_captcha = captcha.submit (form.cleaned_data['recaptcha_challenge_field'], form.cleaned_data['recaptcha_response_field'], WZ['CaptchaPrivate'], "127.0.0.1")
            if not check_captcha.is_valid:
                WZ['ErrorMessage'] = "[UR01]: Captcha response was incorrect."
            else:
                users = User.objects.all().filter(username__exact=form.cleaned_data['login_id'])
                if len(users) < 1:
                    new_user = User()
                    new_user.username = form.cleaned_data['login_id']
                    new_user.first_name = form.cleaned_data['first_name']
                    new_user.last_name = form.cleaned_data['last_name']
                    new_user.email = form.cleaned_data['email']
                    new_user.set_password(form.cleaned_data['password'])
                    new_user.save()

                    new_name = Name()
                    new_name.preferred = form.cleaned_data['first_name']
                    new_name.first = form.cleaned_data['first_name']
                    new_name.last = form.cleaned_data['last_name']
                    new_name.authority = Z.NewRW
                    new_name.user = new_user
                    new_name.save()

                    new_name.owner = new_name.id
                    new_name.save()

                    auth_user = authenticate(username=new_user, password=form.cleaned_data['password'])
                    if auth_user is not None:
                        if auth_user.is_active:
                            login(request, auth_user)
                            WZ['Authenticated'] = 1
                            request.session['last_time'] = time()
                            WZ = Z.SetWhoZwho(request, '.')
                            return HttpResponseRedirect('/WhoZwho/' + WZ['Tabs'][WZ['ActiveTab']][3])
                        else:
                            WZ['ErrorMessage'] = "[UR02]: Login ID disabled."
                    else:
                        WZ['ErrorMessage'] = "[UR03]: Login ID is invalid."
                else:
                    WZ['ErrorMessage'] = "[UR04]: The selected Login ID is already in use."
        else:
            WZ['ErrorMessage'] = str(form.errors)
    else:
        form = RegistrationForm() # An unbound form

    captcha_html = captcha.displayhtml(WZ['CaptchaPublic'], use_ssl = True)

    c = { 'form': form, 'WZ': WZ, 'captcha_html': captcha_html }
    c.update(csrf(request))
    return render_to_response('UserRegistration.html', c )
Ejemplo n.º 2
0
def do(request, nid, browser_tab):
    WZ = Z.SetWhoZwho(request, browser_tab)
    if WZ['ErrorMessage']:
        return GoLogout(request, WZ)

    if nid != '0':
        try:
            name = Name.objects.get(pk=int(nid))
        except:
            return GoLogout(request, WZ, "[PC01]: URL containd an invalid name ID.")

        if WZ['Authority'] < Z.Admin and name.owner != WZ['AuthorizedOwner']:
            return GoLogout(request, WZ, "[PC02]: URL containd an invalid name ID.")

        if WZ['Authority'] >= Z.Admin:
            WZ['AuthorizedOwner'] = name.owner

    if request.method == 'POST': # If the form has been submitted...
        form = DirectoryEditPCForm(request.POST, request.FILES)
        if form.is_valid():
            if nid == '0':
                try:
                    name = Name.objects.get(pk=int(WZ['Nid']))
                except:
                    return GoLogout(request, WZ, "[PC03]: Invalid name ID.")

                new_user = User()
                new_user.username = '******' + str(time.time())
                new_user.first_name = form.cleaned_data['first']
                new_user.last_name = form.cleaned_data['last']
                new_user.email = name.user.email
                new_user.save()

                new_name = Name()
                new_name.user = new_user
                new_name.approved = True
                new_name.authority = Z.NewRO
                new_name.private = True
                new_name.owner = name.owner

                new_name.first = form.cleaned_data['first']
                new_name.last = form.cleaned_data['last']
                new_name.email = form.cleaned_data['email']
                new_name.cell = form.cleaned_data['cell']
                new_name.work_email = form.cleaned_data['work_email']
                new_name.work_phone = form.cleaned_data['work_phone']
                new_name.birthday = form.cleaned_data['birthday']
                new_name.title = form.cleaned_data['title']
                new_name.gender = form.cleaned_data['gender']
                new_name.save()
                new_name.save()
            else:
                name.first = form.cleaned_data['first']
                name.last = form.cleaned_data['last']
                name.email = form.cleaned_data['email']
                name.cell = form.cleaned_data['cell']
                name.work_email = form.cleaned_data['work_email']
                name.work_phone = form.cleaned_data['work_phone']
                name.birthday = form.cleaned_data['birthday']
                name.title = form.cleaned_data['title']
                name.gender = form.cleaned_data['gender']
                name.save()

            logger.info(WZ['User'] + ' PC ' + str(request.POST))

            if WZ['ErrorMessage'] == "":
                if WZ['Authority'] >= Z.Admin:
                    return HttpResponseRedirect('/WhoZwho/aelst')
                else:
                    return HttpResponseRedirect('/WhoZwho/delst')
        else:
            WZ['ErrorMessage'] = str(form.errors)
    else:
        if nid == '0':
            form = DirectoryEditPCForm()
            edit_pc_title = 'Add a New Personal Contact'
            addresses = []
            name = None
            schoices = []
            spouse = []
        else:
            form = DirectoryEditPCForm(initial={
                'first': name.first,
                'last': name.last,
                'email': name.email,
                'cell': name.cell,
                'work_email': name.work_email,
                'work_phone': name.work_phone,
                'birthday': name.birthday,
                'title': name.title,
                'gender': name.gender
                }) 

            addresses = Address.objects.all(). \
                filter(owner__exact=WZ['AuthorizedOwner']). \
                order_by('street')

            if name.wedding:
                spouse = name.wedding.name_set.all(). \
                    exclude(id__exact=name.id)
                schoices = []
            else:
                spouse = []
                schoices = Name.objects.all(). \
                    filter(owner__exact=WZ['AuthorizedOwner']). \
                    filter(wedding__exact=None). \
                    exclude(gender__exact=name.gender). \
                    exclude(id__exact=name.id). \
                    order_by('first')

            edit_pc_title = 'Edit Personal Contact: ' + name.first + ' ' + name.last


        context = {
            'EditPCTitle': edit_pc_title,
            'Admin': Z.Admin,
            'addresses': addresses,
            'browser_tab': WZ['Tabs'][WZ['ActiveTab']][2],
            'form': form,
            'name': name,
            'nid': nid,
            'picture': WZ['httpURL'] + 'static/pics/defaults/greyman.gif',
            'spouse': spouse,
            'schoices': schoices,
            'WZ': WZ
            }

        context.update(csrf(request))
        return render_to_response('DirectoryEditPC.html', context )
Ejemplo n.º 3
0
def do(request, nid, browser_tab):
    WZ = Z.SetWhoZwho(request, browser_tab)
    if WZ['ErrorMessage']:
        return GoLogout(request, WZ)

    if nid != '0':
        try:
            name = Name.objects.get(pk=int(nid))
        except:
            return GoLogout(request, WZ, "[AN01]: URL containd an invalid name ID.")

        if WZ['Authority'] < Z.Admin and name.owner != WZ['AuthorizedOwner']:
            return GoLogout(request, WZ, "[AN02]: URL containd an invalid name ID.")

    if request.method == 'POST': # If the form has been submitted...
        form = DirectoryAddNameForm(request.POST, request.FILES)
        if form.is_valid():
            users = User.objects.all().filter(username__exact=form.cleaned_data['login_id'])
            if len(users) < 1:
                temporary_password = GenerateTemporaryPassword()

                new_user = User()
                new_user.username = form.cleaned_data['login_id']
                new_user.first_name = form.cleaned_data['first_name']
                new_user.last_name = form.cleaned_data['last_name']
                new_user.email = form.cleaned_data['email']
                new_user.set_password(temporary_password)
                new_user.save()

                new_name = Name()
                new_name.user = new_user
                new_name.first = form.cleaned_data['first_name']
                new_name.last = form.cleaned_data['last_name']

                if form.cleaned_data['privileges'] == '1':
                    new_name.authority = Z.NewRO
                else:
                    new_name.authority = Z.NewRW

                if nid != '0':
                    new_name.owner = name.owner

                new_name.save()

                if nid == '0':
                    new_name.owner = new_name.id
                    new_name.save()

                logger.info(WZ['User'] + ' AN ' + str(request.POST))

                send_mail(
                    'Your new WhoZwho directory account.',
                    'A new account, ' + new_user.username + \
                    ', has been created for you on the WhoZwho directory. ' + \
                    'To obtain a password, visit ' + WZ['httpURL'] + '/fgpwd.',
                    WZ['AdminEmail'],
                    [new_user.email],
                    fail_silently=False)

                return HttpResponseRedirect('/WhoZwho/ename/' + str(new_name.id) + '/' + browser_tab)
            else:
                WZ['ErrorMessage'] = "Error: The selected Login ID is already in use."
        else:
            WZ['ErrorMessage'] = str(form.errors)
    else:
        form = DirectoryAddNameForm(initial={
            'privileges': str(Z.NewRW),
            }) 

    if nid == '0':
        AddNameTitle = 'Add a New Name'
    else:
        AddNameTitle = 'Add a New Family Member'

    context = {
        'AddNameTitle': AddNameTitle,
        'browser_tab': WZ['Tabs'][WZ['ActiveTab']][2],
        'form': form,
        'nid': nid,
        'WZ': WZ
        }

    context.update(csrf(request))
    return render_to_response('DirectoryAddName.html', context )