Beispiel #1
0
def login(request, username, password):
    try:
        token = UserService().login(username, password)
        user_id = User.objects(username=username, password=sha256(password.encode()).hexdigest()).first().id
    except Exception as error:
        return HttpResponse(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return HttpResponse(json.dumps({'token': token, 'user_id': str(user_id)}), status=status.HTTP_202_ACCEPTED)
Beispiel #2
0
    def test_change_country_name(self):
        new_country_name = 'New country'

        UserService().change_user_data(self.user.id, new_country_name=new_country_name)
        self.user.reload()

        self.assertEqual(self.user.country.name, new_country_name)
Beispiel #3
0
    def test_change_country_flag(self):
        new_country_flag = 'Link on new country flag'

        UserService().change_user_data(self.user.id, new_country_flag=new_country_flag)
        self.user.reload()

        self.assertEqual(self.user.country.link_img, new_country_flag)
Beispiel #4
0
    def test_change_password(self):
        new_password = '******'

        UserService().change_user_data(self.user.id, new_password=new_password)
        self.user.reload()

        self.assertEqual(self.user.password, new_password)
Beispiel #5
0
def change_user_data(request, user_id):
    try:
        request_data = JSONParser().parse(request)
        if SystemService.verify_token(user_id, request_data['token']):
            UserService().change_user_data(user_id, request_data['country_name'], request_data['link_on_flag'])
    except Exception as error:
        return HttpResponse(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return HttpResponse({}, status=status.HTTP_200_OK)
Beispiel #6
0
def logout(request, user_id):
    try:
        request_data = JSONParser().parse(request)
        if SystemService.verify_token(user_id, request_data['token']):
            UserService().logout(user_id)
        return HttpResponse({}, status=status.HTTP_200_OK)
    except Exception as error:
        return HttpResponse(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Beispiel #7
0
    def test_logout(self):
        self.assertNotEqual(self.user.token, '')
        self.assertTrue(self.user.isAuth)

        UserService().logout(self.user.id)
        self.user.reload()

        self.assertEqual(self.user.token, '')
        self.assertFalse(self.user.isAuth)
Beispiel #8
0
    def test_login(self):
        self.assertEqual(self.user.token, '')
        self.assertFalse(self.user.isAuth)

        UserService().login(self.user.username,self.user.password)
        self.user.reload()

        self.assertNotEqual(self.user.token, '')
        self.assertTrue(self.user.isAuth)
Beispiel #9
0
def delete_account(request, user_id, password):
    try:
        request_data = JSONParser().parse(request)
        if SystemService.verify_token(user_id, request_data['token']):
            deleted = UserService().delete_user_account(user_id, password)
            if not deleted:
                return HttpResponse({'Incorrect password'}, status=status.HTTP_400_BAD_REQUEST)
    except Exception as error:
        return HttpResponse(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return HttpResponse({}, status=status.HTTP_200_OK)
Beispiel #10
0
def register(request):
    try:
        request_data = JSONParser().parse(request)
        result_bool = UserService().register_new_user(request_data['username'], request_data['password'],
                                                      request_data['email'], request_data['country_name'],
                                                      request_data['link_on_flag'])
    except Exception as error:
        return HttpResponse(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return HttpResponse({}, status=status.HTTP_201_CREATED) if result_bool else HttpResponse({},
                                                                                             status=status.HTTP_400_BAD_REQUEST)
Beispiel #11
0
 def setUpClass(cls):
     UserService().register_new_user('Test user','1234','*****@*****.**','country name','')
Beispiel #12
0
 def tearDownClass(cls):
     user = User.objects(username='******').first()
     UserService().delete_user_account(user.id,user.password)
Beispiel #13
0
 def tearDown(self):
     UserService().logout(self.user.id)
Beispiel #14
0
 def setUp(self):
     self.user = User.objects(username='******').first()
     UserService().login(self.user.username, self.user.password)