示例#1
0
def login(request):
    if request.method == 'POST':
        respuesta = {}

        userGW = UserGateway(database)
        fileGW = FileGateway(database)
        filesystem = Filesystem(database)
        userJson = json.loads(request.POST['user'])

        user = User(userGW.getUser(userJson['nick']))
        if user is not None:
            print(user.get_password())
            if security.verifyPassword(userJson['password'],
                                       user.get_password()):
                root = filesystem.getNode(user.get_nick())
                respuesta['user'] = user.toJSON()
                del respuesta['user']['password']
                respuesta['root'] = root
                respuesta['token'] = security.generateJWT(user.get_nick())
                respuesta['totalModelos'] = filesystem.getNumberOfModels(
                    user.get_nick())

                return JsonResponse(respuesta, status=200, safe=False)
            return JsonResponse({}, status=401, safe=False)
        return JsonResponse(respuesta, status=404, safe=False)
    return JsonResponse({}, status=404, safe=False)
示例#2
0
def patchUser(request, id):

    userGW = UserGateway(database)
    patched_properties = json.loads(request.body)
    if userGW.patchUser(id, patched_properties):
        return JsonResponse({}, status=200, safe=False)
    return JsonResponse({}, status=500, safe=False)
示例#3
0
def updateUser(request, id):
    respuesta = {}
    userGW = UserGateway(database)
    user = User(json.loads(request.POST['user']))
    userJson = userGW.updateUser(id, user)
    respuesta['user'] = userJson
    return JsonResponse(respuesta, status=200, safe=False)
示例#4
0
def getUser(request, id):
    respuesta = {}
    userGW = UserGateway(database)
    user = userGW.getUser(id)

    respuesta['user'] = user
    return JsonResponse(respuesta, status=200, safe=False)
示例#5
0
def signup(request):
    if request.method == 'POST':
        respuesta = {}

        userGW = UserGateway(database)
        fileGW = FileGateway(database)
        filesystem = Filesystem(database)
        userJson = json.loads(request.POST['user'])

        user = User(userJson)
        user.set_password(security.createPassword(user.get_password()))
        if not userGW.exists(user.get_nick()):
            if userGW.insertUser(user):
                file = filesystem.create(user.get_nick())
                if fileGW.insertFile(file):
                    respuesta['user'] = user.toJSON()
                    del respuesta['user']['password']
                    respuesta['root'] = file.toJSON()
                    respuesta['root']['hijos'] = []
                    respuesta['token'] = security.generateJWT(user.get_nick())
                    respuesta['totalModelos'] = 0

                    return JsonResponse(respuesta, status=201, safe=False)
            return JsonResponse(respuesta, status=500, safe=False)
        return JsonResponse(respuesta, status=409, safe=False)
    return JsonResponse({}, status=404, safe=False)
示例#6
0
def move(request):
    if request.method == 'POST':
        respuesta = {}

        userGW = UserGateway(database)
        fileGW = FileGateway(database)
        filesystem = Filesystem(database)
        datos = json.loads(request.POST['datos'])

        filesystem.move(datos['idModel'], datos['idFolder'])
        return JsonResponse({}, status=200, safe=False)
    return JsonResponse({}, status=404, safe=False)
示例#7
0
def deleteUser(request, id):
    userGW = UserGateway(database)

    if userGW.deleteUser(id):
        return JsonResponse({}, status=200, safe=False)
    return JsonResponse({}, status=500, safe=False)
示例#8
0
def insertUser(request):
    userGW = UserGateway(database)
    user = User(json.loads(request.POST['user']))
    if userGW.insertUser(user):
        return JsonResponse({'user': user.toJSON()}, status=201, safe=False)
    return JsonResponse({}, status=500, safe=False)