增加用户注册代码和API测试

This commit is contained in:
hohoTT
2015-08-03 18:45:26 +08:00
parent b3d5519987
commit 2a2ef36d14
4 changed files with 51 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ from rest_framework.views import APIView
from utils.shortcuts import serializer_invalid_response, error_response, success_response
from .models import User
from .serializers import UserLoginSerializer, UsernameCheckSerializer
from .serializers import UserLoginSerializer, UsernameCheckSerializer, UserRegisterSerializer
class UserLoginAPIView(APIView):
@@ -30,12 +30,26 @@ class UserLoginAPIView(APIView):
return serializer_invalid_response(serializer)
class UserRegisterView(APIView):
def get(self, request):
pass
class UserRegisterAPIView(APIView):
def post(self, request):
pass
"""
用户注册json api接口
---
request_serializer: UserRegisterSerializer
"""
serializer = UserRegisterSerializer(data=request.DATA)
if serializer.is_valid():
data = serializer.data
try:
User.objects.get(username=data["username"])
return error_response(u"用户名已存在")
except User.DoesNotExist:
user = User.objects.create(username=data["username"], real_name=data["real_name"])
user.set_password(data["password"])
user.save()
return success_response(u"注册成功!")
else:
return serializer_invalid_response(serializer)
class UserChangePasswordView(APIView):