Пример #1
0
def lookup_submit(request):
    '''
        this method handles the form submission for a username lookup.
    '''
    #has_permission(request)

    #if the user submitted the form
    if request.method == "POST":
        username = request.POST['username'].strip()

        '''THIS SECTION VALIDATES THE USERNAME,
        RETURNS ERROR PAGES IF NOT VALID.'''
        if not username.startswith('pdx'):
            return render_to_response(
                'error.html',
                {'error_msg': 'the username: {0} doesn\'t'.format(username) + \
                    ' start with "pdx".<br/><br/>If its not a sponsored' + \
                    ' account, the ticket should go to unix team'},
            )

        else:
            try:
                int(username[3:])
            except:
                return render_to_response(
                    'error.html',
                    {'error_msg': 'The username: {0}'.format(username) + \
                        ' doesn\'t end with a number<br/><br/>If its not' + \
                        ' a sponsored account, the ticket should go to' + \
                        ' unix-team'},
                )

        print "looking up username: {0}".format(username) #debug

        '''DO THE LDAP LOOKUP HERE'''
        search_obj = search(
            'uid={0}'.format(username),
            {'basedn':'dc=pdx,dc=edu'},
            my_creds,
        )

        if search_obj[1] == []:
            return render_to_response(
                'error.html',
                {'error_msg': "no matching record for {0}".format(username)},)
        else:
            try:
                user_dn = search_obj[1][0][0]
                user_cn = search_obj[1][0][1]['cn'][0]
                current_expire_date = search_obj[1][0][1]\
                    ['psuAccountExpireDate'][0]
                account_status = search_obj[1][0][1]\
                    ['psuUnixAccountStatus'][0]

                '''THIS ERROR WILL SHOW WHEN THERE
                AREN'T THE ABOVE NECESSARY PARTS'''
            except Exception as e:
                render_to_response(
                    'error.html',
                    {'error_msg': str(e)},
                )
        print 'account_status: {0}'.format(account_status)
        if account_status.strip() == 'active':
            print 'active'
            account_status = True
        else:
            print 'not active'
            account_status = False
        print 'account_status: {0}'.format(account_status)

        expire_format = current_expire_date[4:6] + '/' + \
            current_expire_date[6:8] + '/' + \
            current_expire_date[0:4]
 
        '''OTHERWISE, RENDER THE EXTENSION FORM.'''
        this_extension_form = extension_form(initial={"custom_extend":""})

        return render_to_response(
            'extend.html',
            {'extension_form':     this_extension_form,
            'username':            username,
            'dn':                  user_dn,
            'user_cn':             user_cn,
            'expire_format':       expire_format,
            'account_status':      account_status,
            'current_expire_date': current_expire_date},
            context_instance= RequestContext(request)
        )

    #if the user didn't submit the form, take them back to the initial page.
    else:
        blank_lookup_form(request)
Пример #2
0
            current_expire_date[6:8] + '/' + \
            current_expire_date[0:4]

        return render_to_response(
            'result.html',
            {'user_dn':           user_dn,
            'user_cn':            user_cn,
            'username':           username,
            'expire_format':      expire_format,
            'account_reset_info': account_reset_errors},
            context_instance = RequestContext(request),
        )

    #if form wasn't submitted, then take the user to the original page
    else:
        this_extension_form = extension_form(initial={"custom_extend":""})
        return render_to_response(
            'extend.html', 
            {"extension_form":this_extension_form,
                "username":username},
            context_instance = RequestContext(request),
        )

@login_required
def results(request):
    '''
        this method displays the results of the extension.
    '''
    #has_permission(request)
    return render_to_response(
        'result.html',