本文整理汇总了Python中accounts.forms.UserLoginForm.add_error方法的典型用法代码示例。如果您正苦于以下问题:Python UserLoginForm.add_error方法的具体用法?Python UserLoginForm.add_error怎么用?Python UserLoginForm.add_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.forms.UserLoginForm
的用法示例。
在下文中一共展示了UserLoginForm.add_error方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)
示例2: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)
示例3: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)
示例4: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)
示例5: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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})
示例6: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)
示例7: login
# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [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)