mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
df420e8331
Signed-off-by: 5t4l1n <stalin78830@gmail.com>
285 lines
8.9 KiB
HTML
285 lines
8.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>BlockChat Login</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
font-family: 'Segoe UI', sans-serif;
|
|
}
|
|
|
|
.login-container {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.login-card {
|
|
background: white;
|
|
border-radius: 20px;
|
|
padding: 40px;
|
|
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
|
max-width: 500px;
|
|
width: 100%;
|
|
}
|
|
|
|
.app-header {
|
|
text-align: center;
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.app-logo {
|
|
font-size: 80px;
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.app-title {
|
|
font-size: 32px;
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.app-subtitle {
|
|
color: #666;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.status-box {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 10px;
|
|
padding: 15px;
|
|
margin: 20px 0;
|
|
text-align: center;
|
|
}
|
|
|
|
.status-box.connected {
|
|
background: #d1ecf1;
|
|
border-color: #bee5eb;
|
|
color: #0c5460;
|
|
}
|
|
|
|
.status-box.error {
|
|
background: #f8d7da;
|
|
border-color: #f5c6cb;
|
|
color: #721c24;
|
|
}
|
|
|
|
.accounts-title {
|
|
font-size: 18px;
|
|
color: #333;
|
|
margin: 30px 0 15px 0;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.account-card {
|
|
background: #f8f9fa;
|
|
border: 2px solid #e9ecef;
|
|
border-radius: 15px;
|
|
padding: 20px;
|
|
margin: 10px 0;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.account-card:hover {
|
|
border-color: #667eea;
|
|
background: #e3f2fd;
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.account-card.selected {
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
border-color: #667eea;
|
|
color: white;
|
|
}
|
|
|
|
.account-name {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
margin-bottom: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.account-address {
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 12px;
|
|
opacity: 0.8;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.login-btn {
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 50px;
|
|
padding: 15px 30px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
width: 100%;
|
|
margin-top: 30px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.login-btn:hover:not(:disabled) {
|
|
background: linear-gradient(135deg, #5a67d8, #6b46c1);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.login-btn:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-card">
|
|
<div class="app-header">
|
|
<div class="app-logo">
|
|
<i class="fas fa-comments"></i>
|
|
</div>
|
|
<h1 class="app-title">BlockChat</h1>
|
|
<p class="app-subtitle">Secure blockchain messaging</p>
|
|
</div>
|
|
|
|
<div class="status-box error" id="statusBox">
|
|
<i class="fas fa-spinner fa-spin me-2"></i>
|
|
<span>Connecting to blockchain...</span>
|
|
</div>
|
|
|
|
<div id="accountsSection" style="display: none;">
|
|
<h3 class="accounts-title">Select Your Account</h3>
|
|
<div id="accountsList"></div>
|
|
</div>
|
|
|
|
<button class="login-btn" id="loginBtn" onclick="startChat()" disabled>
|
|
<i class="fas fa-rocket me-2"></i>
|
|
Enter BlockChat
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.7.4/web3.min.js"></script>
|
|
<script>
|
|
let web3;
|
|
let selectedAccount = null;
|
|
let accounts = [];
|
|
|
|
// Start when page loads
|
|
window.addEventListener('load', function() {
|
|
console.log('🚀 Starting BlockChat login...');
|
|
connectToBlockchain();
|
|
});
|
|
|
|
async function connectToBlockchain() {
|
|
try {
|
|
console.log('🔗 Connecting to Anvil blockchain...');
|
|
|
|
// Connect to Anvil
|
|
web3 = new Web3('http://127.0.0.1:8545');
|
|
|
|
// Test connection
|
|
const isListening = await web3.eth.net.isListening();
|
|
if (!isListening) {
|
|
throw new Error('Cannot connect to Anvil');
|
|
}
|
|
|
|
// Get accounts
|
|
accounts = await web3.eth.getAccounts();
|
|
console.log('✅ Found', accounts.length, 'accounts');
|
|
|
|
if (accounts.length === 0) {
|
|
throw new Error('No accounts found');
|
|
}
|
|
|
|
// Update status
|
|
updateStatus(true, `Connected! Found ${accounts.length} accounts`);
|
|
|
|
// Show accounts
|
|
showAccounts();
|
|
|
|
} catch (error) {
|
|
console.error('❌ Connection failed:', error);
|
|
updateStatus(false, 'Connection failed - Make sure Anvil is running');
|
|
}
|
|
}
|
|
|
|
function updateStatus(connected, message) {
|
|
const statusBox = document.getElementById('statusBox');
|
|
|
|
if (connected) {
|
|
statusBox.className = 'status-box connected';
|
|
statusBox.innerHTML = `<i class="fas fa-check-circle me-2"></i><span>${message}</span>`;
|
|
} else {
|
|
statusBox.className = 'status-box error';
|
|
statusBox.innerHTML = `<i class="fas fa-exclamation-triangle me-2"></i><span>${message}</span>`;
|
|
}
|
|
}
|
|
|
|
function showAccounts() {
|
|
const accountsSection = document.getElementById('accountsSection');
|
|
const accountsList = document.getElementById('accountsList');
|
|
|
|
let html = '';
|
|
accounts.forEach((account, index) => {
|
|
html += `
|
|
<div class="account-card" onclick="selectAccount('${account}', ${index})">
|
|
<div class="account-name">
|
|
<i class="fas fa-wallet me-2"></i>
|
|
Account ${index + 1}
|
|
</div>
|
|
<div class="account-address">${account}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
accountsList.innerHTML = html;
|
|
accountsSection.style.display = 'block';
|
|
}
|
|
|
|
function selectAccount(account, index) {
|
|
selectedAccount = account;
|
|
console.log('📝 Selected account:', account);
|
|
|
|
// Update visual selection
|
|
document.querySelectorAll('.account-card').forEach(card => {
|
|
card.classList.remove('selected');
|
|
});
|
|
document.querySelectorAll('.account-card')[index].classList.add('selected');
|
|
|
|
// Enable login button
|
|
document.getElementById('loginBtn').disabled = false;
|
|
}
|
|
|
|
function startChat() {
|
|
if (!selectedAccount) {
|
|
alert('Please select an account first!');
|
|
return;
|
|
}
|
|
|
|
console.log('🚀 Starting chat with account:', selectedAccount);
|
|
|
|
// Store selected account
|
|
localStorage.setItem('myaddress', selectedAccount);
|
|
|
|
// Navigate to chat
|
|
window.location.href = 'account.html';
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|