Skip to content
Snippets Groups Projects
Select Git revision
  • cd8e4a1d15a8fc773a9c3201b9725a5c7d8f6d41
  • main default protected
2 results

login.html

Blame
  • Forked from LSDS / Teaching / Bachelor / Cloud-and-Deployment / Project -- Web SSO with KinD
    Source project has a limited visibility.
    login.html 3.38 KiB
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Login</title>
            <style>
             body {
                 font-family: Arial, sans-serif;
                 display: flex;
                 justify-content: center;
                 align-items: center;
                 height: 100vh;
                 margin: 0;
                 background-color: #f0f2f5;
             }
             .container {
                 padding: 20px;
                 background-color: white;
                 border-radius: 8px;
                 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
             }
             .form-group {
                 margin-bottom: 15px;
             }
             label {
                 display: block;
                 margin-bottom: 5px;
             }
             input {
                 width: 100%;
                 padding: 8px;
                 border: 1px solid #ddd;
                 border-radius: 4px;
                 box-sizing: border-box;
             }
             .button {
                 width: 100%;
                 padding: 10px;
                 border: none;
                 border-radius: 5px;
                 background-color: #1877f2;
                 color: white;
                 cursor: pointer;
             }
             .button:hover {
                 background-color: #166fe5;
             }
             .back-link {
                 display: block;
                 margin-top: 15px;
                 text-align: center;
                 color: #1877f2;
                 text-decoration: none;
             }
            </style>
        </head>
        <body>
            <div class="container">
                <h2>Login</h2>
                <form id="loginForm">
                    <div class="form-group">
                        <label for="email">Email:</label>
                        <input type="email" id="email" name="email" required>
                    </div>
                    <div class="form-group">
                        <label for="password">Password:</label>
                        <input type="password" id="password" name="password" required>
                    </div>
                    <button type="submit" class="button">Login</button>
                </form>
                <a href="index.html" class="back-link">Back to Home</a>
            </div>
    
            <script>
             document.getElementById('loginForm').addEventListener('submit', async (e) => {
                 e.preventDefault();
                 const email = document.getElementById('email').value;
                 const password = document.getElementById('password').value;
    
                 try {
                     const response = await fetch('http://localhost:8000/login', {
                         method: 'POST',
                         headers: {
                             'Content-Type': 'application/json',
                         },
                         body: JSON.stringify({ email, password }),
                     });
                     const data = await response.json();
    
                     if (data.status === 'OK:LOGGED_IN') {
                         localStorage.setItem('userEmail', email);
                         window.location.href = 'dashboard.html';
                     } else if (data.status === 'OK:NEED_PASSWORD') {
    					 localStorage.setItem('userEmail', email);
    					 alert('Please provide your password');
    				 } else {
                         alert('Login failed: ' + data.status);
                     }
                 } catch (error) {
                     alert('Error during login. ' + error);
                 }
             });
            </script>
        </body>
    </html>