Пример #1
0
def wifi(request):
    if request.user.is_authenticated():
        orgs = participants_models.user_organizations(request.user)
        if orgs:
            return redirect("http://help.kitap.tatar.ru")
    else:
        return redirect("index:frontend:index")
Пример #2
0
def wifi(request):
    ap_mac = request.GET.get('ap_mac', '')
    if request.user.is_authenticated():
        if ap_mac:
            request.session['ap_mac'] = ap_mac
        orgs = participants_models.user_organizations(request.user)
        if orgs:
            return redirect('http://help.kitap.tatar.ru')
    return redirect('index:frontend:index')
Пример #3
0
def wifi(request):
    ap_mac = request.GET.get('ap_mac', '')
    if request.user.is_authenticated():
        if ap_mac:
            request.session['ap_mac'] = ap_mac
        orgs = participants_models.user_organizations(request.user)
        if orgs:
            return redirect('http://help.kitap.tatar.ru')
    return redirect('index:frontend:index')
Пример #4
0
def login(
    request,
    template_name="registration/login.html",
    redirect_field_name=REDIRECT_FIELD_NAME,
    authentication_form=AuthenticationForm,
    current_app=None,
    extra_context=None,
):
    """
    Displays the login form and handles the login action.
    """
    wifi = request.GET.get("wifi", "")
    remote_addr = request.META.get("REMOTE_ADDR", "")
    redirect_to = request.REQUEST.get(redirect_field_name, "")

    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            netloc = urlparse.urlparse(redirect_to)[1]

            # Use default setting if redirect_to is empty
            if not redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Heavier security check -- don't allow redirection to a different
            # host.
            elif netloc and netloc != request.get_host():
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Okay, security checks complete. Log the user in.
            auth_login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            else:
                return HttpResponse(
                    u"У вас не работают cookies. Пожалуйста, включите их в браузере или очистите кеш браузера."
                )

            if request.user.is_authenticated():
                if wifi:
                    username = form.cleaned_data["username"]
                    suffix = "@tatar.ru"
                    if username.endswith(suffix):
                        username = "******" + username.replace(suffix, "")
                    return render(
                        request,
                        "accounts/frontend/to_wifi.html",
                        {"username": username, "password": form.cleaned_data["password"]},
                    )

                orgs = participants_models.user_organizations(request.user)
                if orgs:
                    return redirect("http://help.kitap.tatar.ru")

            return redirect(redirect_to)
    else:
        form = authentication_form(request)

    request.session.set_test_cookie()

    current_site = get_current_site(request)

    context = {"form": form, redirect_field_name: redirect_to, "site": current_site, "site_name": current_site.name}
    if extra_context is not None:
        context.update(extra_context)
    return render(request, template_name, context, current_app=current_app)
Пример #5
0
def login(request, template_name='registration/login.html',
          redirect_field_name=REDIRECT_FIELD_NAME,
          authentication_form=AuthenticationForm,
          current_app=None, extra_context=None):
    """
    Displays the login form and handles the login action.
    """
    ap_mac = request.GET.get('ap_mac', '')
    wifi = request.GET.get('wifi', '')
    remote_addr = request.META.get('REMOTE_ADDR', '')
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            netloc = urlparse.urlparse(redirect_to)[1]

            # Use default setting if redirect_to is empty
            if not redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Heavier security check -- don't allow redirection to a different
            # host.
            elif netloc and netloc != request.get_host():
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Okay, security checks complete. Log the user in.
            auth_login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            else:
                return HttpResponse(
                    u'У вас не работают cookies. Пожалуйста, включите их в браузере или очистите кеш браузера.')

            if request.user.is_authenticated():
                if ap_mac:
                    request.session['ap_mac'] = ap_mac
                    library = participants_models.get_org_by_ap_mac(ap_mac)
                    if library:
                        request.session['org_id'] = library.id
                if wifi:
                    username = form.cleaned_data['username']
                    suffix = '@tatar.ru'
                    if username.endswith(suffix):
                        username = username.replace(suffix, '')
                    # username = u'EDU\\' + username

                    ruslan_user = get_ruslan_user(request)
                    wifi_username = username
                    wifi_password = form.cleaned_data['password']
                    if ruslan_user:
                        wifi_username = ruslan_user.username
                        # wifi_password = ruslan_user.password
                    return render(request, 'accounts/frontend/to_wifi.html', {
                        'username': wifi_username,
                        'password': wifi_password
                    })

                orgs = participants_models.user_organizations(request.user)
                if orgs:
                    return redirect('http://help.kitap.tatar.ru')

            return redirect(redirect_to)
    else:
        form = authentication_form(request)

    request.session.set_test_cookie()

    current_site = get_current_site(request)

    library = None
    if ap_mac:
        library = participants_models.get_org_by_ap_mac(ap_mac)
        if library:
            request.session['org_id'] = library.id
    context = {
        'form': form,
        'library': library,
        redirect_field_name: redirect_to,
        'site': current_site,
        'site_name': current_site.name,
    }
    if extra_context is not None:
        context.update(extra_context)


    return render(request, template_name, context, current_app=current_app)
Пример #6
0
def login(request,
          template_name='registration/login.html',
          redirect_field_name=REDIRECT_FIELD_NAME,
          authentication_form=AuthenticationForm,
          current_app=None,
          extra_context=None):
    """
    Displays the login form and handles the login action.
    """
    ap_mac = request.GET.get('ap_mac', '')
    wifi = request.GET.get('wifi', '')
    remote_addr = request.META.get('REMOTE_ADDR', '')
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            netloc = urlparse.urlparse(redirect_to)[1]

            # Use default setting if redirect_to is empty
            if not redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Heavier security check -- don't allow redirection to a different
            # host.
            elif netloc and netloc != request.get_host():
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Okay, security checks complete. Log the user in.
            auth_login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            else:
                return HttpResponse(
                    u'У вас не работают cookies. Пожалуйста, включите их в браузере или очистите кеш браузера.'
                )

            if request.user.is_authenticated():
                if ap_mac:
                    request.session['ap_mac'] = ap_mac
                    library = participants_models.get_org_by_ap_mac(ap_mac)
                    if library:
                        request.session['org_id'] = library.id
                if wifi:
                    username = form.cleaned_data['username']
                    suffix = '@tatar.ru'
                    if username.endswith(suffix):
                        username = username.replace(suffix, '')
                    # username = u'EDU\\' + username

                    ruslan_user = get_ruslan_user(request)
                    wifi_username = username
                    wifi_password = form.cleaned_data['password']
                    if ruslan_user:
                        wifi_username = ruslan_user.username
                        # wifi_password = ruslan_user.password
                    return render(request, 'accounts/frontend/to_wifi.html', {
                        'username': wifi_username,
                        'password': wifi_password
                    })

                orgs = participants_models.user_organizations(request.user)
                if orgs:
                    return redirect('http://help.kitap.tatar.ru')

            return redirect(redirect_to)
    else:
        form = authentication_form(request)

    request.session.set_test_cookie()

    current_site = get_current_site(request)

    library = None
    if ap_mac:
        library = participants_models.get_org_by_ap_mac(ap_mac)
        if library:
            request.session['org_id'] = library.id
    context = {
        'form': form,
        'library': library,
        redirect_field_name: redirect_to,
        'site': current_site,
        'site_name': current_site.name,
    }
    if extra_context is not None:
        context.update(extra_context)

    return render(request, template_name, context, current_app=current_app)