Пример #1
0
def download_package():
    """
    Tries to retrieve package from git
    """
    data = request.get_json()
    validate_data(data, {'token', 'package_id'})
    package = Package.get_package_by_id(data['package_id'])
    package.download_package()
    return response_ok({'data': 'Done'})
Пример #2
0
def login_action():
    """
    API login entry point
    """
    data = request.get_json()
    validate_data(data, {'username', 'password'})
    token = login(data['username'], data['password'])
    data = {"token": token.token, "verified": "true"}
    return response_ok(data)
Пример #3
0
def delete_package():
    """
    Deletes package
    """
    data = request.get_json()
    validate_data(data, {'token', 'package_id'})
    package = Package.get_package_by_id(data['package_id'])
    package.delete_package()
    data = {"data": "done"}
    return response_ok(data)
Пример #4
0
def delete_user():
    """
    Deletes user by it's id (only deactivation)
    """
    data = request.get_json()
    validate_data(data, {'token', 'user_id'})
    token = data['token']
    user_id = data['user_id']
    validate_token(token)
    user = User.get_user_by_id(user_id)
    User.deactivate_user_by_id(user.id)
    data = {"data": "done"}
    return response_ok(data)
Пример #5
0
def is_user_authorised():
    """
    Information about users token, whenever its valid token or not
    """
    data = request.get_json()
    validate_data(data, {'token'})
    token = check_token_exists(data['token'])
    if token == None\
        or (token.created + timedelta(hours=24) < datetime.utcnow() \
        and token.update + timedelta(hours=2) < datetime.utcnow())\
        or token.user.active == False:
        raise ApiException(403, "Invalid token.")
    tokenData = {"verified": "true" if token.user.activated else "false"}
    return response_ok(tokenData)
Пример #6
0
def activation_action():
    """
    Acc activation
    """
    data = request.get_json()
    validate_data(data, {'token'})
    token = check_token_exists(data['token'])
    if token == None:
        raise ApiException(403, "Invalid token.")
    if token.user.activated:
        raise ApiException(400, "User has been already activated.")
    #check code somehow
    token.user.update_activation_by_id(token.user.id, True)
    data = {"data": "activated"}
    return response_ok(data)
Пример #7
0
def stats():
    """
    Return status with count of users, modules, projects and packages
    """
    token = request.args.get('token')
    validate_token(token)
    user_count = User.query.count()
    module_count = Module.query.count()
    project_count = Project.query.count()
    package_count = Package.query.count()
    data = {
        'user_count': user_count,
        'module_count': module_count,
        'project_count': project_count,
        'package_count': package_count
    }
    return response_ok(data)
Пример #8
0
def registration_action():
    """
    Registration
    """
    data = request.get_json()
    validate_data(data, {'username', 'password', 'email'})
    if not validate_email(data['email']):
        raise ApiException(400, "email")
    if not validate_username(data['username']):
        raise ApiException(400, "username")
    if not validate_password(data['password']):
        raise ApiException(400, "password")
    if User.check_unique(data['username'], data['email'], True):
        userEntity = User(data['username'], data['email'], data['password'])
        userEntity.save_entity()
        token = authenticate(None, True, userEntity.id)
        data = {"user_id": userEntity.id, "token": token.token}
        return response_ok(data)
Пример #9
0
def build_module_action():
    """
    Update or create module
    """
    data = request.get_json()
    if data == None:
        raise ApiException(400, "data")
    if (data['token'] == None):
        raise ApiException(403, "Invalid token")
    if (('module_id' not in data) or (data['module_id'] == None)):
        raise ApiException(403, "Invalid module_id")
    else:
        moduleId = data['module_id']
    validate_token(data['token'])
    #check permissions in the future
    
    data = Module.get_module_by_id(moduleId).build_module()

    return response_ok(data)
Пример #10
0
def home():
    """
    Some kind of homepage
    """
    return response_ok({"data": "This is evodoc backend api."})