Esempio n. 1
0
def login(request):
    announcements = Announcement.get_all_enabled_annoucements()
    if not settings.LOGIN_ENABLED:
        # login disabled
        if request.method == 'POST':
            return HttpResponseForbidden()
        else:
            return render_to_response('application/wait.html',
                                      {'announcements': announcements})

    error_messages = []
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            passwd = form.cleaned_data['password']

            national_id = form.cleaned_data['national_id']
            applicants = list(
                Applicant.objects.filter(national_id=national_id).all())
            if len(applicants) != 0:
                applicant = applicants[0]
            else:
                applicant = None

            if applicant != None:
                if applicant.activation_required:
                    email = applicant.email
                    return render_to_response(
                        'application/registration/activation-required.html',
                        {'email': email})
                elif (applicant.check_password(passwd)
                      or (settings.DEBUG and settings.FAKE_LOGIN)
                      or (settings.USE_ADDITIONAL_PASSWORD
                          and applicant.check_additional_password(passwd))):
                    # authenticated

                    if not applicant.has_logged_in:
                        applicant.has_logged_in = True
                        applicant.save()

                    request.session['applicant_id'] = applicant.id

                    return redirect_to_applicant_first_page(applicant)

            from django.forms.util import ErrorList

            form._errors['password'] = ErrorList(['รหัสผ่านผิดพลาด'])
            error_messages.append('รหัสผ่านผิดพลาด')
    else:
        form = LoginForm()

    return render_to_response(
        'application/start.html', {
            'form': form,
            'submission_deadline_passed': submission_deadline_passed(),
            'errors': error_messages,
            'announcements': announcements
        })
Esempio n. 2
0
def login(request):
    announcements = Announcement.get_all_enabled_annoucements()
    if not settings.LOGIN_ENABLED:
        # login disabled
        if request.method == 'POST':
            return HttpResponseForbidden()
        else:
            return render_to_response('application/wait.html',
                                      { 'announcements': announcements })     

    error_messages = []
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            passwd = form.cleaned_data['password']

            national_id = form.cleaned_data['national_id']
            applicants = list(Applicant.objects.filter(national_id=national_id).all())
            if len(applicants)!=0:
                applicant = applicants[0]
            else:
                applicant = None

            if applicant!=None:
                if applicant.activation_required:
                    email = applicant.email
                    return render_to_response(
                        'application/registration/activation-required.html',
                        { 'email': email })
                elif (applicant.check_password(passwd) or
                      (settings.DEBUG and settings.FAKE_LOGIN) or
                      (settings.USE_ADDITIONAL_PASSWORD and
                       applicant.check_additional_password(passwd))):
                    # authenticated

                    if not applicant.has_logged_in:
                        applicant.has_logged_in = True
                        applicant.save()

                    request.session['applicant_id'] = applicant.id
                    
                    return redirect_to_applicant_first_page(applicant)
            
            from django.forms.util import ErrorList

            form._errors['password'] = ErrorList(['รหัสผ่านผิดพลาด'])
            error_messages.append('รหัสผ่านผิดพลาด')
    else:
        form = LoginForm()

    return render_to_response('application/start.html',
                              { 'form': form,
                                'submission_deadline_passed':
                                    submission_deadline_passed(),
                                'errors': error_messages,
                                'announcements': announcements })
Esempio n. 3
0
def redirect_to_first_form():
    if not submission_deadline_passed():
        return HttpResponseRedirect(reverse(FORM_STEPS[0][1]))
    else:
        return redirect_to_deadline_error()
def redirect_to_first_form():
    if not submission_deadline_passed():
        return HttpResponseRedirect(reverse(FORM_STEPS[0][1]))
    else:
        return redirect_to_deadline_error()
Esempio n. 5
0
def index(request):
    if settings.SHOW_CLEARING_HOUSE_RESULT:
        return clearing_index(request)

    if not request.applicant.is_submitted:
        return HttpResponseForbidden()

    if settings.SHOW_ONLY_RESULTS:
        return result_index(request)

    template_data = []

    additional_result = None
    if request.applicant.has_additional_result:
        additional_result = request.applicant.additional_result
        if not additional_result.is_waived:
            return redirect('confirmation-quota-index')

    template_data.append({'additional_result': additional_result})

    STATUS_COMPONENT_FUNCTIONS = [
        prepare_notice,
        prepare_instruction_info,
        prepare_ticket_random_seed,
        prepare_score_request_status,
        ]        

    for f in STATUS_COMPONENT_FUNCTIONS:
        template_data.append(f(request))

    submission_info = request.applicant.submission_info
    applicant = request.applicant

    round_data = prepare_round_data()

    admission_data = (
        prepare_admission_result_data(applicant,
                                      round_data['current_round']))
    confirmation_data = (
        prepare_confirmation_data(applicant, 
                                  admission_data['admitted_major']))

    template_data.append(round_data)
    template_data.append(admission_data)
    template_data.append(confirmation_data)
    template_data.append({
            'exam_scores':
                prepare_exam_scores(request.applicant)})

    core_data = { 'applicant': applicant,
                  'submission_info': submission_info,
                  'can_log_out': True }
    template_data.append(core_data)

    config_data = { 'shows_score_import_status':
                        settings.SHOW_SCORE_IMPORT_STATUS,
                    'submission_deadline_passed':
                        submission_deadline_passed() }
    template_data.append(config_data)

    template_items = []
    for d in template_data:
        template_items += d.items()

    return render_to_response("application/status/index.html",
                              dict(template_items))