Init
This commit is contained in:
commit
a5b7dfc60c
100 changed files with 21307 additions and 0 deletions
37
account/views.py
Normal file
37
account/views.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template.context import RequestContext
|
||||
from django.contrib.auth import login, logout, authenticate
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from account.forms import LoginForm
|
||||
|
||||
|
||||
def auth_login(request):
|
||||
redirect_to = request.REQUEST.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 = authenticate(username=username, password=password)
|
||||
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()
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
else:
|
||||
print 'user is none'
|
||||
else:
|
||||
form = LoginForm()
|
||||
return render_to_response('login.html',
|
||||
RequestContext(request, locals()))
|
||||
|
||||
|
||||
def auth_logout(request):
|
||||
redirect_to = request.REQUEST.get('next', '') or '/'
|
||||
logout(request)
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
Loading…
Add table
Add a link
Reference in a new issue