Ejemplo n.º 1
0
 def post(self, request):
     if request.POST["view_name"] == 'is_working':
         if 'multiple_data' in request.POST:
             return HttpResponse("Working multiple_data POST " +
                                 request.POST["multiple_data"])
         return HttpResponse("Working POST " + request.POST["view_name"])
     elif request.POST["view_name"] == 'create_user':
         username = request.POST['username']
         password = request.POST['password']
         user = MudUser(username=username, password=password)
         # save() before : should be set_password()
         user.set_password(password)
         try:
             user.save()
         except IntegrityError:
             return HttpResponse(user.username + " The ID already exists.")
         else:
             return HttpResponse("Success create User " + user.username)
     # login
     elif request.POST["view_name"] == 'login_user':
         username = request.POST['username']
         password = request.POST['password']
         user = authenticate(username=username, password=password)
         if user is not None:
             login(request, user)
             return HttpResponse("Login success")
         else:
             return HttpResponse("invalid")
     # check login
     elif request.POST["view_name"] == 'login_check':
         if request.user.is_authenticated:
             return HttpResponse("Logged in")
         else:
             return HttpResponse("invalid")
     # get_username # must before login
     elif request.POST["view_name"] == 'get_username':
         if request.user.is_authenticated:
             return HttpResponse(request.user.username)
         else:
             return HttpResponse("invalid")
     # logout
     elif request.POST["view_name"] == 'logout_user':
         if request.user.is_authenticated:
             user = MudUser.objects.get(pk=request.user.pk)
             user.now_connected_character_name = ''
             user.save()
         logout(request)
         return HttpResponse("Logout success")
     else:
         pass
 def post(self, request):
     if request.POST["view_name"] == 'is_working':
         if 'multiple_data' in request.POST:
             return HttpResponse("Working multiple_data POST " +
                                 request.POST["multiple_data"])
         return HttpResponse("Working POST " + request.POST["view_name"])
     elif request.POST["view_name"] == 'create_user':
         username = request.POST['username']
         password = request.POST['password']
         user = MudUser(username=username, password=password)
         try:
             user.save()
         except IntegrityError:
             return HttpResponse(user.username + " The ID already exists.")
         else:
             return HttpResponse("Success create User " + user.username)
     else:
         pass
Ejemplo n.º 3
0
    def test_004_02_create_same_two_username_muduser_model_with_password(self):
        try:
            user1 = MudUser.objects.create(
                username='******',
                password='******',
            )
            user2 = MudUser(username='******', password='******')
        except IntegrityError:
            pass

        with self.assertRaises(MudUser.DoesNotExist):
            assert MudUser.objects.get(
                pk=2).username == user2.username, 'Should be equal'
        assert MudUser.objects.count() == 1, 'Should be equal'
        assert MudUser.objects.get(
            pk=1).username == user1.username, 'Should be equal'
        assert MudUser.objects.get(
            pk=1).password == user1.password, 'Should be equal'
Ejemplo n.º 4
0
 def test_004_02_create_muduser_model_wtih_muduser_method(self):
     user = MudUser(username='******', password='******')
     user.save()
     assert MudUser.objects.count() == 1, 'Should be equal'
     assert MudUser.objects.get(
         pk=1).username == user.username, 'Should be equal'