本文整理汇总了Python中accounts.forms.UserLoginForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python UserLoginForm.is_valid方法的具体用法?Python UserLoginForm.is_valid怎么用?Python UserLoginForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.forms.UserLoginForm
的用法示例。
在下文中一共展示了UserLoginForm.is_valid方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request):
form = UserLoginForm()
args = dict()
args['form'] = form
args['title'] = 'Login'
if request.method == 'GET':
return render(request, 'accounts/login.html', args)
elif request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = auth.authenticate(email=email, password=password)
if user is not None:
if user.is_active:
auth.login(request, user)
return redirect('accounts:profile', user.pk)
else:
form.add_error(None, u'Користувач заблокований')
else:
form.add_error(None, u'Невірний логін або пароль')
args['form'] = form
return render(request, 'accounts/login.html', args)
示例2: auth_login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def auth_login(request):
print (request.user.is_authenticated())
next = request.GET.get('next')
title = "Login"
form = UserLoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data.get("username")
password = form.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if next:
return HttpResponseRedirect(next)
print (request.user.is_authenticated())
#redirect url link comes in here
return redirect("logged_in")
action_url = reverse("login")
extra_form_link = "Upgrade your account today <a href='%s'>here</a>!" %(reverse("account_upgrade"))
context = {
"form":form,
"title":title,
}
return render(request, "form.html", context)
示例3: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request, success_url=None):
if request.method == "POST":
form = UserLoginForm(request.POST)
if form.is_valid():
try:
user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password"))
if user is not None:
auth.login(request, user)
messages.error(request, "You have successfully logged in")
return redirect(reverse("profile"))
else:
form.add_error(None, "Your email or password was not recognised")
except SubscriptionEnded:
form.add_error(None, "Your subscription has ended")
else:
form = UserLoginForm()
args = {"form": form}
args.update(csrf(request))
return render(request, "login.html", args)
示例4: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request, success_url=None):
if request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))
if user is not None:
auth.login(request, user)
messages.error(request, "You have sucessfully logged in")
return redirect(reverse('profile'))
else:
form.add_error(None, "Your email or password was not recognised")
else:
form = UserLoginForm()
args = {'form':form}
args.update(csrf(request))
return render(request, 'login.html', args)
示例5: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request, success_url=None):
if request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))
if user is not None:
auth.login(request, user)
return redirect(profile)
else:
messages.error(request, "Unable to log you in! Please try again.")
return redirect(register)
else:
messages.error(request, "Unable to log you in! Please try again.")
return redirect(register)
示例6: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request):
loginForm = UserLoginForm()
# Dealing with user authentication situation.
if request.method == 'POST':
loginForm = UserLoginForm(request.POST)
context = { 'loginForm': loginForm }
#print request.session.modified # False
print request.user
if loginForm.is_valid():
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
#print request.session.modified # False
if user is not None:
auth.login(request, user)
#print request.session.modified # True
request.session.set_expiry(10)
#print request.session.modified # True
return redirect('player_loggedIn')
else:
context['playerDoesNotExist'] = 'Please check your username and/or password.'
return render(request, 'login.html', context)
else:
return render(request, 'login.html', context)
else:
context = { 'loginForm': loginForm }
return render(request, 'login.html', context)
示例7: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request, success_url=None):
if request.user.is_authenticated():
return redirect(reverse('profile'))
if request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
try:
user = auth.authenticate(email=request.POST.get('email'),
password=request.POST.get('password'))
if user is not None:
auth.login(request, user)
messages.error(request, "You have successfully logged in")
return redirect(reverse('profile'))
else:
subscription_not_ended = arrow.now() < arrow.get(user.subscription_end)
if not subscription_not_ended:
form.add_error(None,"Your subscription has now ended")
form.add_error(None,"Your email or password was not recognised")
except SubscriptionEnded:
form.add_error(None,"Your subscription has now ended")
else:
form = UserLoginForm()
args = {'form':form}
args.update(csrf(request))
return render(request, 'login.html', args)
示例8: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request):
"""
This method checks for post method and if not displays a an empty login form. If it is a POST then the form is
populated and checked for validity before authentication.
:param request:
:return:
"""
if request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
user = auth.authenticate(email=request.POST.get('email'),
password=request.POST.get('password'))
if user is not None:
auth.login(request, user)
messages.error(request, "You have successfully logged in")
return redirect(reverse('profile'))
else:
form.add_error(None, "Your email or password was not recognised")
else:
form = UserLoginForm()
args = {'form': form}
args.update(csrf(request))
return render(request, 'login.html', args)
示例9: login_view
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login_view(request):
next = request.GET.get("next")
form = UserLoginForm(request.POST or None)
title = "Login"
if form.is_valid():
username = form.cleaned_data.get("username")
password = form.cleaned_data.get("password")
user = authenticate(username=username, password=password)
login(request, user)
if next:
return redirect(next)
return redirect("/")
context = {"form": form, "title": title}
return render(request, "form.html", context)
示例10: post_list
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def post_list(request): #list items #this one is for homepage
today = timezone.now().date()
queryset_list = Post.objects.active() #.order_by("-timestamp")
print (request.user.is_authenticated())
next = request.GET.get('next')
title = "Login"
form = UserLoginForm(request.POST or None)
if request.user.is_staff: #or request.user.is_admin:
queryset_list = Post.objects.all()
paginator = Paginator(queryset_list, 1) # Show 1 blog(s) per page
page_request_var = 'page'
page = request.GET.get( page_request_var )
try:
queryset = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
queryset = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
queryset = paginator.page(paginator.num_pages)
if form.is_valid():
username = form.cleaned_data.get("username")
password = form.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if next:
return HttpResponseRedirect(next)
print (request.user.is_authenticated())
#redirect url link comes in here
return redirect("/")
action_url = reverse("login")
extra_form_link = "Upgrade your account today <a href='%s'>here</a>!" %(reverse("account_upgrade"))
context = {
"object_list":queryset,
"title":"List",
"form":form,
"title":title,
"page_request_var":page_request_var,
"today":today,
}
return render (request, "post_list.html", context)
示例11: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request):
"""Return a login page"""
if request.user.is_authenticated:
return redirect(reverse('index'))
if request.method == "POST":
login_form = UserLoginForm(request.POST)
if login_form.is_valid():
user = auth.authenticate(username=request.POST['username'],
password=request.POST['password'])
if user:
auth.login(user=user, request=request)
messages.success(request, "You have successfully logged in")
return redirect(reverse('index'))
else:
login_form.add_error(None, "Your username or password is incorrect")
else:
login_form = UserLoginForm()
return render(request, 'login.html', {"login_form": login_form})
示例12: post
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def post(request):
login_form = UserLoginForm(request.POST, request=request)
if login_form.is_valid():
user = authenticate(
username=request.POST.get('username'),
password=request.POST.get('password'),
)
if NEED_CONFIRM_EMAIL and not user.is_active:
messages.success(request, u"账号需要激活, 请登陆您的邮箱激活, 或"
u"点击<a href='" + DOMAIN +
reverse('accounts:resend_activate',
kwargs={'username': request.POST.get('username')}) +
u"'>这里</a>重发激活邮件")
return HttpResponseRedirect(reverse('accounts:index'))
auth.login(request, user)
messages.success(request, u'登录成功')
if 'next' in request.GET:
return HttpResponseRedirect(request.GET.get('next'))
return HttpResponseRedirect(reverse('accounts:index'))
else:
return render(request, "accounts/form_tpl.html", {"form": login_form})
示例13: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request, success_url=None):
if request.method == 'POST':
form = UserLoginForm(request.POST)
if form.is_valid():
user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))
if user is not None:
auth.login(request, user)
first_login = User.objects.filter(pk=request.user.id).values_list('first_login', flat=True)
user_first_login = first_login[0]
if user.date_joined.date() == user.last_login.date() and user_first_login:
User.objects.filter(pk=request.user.id).update(first_login = False)
return redirect(edit_profile)
else:
return redirect(profile)
else:
messages.error(request, "Unable to log you in! Please try again.")
return redirect(register)
else:
messages.error(request, "Unable to log you in! Please try again.")
return redirect(register)
示例14: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import is_valid [as 别名]
def login(request):
if request.method == 'POST':
# if submitting form create instance of form class and populate
form = UserLoginForm(request.POST)
if form.is_valid(): # if login form is valid
# authenticate user:
# 'auth' will find our class 'EmailAuth' in backends.py via the
# backend list in settings.py and then call the authenticate method.
user = auth.authenticate(email=request.POST.get('email'),
password=request.POST.get('password'))
if user is not None:
auth.login(request, user) # login user. login() is a django method. Sets up a user session.
messages.success(request, "You have successfully logged in.")
return redirect(reverse('profile'))
else:
form.add_error(None, "Your email or password is not recognised.")
else:
# if login link has been clicked show the empty login form
form = UserLoginForm()
args = {'form': form}
args.update(csrf(request))
return render(request, 'login.html', args)