# Path: huacaya/auth/exception.py
# class RegisterError(Exception):
#     pass
# 
# class AuthorizationError(Exception):
#     pass


import datetime
import re
from uuid import uuid4
from base64 import b32encode
from .exception import RegisterError, AuthorizationError
    from urlparse import urlparse
    from urllib.parse import urlparse
        if self._dao.has_client_id(client_id):
            raise RegisterError('client_id have been registered.')
        else:
            client_data = kwds.copy()
            client_data['client_id'] = client_id
            self._dao.insert_client(client_data)

    def register_account(self, account):
        identity = account.get('username', None)
        if self._dao.has_username(identity):
            raise RegisterError('username had been registered')
        else:
            uid = self._dao.insert_account(account)
            return uid

    def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
        if self._dao.has_client_id(client_id):
            authorization_code_data = {
                'code': rndgen(),
                'issue_time': datetime.datetime.utcnow(),
                'expires_in': 300,
                'disabled': False,
                'account_ident': account_ident,
                'redirect_uri': redirect_uri,
                'client_id': client_id,
                'scope': scope,
            }
            self._dao.insert_authorization_code(authorization_code_data)
            return authorization_code_data['code']
        else:

# Path: huacaya/auth/exception.py
# class RegisterError(Exception):
#     pass
# 
# class AuthorizationError(Exception):
#     pass


# Path: huacaya/auth/auth.py
import datetime
import re
from uuid import uuid4
from base64 import b32encode
from .exception import RegisterError, AuthorizationError
    from urlparse import urlparse
    from urllib.parse import urlparse

        if self._dao.has_client_id(client_id):
            raise RegisterError('client_id have been registered.')
        else:
            client_data = kwds.copy()
            client_data['client_id'] = client_id
            self._dao.insert_client(client_data)

    def register_account(self, account):
        identity = account.get('username', None)
        if self._dao.has_username(identity):
            raise RegisterError('username had been registered')
        else:
            uid = self._dao.insert_account(account)
            return uid

    def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
        if self._dao.has_client_id(client_id):
            authorization_code_data = {
                'code': rndgen(),
                'issue_time': datetime.datetime.utcnow(),
                'expires_in': 300,
                'disabled': False,
                'account_ident': account_ident,
                'redirect_uri': redirect_uri,
                'client_id': client_id,
                'scope': scope,
            }
            self._dao.insert_authorization_code(authorization_code_data)
            return authorization_code_data['code']
        else:

            raise AuthorizationError(dict(