Пример #1
0
def user_login():
    username = request.form.get('Username')
    password = request.form.get('Password')

    if not username:
        raise BenomeControllerException('Username required')

    user_details = user_manager.get_user(username=username, exception=False)
    if not user_details:
        raise BenomeControllerException('Login failed')

    user_id = None
    context_id = None

    if current_user and not current_user.is_anonymous and current_user.get_name() == username:
        user_id = current_user.get_id()
        context_id = current_user.get_root_context_id()
        user = current_user
    else:
        user = init_user(username=username, password=password)
        if user:
            login_user(user, remember=True)
            user_id = user.get_id()
            context_id = user.get_root_context_id()
        else:
            raise BenomeControllerException('Login failed')

    return json_response(auth_result(user))
Пример #2
0
def data_load(context_id=None):
    if not current_user or current_user.is_anonymous:
        return json_response({
            'ContextID': None,
            'Points': [],
            'Contexts': [],
            'Associations': []
        })

    if not context_id or str(context_id) in ('null', 'None'):
        context_id = current_user.get_root_context_id()

    contexts = call_container('get_contexts', data=context_id)
    points = call_container('get_points', data=context_id)
    associations = call_container('get_associations', data=context_id)

    return json_response({
        'ContextID': context_id,
        'LastID': current_user.get_last_id(),
        'Points': points,
        'Contexts': contexts,
        'Associations': associations
    })