Exemplo n.º 1
0
def register_user(user_id, password, ip, email, nickname, realname, career,
                  address, over18):
    url = cfg.config.get('ptt_server', '') + '/register'

    params = {
        'UserID': user_id,
        'Passwd': password,
        'IP': ip,
        'Email': email,
        'Nickname': nickname,
        'Realname': realname,
        'Career': career,
        'Address': address,
        'Over18': over18,
    }
    err, result = http_post(url, params)
    if err is not None:
        return err, result

    jwt = result.get('Jwt', '')

    pyutil_mongo.db_update('user', {'user_id': user_id}, {
        'jwt': jwt,
        'active': True,
        'last_login': get_current_milli_ts()
    })

    return None, jwt
    def test_login(self, the_mock):
        with self.app.test_request_context(_with_app_prefix(account_login.ROUTE), environ_base={'REMOTE_ADDR': '10.1.2.3'}):
            err, ret = account_login.account_login({'client_id': 'test_client_id', 'client_secret': 'test_client_secret'})

        assert err is not None

        params = {
            'client_id': 'test_client_id',
            'client_secret': 'test_client_secret',

            'username': '******',
            'password': '******',
            'password_confirm': 'test_password',
            'over18': True,
        }

        pyutil_mongo.db_update('client', {'client_id': 'test_client_id'}, {'client_secret': 'test_client_secret'})

        with self.app.test_request_context(_with_app_prefix(account_login.ROUTE), environ_base={'REMOTE_ADDR': '10.1.2.3'}):
            err, ret = account_register.account_register(params)
            assert err is None

            err, ret = account_login.account_login({'client_id': 'test_client_id', 'client_secret': 'test_client_secret', 'username': '******', 'password': '******'})

        assert err is None
        assert 'access_token' in ret
Exemplo n.º 3
0
    def test_is_valid_client(self):
        pyutil_mongo.db_update('client', {'client_id': 'test_client_id'},
                               {'client_secret': 'test_client_secret'})

        assert utils.is_valid_client('test_client_id', 'test_client_secret')
        assert not utils.is_valid_client('test_client_id', 'test_not-exists')
        assert not utils.is_valid_client('test_not-exists',
                                         'test_client_secret')
        assert not utils.is_valid_client('test_not-exists', 'test_not-exists')

        pyutil_mongo.db_force_remove('client', {})
Exemplo n.º 4
0
def validate_user(user_id, password, ip):
    url = cfg.config.get('ptt_server', '') + '/login'
    err, result = http_post(url, {
        'UserID': user_id,
        'Passwd': password,
        "IP": ip
    })
    if err is not None:
        return err, ''

    jwt = result.get('Jwt', '')

    pyutil_mongo.db_update('user', {'user_id': user_id}, {
        'jwt': jwt,
        'active': True,
        'last_login': get_current_milli_ts()
    })

    return None, jwt
Exemplo n.º 5
0
def post_login(user_id, jwt, is_register=False):
    current_milli_ts = get_current_milli_ts()

    update_data = {
        'login_milli_ts': current_milli_ts,
        'update_milli_ts': current_milli_ts,
    }
    if is_register:
        update_data['register_milli_ts'] = current_milli_ts

    err, results = pyutil_mongo.db_update('user', {'user_id': user_id}, update_data)
    if err:
        return err

    err, results = pyutil_mongo.db_update('access_token', {'access_token': jwt}, {'user_id': user_id, 'update_milli_ts': current_milli_ts})
    if err:
        return err

    return None
Exemplo n.º 6
0
    def test_register(self, the_mock):
        params = {
            'client_id': 'test_client_id',
            'client_secret': 'test_client_secret',
            'username': '******',
            'password': '******',
            'password_confirm': 'test_password',
            'over18': True,
        }

        pyutil_mongo.db_update('client', {'client_id': 'test_client_id'},
                               {'client_secret': 'test_client_secret'})

        with self.app.test_request_context(
                _with_app_prefix(account_register.ROUTE),
                environ_base={'REMOTE_ADDR': '10.1.2.3'}):
            cfg.logger.info('to account_register')
            err, ret = account_register.account_register(params)
            cfg.logger.info('after request: e: %s ret: %s', err, ret)

        assert err is None
        assert 'access_token' in ret
Exemplo n.º 7
0
def register_client(params):
    client_id = params.get('client_id', '')
    client_secret = params.get('client_secret', '')

    if not client_id:
        return Exception('invalid client'), {}

    update_milli_ts = get_current_milli_ts()

    err, result = pyutil_mongo.db_update('client', {'client_id': client_id}, {
        'client_secret': client_secret,
        'update_milli_ts': update_milli_ts
    })

    return err, {'success': True}