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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)