Merge branch 'dev' into hohoTT-dev
This commit is contained in:
@@ -25,7 +25,6 @@ class UserRegisterSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class UserChangePasswordSerializer(serializers.Serializer):
|
||||
username = serializers.CharField(max_length=30)
|
||||
old_password = serializers.CharField()
|
||||
new_password = serializers.CharField(max_length=30, min_length=6)
|
||||
|
||||
|
||||
@@ -123,22 +123,13 @@ class UserChangePasswordAPITest(APITestCase):
|
||||
user = User.objects.create(username="test")
|
||||
user.set_password("aaabbb")
|
||||
user.save()
|
||||
self.client.login(username="test",password="aaabbb")
|
||||
|
||||
def test_error_old_password(self):
|
||||
data = {"username": "test", "old_password": "aaaccc", "new_password": "aaaddd"}
|
||||
data = {"old_password": "aaaccc", "new_password": "aaaddd"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
self.assertEqual(response.data, {"code": 1, "data": u"密码不正确,请重新修改!"})
|
||||
|
||||
def test_invalid_data_format(self):
|
||||
data = {"old_password": "aaa", "new_password": "aaaddd"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
self.assertEqual(response.data["code"], 1)
|
||||
|
||||
def test_username_does_not_exist(self):
|
||||
data = {"username": "test1", "old_password": "aaabbb", "new_password": "aaaddd"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
self.assertEqual(response.data["code"], 1)
|
||||
|
||||
def test_success_change_password(self):
|
||||
data = {"username": "test", "old_password": "aaabbb", "new_password": "aaaccc"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
|
||||
@@ -35,7 +35,7 @@ class UserLoginAPIView(APIView):
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
|
||||
@login_required
|
||||
def logout(request):
|
||||
auth.logout(request)
|
||||
return http.HttpResponseRedirect("/")
|
||||
@@ -69,6 +69,7 @@ class UserRegisterAPIView(APIView):
|
||||
|
||||
|
||||
class UserChangePasswordAPIView(APIView):
|
||||
@login_required
|
||||
def post(self, request):
|
||||
"""
|
||||
用户修改密码json api接口
|
||||
@@ -78,7 +79,8 @@ class UserChangePasswordAPIView(APIView):
|
||||
serializer = UserChangePasswordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
data = serializer.data
|
||||
user = auth.authenticate(username=data["username"], password=data["old_password"])
|
||||
username = request.user.username
|
||||
user = auth.authenticate(username=username, password=data["old_password"])
|
||||
if user:
|
||||
user.set_password(data["new_password"])
|
||||
user.save()
|
||||
|
||||
Reference in New Issue
Block a user