diff --git a/syncano/models/accounts.py b/syncano/models/accounts.py index 082cccf..8623c49 100644 --- a/syncano/models/accounts.py +++ b/syncano/models/accounts.py @@ -1,4 +1,4 @@ - +from syncano.exceptions import SyncanoValueError from . import fields from .base import Model @@ -117,6 +117,10 @@ class Meta: 'methods': ['post'], 'path': '/users/{id}/reset_key/', }, + 'auth': { + 'methods': ['post'], + 'path': '/user/auth/', + }, 'list': { 'methods': ['get'], 'path': '/users/', @@ -133,6 +137,21 @@ def reset_key(self): connection = self._get_connection() return connection.request('POST', endpoint) + def auth(self, username=None, password=None): + properties = self.get_endpoint_data() + endpoint = self._meta.resolve_endpoint('auth', properties) + connection = self._get_connection() + + if not (username and password): + raise SyncanoValueError('You need provide username and password.') + + data = { + 'username': username, + 'password': password + } + + return connection.request('POST', endpoint, data=data) + def _user_groups_method(self, group_id=None, method='GET'): properties = self.get_endpoint_data() endpoint = self._meta.resolve_endpoint('groups', properties) diff --git a/tests/integration_test_accounts.py b/tests/integration_test_accounts.py index 36d6e90..ac467db 100644 --- a/tests/integration_test_accounts.py +++ b/tests/integration_test_accounts.py @@ -67,3 +67,8 @@ def test_user_alt_login(self): user_key=self.USER_KEY, instance_name=self.INSTANCE_NAME) self.check_connection(con) + + def test_user_auth(self): + self.assertTrue( + self.connection.User().auth(username=self.USER_NAME, password=self.USER_PASSWORD) + )