本文整理汇总了Python中User.models.User.userAuth方法的典型用法代码示例。如果您正苦于以下问题:Python User.userAuth方法的具体用法?Python User.userAuth怎么用?Python User.userAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User.models.User
的用法示例。
在下文中一共展示了User.userAuth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logout
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import userAuth [as 别名]
def logout(request):
if User.userAuth(request, tokkening=True):
user = User.objects.get(id=request.session['id'])
user.logout(request)
return redirect('/')
else:
return redirect('/')
示例2: login
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import userAuth [as 别名]
def login(request):
if User.userAuth(request, tokkening=True):
return redirect('/users/')
if request.method == 'POST':
print 'loging..'
username = request.POST['username']
password = request.POST['password']
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
msg = 'Error. User not found.'
print msg
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
except User.MultipleObjectsReturned:
msg = 'Error. Multiple user. Please contact with administrator.'
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
if user.passwordCompare(password):
user.login(request)
msg = 'Login successfully'
print msg
return redirect('/users/')
else:
msg = 'Error. Wrong password.'
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
else:
return render_to_response('login.html', context_instance=RequestContext(request))
示例3: token_detail
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import userAuth [as 别名]
def token_detail(request, format=None):
if User.userAuth(request, tokkening=False) == False:
print u"Access denied"
return render_to_response('denied.html', context_instance=RequestContext(request))
if request.method == 'GET':
try:
user = User.objects.get(id=request.session['id'])
token = Token.objects.get(id=user.token_id)
except Token.DoesNotExist or User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = TokenSerializer(token)
return Response(serializer.data)
示例4: user_list
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import userAuth [as 别名]
def user_list(request, format=None):
if User.userAuth(request, tokkening=True) == False:
print u"Access denied"
return render_to_response('denied.html', context_instance=RequestContext(request))
if request.method == 'GET':
users = User.objects.all()
serializer = UserSerializer(users, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例5: user_detail
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import userAuth [as 别名]
def user_detail(request, pk, format=None):
if User.userAuth(request, tokkening=True) == False:
print u"Access denied"
return Response(status=status.HTTP_403_FORBIDDEN)
try:
user = User.objects.get(id=pk)
except User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = UserSerializer(user)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = UserSerializer(user, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
user.delete()
return Response(status=status.HTTP_204_NO_CONTENT)