283 lines
8.1 KiB
HTML
283 lines
8.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Authentication - Artifactory</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.login-container {
|
|
background: white;
|
|
padding: 2rem;
|
|
border-radius: 10px;
|
|
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.login-header h1 {
|
|
color: #333;
|
|
margin-bottom: 0.5rem;
|
|
font-size: 2rem;
|
|
}
|
|
|
|
.login-header p {
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: #333;
|
|
font-weight: 500;
|
|
}
|
|
|
|
input[type="text"],
|
|
input[type="password"] {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e1e1e1;
|
|
border-radius: 6px;
|
|
font-size: 1rem;
|
|
transition: border-color 0.3s ease;
|
|
}
|
|
|
|
input[type="text"]:focus,
|
|
input[type="password"]:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.login-button {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: transform 0.2s ease;
|
|
}
|
|
|
|
.login-button:hover {
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.login-button:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.alert {
|
|
padding: 12px;
|
|
margin-bottom: 1rem;
|
|
border-radius: 6px;
|
|
display: none;
|
|
}
|
|
|
|
.alert-error {
|
|
background-color: #f8d7da;
|
|
border: 1px solid #f5c6cb;
|
|
color: #721c24;
|
|
}
|
|
|
|
.alert-success {
|
|
background-color: #d4edda;
|
|
border: 1px solid #c3e6cb;
|
|
color: #155724;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.spinner {
|
|
border: 3px solid #f3f3f3;
|
|
border-top: 3px solid #667eea;
|
|
border-radius: 50%;
|
|
width: 30px;
|
|
height: 30px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.footer {
|
|
text-align: center;
|
|
margin-top: 2rem;
|
|
padding-top: 1rem;
|
|
border-top: 1px solid #e1e1e1;
|
|
color: #666;
|
|
font-size: 0.8rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-header">
|
|
<h1>🔐 Sign In</h1>
|
|
<p>Access Artifactory Services</p>
|
|
</div>
|
|
|
|
<div id="alert" class="alert"></div>
|
|
|
|
<form id="loginForm">
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input type="text" id="username" name="username" required placeholder="Enter your domain username">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" required placeholder="Enter your password">
|
|
</div>
|
|
|
|
<button type="submit" class="login-button" id="loginButton">
|
|
Sign In
|
|
</button>
|
|
</form>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p>Authenticating...</p>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Use your Active Directory credentials</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const loginForm = document.getElementById('loginForm');
|
|
const loginButton = document.getElementById('loginButton');
|
|
const loading = document.getElementById('loading');
|
|
const alert = document.getElementById('alert');
|
|
|
|
function showAlert(message, type = 'error') {
|
|
alert.className = `alert alert-${type}`;
|
|
alert.textContent = message;
|
|
alert.style.display = 'block';
|
|
}
|
|
|
|
function hideAlert() {
|
|
alert.style.display = 'none';
|
|
}
|
|
|
|
function setLoading(isLoading) {
|
|
if (isLoading) {
|
|
loginButton.disabled = true;
|
|
loginButton.textContent = 'Signing In...';
|
|
loading.style.display = 'block';
|
|
} else {
|
|
loginButton.disabled = false;
|
|
loginButton.textContent = 'Sign In';
|
|
loading.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
function storeToken(token) {
|
|
// Store token in localStorage for client-side access
|
|
localStorage.setItem('auth_token', token);
|
|
localStorage.setItem('auth_timestamp', new Date().getTime());
|
|
}
|
|
|
|
function redirectToApp() {
|
|
// Redirect to the main application or dashboard
|
|
const returnUrl = new URLSearchParams(window.location.search).get('return_url');
|
|
window.location.href = returnUrl || '/dashboard';
|
|
}
|
|
|
|
loginForm.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
hideAlert();
|
|
setLoading(true);
|
|
|
|
const formData = new FormData(loginForm);
|
|
|
|
try {
|
|
const response = await fetch('/auth/login', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
// Store token if provided in header
|
|
const token = response.headers.get('X-Auth-Token');
|
|
if (token) {
|
|
storeToken(token);
|
|
}
|
|
|
|
showAlert(`Welcome back, ${data.user.display_name || data.user.username}!`, 'success');
|
|
|
|
// Redirect after a short delay
|
|
setTimeout(() => {
|
|
redirectToApp();
|
|
}, 1500);
|
|
} else {
|
|
showAlert(data.message || 'Login failed');
|
|
}
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
showAlert('Network error. Please try again.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
});
|
|
|
|
// Check if user is already authenticated
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
try {
|
|
const response = await fetch('/auth/user', {
|
|
credentials: 'include'
|
|
});
|
|
|
|
if (response.ok) {
|
|
const user = await response.json();
|
|
showAlert(`Already signed in as ${user.display_name || user.username}`, 'success');
|
|
setTimeout(() => {
|
|
redirectToApp();
|
|
}, 1500);
|
|
}
|
|
} catch (error) {
|
|
// User not authenticated, show login form
|
|
console.log('User not authenticated');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |