Ejemplo n.º 1
0
def login(request):
    next = request.GET['next'] if 'next' in request.GET.keys() else ''
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request,
                           user,
                           backend='django.contrib.auth.backends.ModelBackend')
                if 'next' in request.POST.keys():
                    return HttpResponseRedirect(request.POST['next'])
                else:
                    return HttpResponseRedirect(reverse('main:arm_list'))
    else:
        form = UserLoginForm()

    context = {
        'title': 'вход в систему',
        'form': form,
        'next': next,
    }
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 2
0
def login(request):
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)

        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']

            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(reverse('main'))

    else:
        form = UserLoginForm()

    context = {
        'title': 'авторизация',
        'style_link': 'css/auth.css',
        'script_link': 'js/auth.js',

        'form': form
    }

    return render(request, 'authapp/login.html', context)
Ejemplo n.º 3
0
def login(request):
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)

            if user and user.is_active:
                auth.login(request, user)
                messages.error(request, 'Ваш акаунт активен!!!')
                return HttpResponseRedirect(reverse('main'))
            else:
                context = {'form': form}
                messages.error(request, 'Ваш акаунт не активен!!!')
                return render(request, 'authapp/login.html', context)
        else:
            context = {'form': form}
            messages.error(request, 'Неверные данные для входа в систему.')
            return render(request, 'authapp/login.html', context)

    else:
        form = UserLoginForm()
    context = {'form': form}
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 4
0
def login(request):
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(reverse('index'))
    else:
        form = UserLoginForm()
    context = {'form': form}
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 5
0
def login(request):
    title = 'Вход'
    login_form = UserLoginForm(data=request.POST)

    if request.method == 'POST' and login_form.is_valid():
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)
            return HttpResponseRedirect(reverse('mainapp:index'))

    context = {'title': title, 'login_form': login_form}
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 6
0
def login(request):
    login_form = UserLoginForm(data=request.POST)
    if request.method == 'POST' and login_form.is_valid():
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)
            return HttpResponseRedirect(reverse('index'))

    context = {'login_form': login_form}
    context.update(main_menu_generate(MainMenu.objects.all()))
    return render(request, 'libapp/index.html', context)
Ejemplo n.º 7
0
def login(request):
    title = "Log in"

    login_form = UserLoginForm(data=request.POST or None)
    if request.method == "POST" and login_form.is_valid():
        username = request.POST["username"]
        password = request.POST["password"]
        user = auth.authenticate(username=username,password=password)
        if user and user.is_active:
            auth.login(request, user)
            return HttpResponseRedirect(reverse("main:index"))

    context = {"title": title, "login_form": login_form}
    return render(request, "authapp/login.html", context)
Ejemplo n.º 8
0
def login(request):
    if request.method == "POST":
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST["username"]
            password = request.POST["password"]
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(reverse("main"))
    else:
        form = UserLoginForm()
    context = {"form": form}
    return render(request, "authapp/login.html", context)
Ejemplo n.º 9
0
def login(request):
    title = 'Login'

    login_form = UserLoginForm(data=request.POST or None).as_p()
    next = request.GET['next'] if 'next' in request.GET.keys() else ''

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)
            if 'next' in request.POST.keys():
                return HttpResponseRedirect(request.POST['next'])
            return HttpResponseRedirect(reverse('main:index'))

    context = {
        'title': title,
        'body_class': 'authform',
        'login_form': login_form,
        'next': next,
        'vk_link': vk_auth_link
    }

    if 'auth_email' in request.session:
        if request.session['auth_email'] == 'sent':
            context[
                'msg'] = 'Вам на e-mail отправлено сообщение с кодом активации'
        elif request.session['auth_email'] == 'not sent':
            context[
                'msg'] = 'Сообщение с кодом активации на e-mail отправить не удалось'

    return render(request, 'authapp/login.html', context)
Ejemplo n.º 10
0
def login(request):
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request, user)
                print('LOGIN OK')
                return HttpResponseRedirect(reverse('mainapp:index'))

    form = UserLoginForm()
    context = {
        'form': form
        # 'year': date.year,
        # 'device': device,
    }
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 11
0
def login(request):
    title = 'Вход'

    login_form = UserLoginForm(data=request.POST)
    if request.method == 'POST' and login_form.is_valid():
        username = request.POST['username']
        password = request.POST['password']
        # print(login_form.cleaned_data)

        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)

        else:
            messages.error(request, 'Invalid username/password!')

        return HttpResponseRedirect(reverse('index'))

    else:
        context = {'login_form': login_form, 'title': title}
        return render(request, 'authapp/login.html', context=context)
Ejemplo n.º 12
0
def login(request):
    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(reverse('index'))
        else:
            print(form.errors)
    else:
        form = UserLoginForm()
    context = {
        'form': form,
        'title': 'GeekShop - Авторизация',
        'title_2': 'Авторизация',
        'container_class': 'col-lg-5'
    }
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 13
0
def login(request):
    # форму заполняем данными полученными с сайта POST

    if request.method == 'POST':
        form = UserLoginForm(data=request.POST)  # Объявили форму и метод
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            # Здесь мы проверяем и проводим авторизацию, если все правильно то
            # Отправляем на главную страницу
            user = auth.authenticate(username=username, password=password)
            # этот метод берет данные из б.д. пользователей и проверяет на
            # совпадение и на его активность
            if user and user.is_active:
                # Здесь нужно будет раобраться потомучто при создании пользователя в формах проводилась проврека на
                # выставление авторизация-нет. Из-за этого выходила ошибка. Сейчас стоит истина и работает.
                auth.login(request, user)  # Производлим авторизацию
                # отправляем главную страницу
                return HttpResponseRedirect(reverse('main'))
    else:
        form = UserLoginForm()
    context = {'form': form}  # Форму передали в контекст
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 14
0
def login(request):
    ''' Вход в систему '''
    page_title = 'Вход в систему'
    form = UserLoginForm()
    if request.POST.get('login'):
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)
            print(1)
            return redirect('index')

    content = {'form': form, "page_title": page_title}

    return render(request, 'authapp/login.html', content)
Ejemplo n.º 15
0
def login(request):
    login_form = UserLoginForm(data=request.POST)

    print(login_form.is_valid())
    print(login_form.errors)

    if request.method == 'POST' and login_form.is_valid():
        username = request.POST['username']
        password = request.POST['password']
        print(username)
        print(password)

        user = auth.authenticate(username=username, password=password)

        if user and user.active:
            auth.login(request, user)
            return HttpResponseRedirect(reverse('main:main'))
    else:
        login_form = UserLoginForm()

    content = {'login_form': login_form}
    return render(request, 'authapp/sign_in.html', content)