working on deletion functions
This commit is contained in:
		
							parent
							
								
									f97e04df55
								
							
						
					
					
						commit
						ee572e1f59
					
				@ -7,17 +7,15 @@
 | 
				
			|||||||
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
 | 
					    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
 | 
				
			||||||
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
 | 
					    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
 | 
				
			||||||
    <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.dataTables.min.css">
 | 
					    <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.dataTables.min.css">
 | 
				
			||||||
    <script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>
 | 
					 | 
				
			||||||
    <style>
 | 
					    <style>
 | 
				
			||||||
        /* Blur effect for the password field */
 | 
					 | 
				
			||||||
        .password-blur {
 | 
					        .password-blur {
 | 
				
			||||||
            filter: blur(4px);
 | 
					            filter: blur(4px);
 | 
				
			||||||
            transition: filter 0.3s ease;
 | 
					            transition: filter 0.3s ease;
 | 
				
			||||||
 | 
					            cursor: pointer;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    </style>
 | 
					    </style>
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
 | 
					 | 
				
			||||||
    <!-- Navbar -->
 | 
					    <!-- Navbar -->
 | 
				
			||||||
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
 | 
					    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
 | 
				
			||||||
        <a class="navbar-brand" href="/">KTVManager</a>
 | 
					        <a class="navbar-brand" href="/">KTVManager</a>
 | 
				
			||||||
@ -26,15 +24,9 @@
 | 
				
			|||||||
        </button>
 | 
					        </button>
 | 
				
			||||||
        <div class="collapse navbar-collapse" id="navbarNav">
 | 
					        <div class="collapse navbar-collapse" id="navbarNav">
 | 
				
			||||||
            <ul class="navbar-nav ml-auto">
 | 
					            <ul class="navbar-nav ml-auto">
 | 
				
			||||||
                <li class="nav-item">
 | 
					                <li class="nav-item"><a class="nav-link" href="/">Home</a></li>
 | 
				
			||||||
                    <a class="nav-link" href="/">Home</a>
 | 
					                <li class="nav-item"><a class="nav-link" href="/accounts">Accounts</a></li>
 | 
				
			||||||
                </li>
 | 
					                <li class="nav-item"><a class="nav-link" href="/urls">URLs</a></li>
 | 
				
			||||||
                <li class="nav-item">
 | 
					 | 
				
			||||||
                    <a class="nav-link" href="/accounts">Accounts</a>
 | 
					 | 
				
			||||||
                </li>
 | 
					 | 
				
			||||||
                <li class="nav-item">
 | 
					 | 
				
			||||||
                    <a class="nav-link" href="/urls">URLs</a>
 | 
					 | 
				
			||||||
                </li>
 | 
					 | 
				
			||||||
            </ul>
 | 
					            </ul>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    </nav>
 | 
					    </nav>
 | 
				
			||||||
@ -52,6 +44,7 @@
 | 
				
			|||||||
                        <th>Stream URL</th>
 | 
					                        <th>Stream URL</th>
 | 
				
			||||||
                        <th>Expiry Date</th>
 | 
					                        <th>Expiry Date</th>
 | 
				
			||||||
                        <th>Password</th>
 | 
					                        <th>Password</th>
 | 
				
			||||||
 | 
					                        <th>Actions</th>
 | 
				
			||||||
                    </tr>
 | 
					                    </tr>
 | 
				
			||||||
                </thead>
 | 
					                </thead>
 | 
				
			||||||
                <tbody>
 | 
					                <tbody>
 | 
				
			||||||
@ -62,8 +55,11 @@
 | 
				
			|||||||
                        <td>{{ account.stream }}</td>
 | 
					                        <td>{{ account.stream }}</td>
 | 
				
			||||||
                        <td><a href="{{ account.streamURL }}" target="_blank">{{ account.streamURL }}</a></td>
 | 
					                        <td><a href="{{ account.streamURL }}" target="_blank">{{ account.streamURL }}</a></td>
 | 
				
			||||||
                        <td>{{ account.expiaryDate_rendered }}</td>
 | 
					                        <td>{{ account.expiaryDate_rendered }}</td>
 | 
				
			||||||
                        <td class="password-cell" data-password="{{ account.password }}">
 | 
					                        <td class="password-cell password-blur" data-password="{{ account.password }}">********</td>
 | 
				
			||||||
                            <span class="password-blur">********</span>
 | 
					                        <td>
 | 
				
			||||||
 | 
					                            <button class="btn btn-danger delete-account-btn" data-stream="{{ account.stream }}" data-username="{{ account.username }}">
 | 
				
			||||||
 | 
					                                Delete
 | 
				
			||||||
 | 
					                            </button>
 | 
				
			||||||
                        </td>
 | 
					                        </td>
 | 
				
			||||||
                    </tr>
 | 
					                    </tr>
 | 
				
			||||||
                    {% endfor %}
 | 
					                    {% endfor %}
 | 
				
			||||||
@ -80,38 +76,66 @@
 | 
				
			|||||||
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.7/dist/umd/popper.min.js"></script>
 | 
					    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.7/dist/umd/popper.min.js"></script>
 | 
				
			||||||
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 | 
					    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 | 
				
			||||||
    <script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
 | 
					    <script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
 | 
				
			||||||
 | 
					    <script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
 | 
					        const authValue = "{{ auth | safe }}";  // Passing `auth` safely
 | 
				
			||||||
        $(document).ready(function() {
 | 
					        $(document).ready(function() {
 | 
				
			||||||
            // Custom sorting for dates in DD/MM/YYYY format
 | 
					 | 
				
			||||||
            $.fn.dataTable.ext.type.order['date-eu'] = function(data) {
 | 
					            $.fn.dataTable.ext.type.order['date-eu'] = function(data) {
 | 
				
			||||||
                const parts = data.split('/');
 | 
					                const parts = data.split('/');
 | 
				
			||||||
                return new Date(parts[2], parts[1] - 1, parts[0]).getTime();
 | 
					                return new Date(parts[2], parts[1] - 1, parts[0]).getTime();
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const table = $('#accountsTable').DataTable({
 | 
					            $('#accountsTable').DataTable({
 | 
				
			||||||
                "searching": true,
 | 
					                "searching": true,
 | 
				
			||||||
                "ordering": true,
 | 
					                "ordering": true,
 | 
				
			||||||
                "responsive": true, // Enable responsive layout
 | 
					                "responsive": true,
 | 
				
			||||||
                "columnDefs": [
 | 
					                "columnDefs": [
 | 
				
			||||||
                    { "type": "date-eu", "targets": 4 } // Column index for Expiry Date
 | 
					                    { "type": "date-eu", "targets": 4 }
 | 
				
			||||||
                ]
 | 
					                ]
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Use event delegation for password cell clicks
 | 
					 | 
				
			||||||
            $('#accountsTable tbody').on('click', '.password-cell', function() {
 | 
					            $('#accountsTable tbody').on('click', '.password-cell', function() {
 | 
				
			||||||
                const $cell = $(this);
 | 
					                const $cell = $(this);
 | 
				
			||||||
                const password = $cell.data('password');
 | 
					                $cell.text($cell.data('password'));
 | 
				
			||||||
                $cell.html(password); // Display the actual password
 | 
					                $cell.removeClass('password-blur');
 | 
				
			||||||
                $cell.removeClass('password-blur'); // Remove blur effect
 | 
					 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                // Add click outside event to blur it again
 | 
					                $(document).on('click.password', function(event) {
 | 
				
			||||||
                $(document).one('click', function(event) {
 | 
					 | 
				
			||||||
                    if (!$(event.target).closest('.password-cell').length) {
 | 
					                    if (!$(event.target).closest('.password-cell').length) {
 | 
				
			||||||
                        $cell.html('<span class="password-blur">********</span>'); // Restore blurred password
 | 
					                        $cell.text('********').addClass('password-blur');
 | 
				
			||||||
                        $cell.addClass('password-blur'); // Restore blur effect
 | 
					                        $(document).off('click.password');
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Delete functionality
 | 
				
			||||||
 | 
					            $('.delete-account-btn').click(async function() {
 | 
				
			||||||
 | 
					                const stream = $(this).data('stream');
 | 
				
			||||||
 | 
					                const username = $(this).data('username');
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                if (confirm(`Are you sure you want to delete account for stream: ${stream}, username: ${username}?`)) {
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        const response = await fetch('http://vps.k-world.me.uk:3001/deleteAccount', {
 | 
				
			||||||
 | 
					                            method: 'POST',
 | 
				
			||||||
 | 
					                            headers: {
 | 
				
			||||||
 | 
					                                'Content-Type': 'application/json',
 | 
				
			||||||
 | 
					                                'Authorization': 'Basic ' +  authValue  // Adjust auth here as needed
 | 
				
			||||||
 | 
					                            },
 | 
				
			||||||
 | 
					                            body: JSON.stringify({ stream, username })
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        const result = await response.json();
 | 
				
			||||||
 | 
					                        if (response.ok) {
 | 
				
			||||||
 | 
					                            alert(result.message);
 | 
				
			||||||
 | 
					                            $(this).closest('tr').remove();
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            alert(result.error || 'Failed to delete account');
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    } catch (error) {
 | 
				
			||||||
 | 
					                        console.error('Error deleting account:', error);
 | 
				
			||||||
 | 
					                        alert('Error occurred while deleting account');
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user