本文整理汇总了Python中forms.LoginForm.login方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.login方法的具体用法?Python LoginForm.login怎么用?Python LoginForm.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.login方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auth_login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def auth_login(request):
redirect_to = request.GET.get('next', '') or '/'
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = form.login(request)
if user is not None:
if user.is_active:
login(request, user)
member, created = \
User.objects.get_or_create(username=username)
if created:
member.save()
# save password in the session for later use with LDAP
key = store_ldap_password(request, password)
response = HttpResponseRedirect(redirect_to)
response.set_cookie('sessionkey', key)
return response
else:
return render(request, 'login.html', {'form': form})
else:
form = LoginForm()
return render_to_response('login.html',
RequestContext(request, locals()))
示例2: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def login(req):
if req.method == "POST":
form = LoginForm(req.POST)
if form.login(req):
return HttpResponseRedirect(reverse("index", args=[]))
else:
form = LoginForm()
return render_to_response("login.html", {"settings": settings, "form": form}, context_instance=RequestContext(req))
示例3: signin
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def signin(req):
if req.method == 'POST':
form = LoginForm(req.POST)
if form.login(req):
return HttpResponseRedirect(reverse('home', args=[]))
else:
form = LoginForm()
return render_to_response('login.html', {'settings' : settings, 'form': form}, context_instance=RequestContext(req))
示例4: index
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def index(request):
#@todo How to set form data without calling constructor?
if 'create' in request.POST:
register_form = RegisterForm(request.POST)
if register_form.is_valid():
register_form.save()
return HttpResponseRedirect('/?succes_register=1')
else:
register_form = RegisterForm()
if 'login' in request.POST:
login_form = LoginForm(request.POST)
if login_form.is_valid():
response = HttpResponseRedirect('/?succes_login=1')
login_form.login(response)
return response
else:
login_form = LoginForm()
if 'post' in request.POST:
post_form = PostForm(request.POST)
if post_form.is_valid():
post_form.save(request)
return HttpResponseRedirect('/?succes_post=1')
else:
post_form = PostForm()
succes_register = 0
if 'succes_register' in request.GET and request.GET['succes_register']:
succes_register = 1
posts = request.user.get_news(0, -1)
tpl_vars = {
'register_form': register_form,
'succes_register': succes_register,
'login_form': login_form,
'post_form': post_form,
'posts': posts
}
return render_to_response('index.html', tpl_vars, context_instance=RequestContext(request))
示例5: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def login(request):
form = LoginForm(request.POST or None)
if request.method == 'POST' and form.is_valid():
user = form.login(request)
if user:
auth_login(request, user)
return redirect('/')
return render(request, 'users/login.html', {
'form': form,
})
示例6: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def login(request):
reason = None
next = request.REQUEST.get('next', '')
if request.method == "POST":
openidform = OpenIDForm(request.POST)
def openid_failure(request,message):
return direct_to_template(request, "account/login.html", {
"form": LoginForm(),
"openidform": openidform,
"openid_message":message,
"reason": reason,
})
def if_not_user_url(request):
return HttpResponseRedirect(reverse('acct_login'))
if request.POST.has_key('openid_url'):
redirect_to = '/openid/complete/'
if next:
logger.info("NEXT: %s", next)
redirect_to += '?' + urlencode({'next':next})
return openid_consumer_views.begin(request,on_failure=openid_failure,sreg = 'email,nickname',redirect_to=redirect_to, if_not_user_url=if_not_user_url)
form = LoginForm(request.POST)
redirect_to = None
if form.login(request):
return HttpResponseRedirect(make_absolute_url(next or '/'))
else:
# http://jira.filmaster.org/browse/FLM-420
full_next = FULL_DOMAIN + next
if next == full_url("LOGOUT") or full_next == full_url("LOGOUT"):
next = ""
reason = request.GET.get('reason')
form = LoginForm(
initial = {
'next': next,
'reason': reason,
})
openidform = OpenIDForm(
initial = {
'next': next,
'reason': reason,
})
return direct_to_template(request, "account/login.html", {
"next": next,
"form": form,
"openidform": openidform,
"reason": reason,
})
示例7: login_user
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def login_user(request):
form = LoginForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
user = form.login(request)
if user:
login(request, user)
if request.GET.get('next'):
return HttpResponseRedirect(request.GET.get('next'))# Redirect to a success page.
else:
return HttpResponseRedirect('/')
return render(request, 'bbs/login.html', {'form': form })
示例8: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def login(request):
error = ''
if request.method == 'POST':
if 'logout' in request.POST:
logout(request)
return HttpResponseRedirect('/')
login_form = None
if request.method == 'POST':
login_form = LoginForm(request.POST)
if login_form.is_valid():
login_form.login(request)
else:
login_form = LoginForm()
t = loader.get_template('login.view')
c = { 'is_authenticated' : request.user.is_authenticated(),
'login_form' : login_form }
c.update(csrf(request))
return HttpResponse(t.render(Context(c)))
示例9: index
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import login [as 别名]
def index(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = form.login(request)
if user:
login(request, user)
return HttpResponseRedirect('/notifications')
else:
print"no"
else:
form = LoginForm()
return render(request, 'index.html', {'form': form})