Ejemplo n.º 1
0
        return;
    }
    $file = $_POST['file'];
    if (empty($name) || empty($password)) {
        $response['status'] = '403';
        $response['message'] = 'Name, email and password cannot be blank.';
        echo json_encode($response);
        return;
    }
    if (dbClass::getPasswordFromPasswords($password)) {
        $response['status'] = '403';
        $response['message'] = 'This password is already set up.';
        echo json_encode($response);
        return;
    }
    if (dbClass::savePassword($name, $password)) {
        $pwdId = dbClass::getLastPasswordId()['id'];
        foreach ($file as $fl) {
            $filename = array_pop(explode('/', $fl));
            if (dbClass::query('INSERT INTO files (password_id, file) VALUES ("' . $pwdId . '", "' . $filename . '")')) {
                $response['status'] = '200';
                $response['message'] = 'Password has been successfully set up for ' . $name . '.';
            } else {
                $response['status'] = '500';
                $response['message'] = 'Could not save the password.';
            }
        }
    }
    echo json_encode($response);
    return;
}