speakmore-2.0/templates/login.html

60 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
{% include 'head.html' %}
</head>
<body class="login-body">
<div class="login-div">
<form class="login-form" id="login-form" method="POST">
<img class="login-img" src="{{ url_for('static', filename='images/ms-style-logo.svg') }}" alt="Image">
<h2 class="login-h2">Sign in</h2>
<div class="login-input-div-first">
<input class="login-input" type="text" class="form-control" id="username" name="username" placeholder="Username" required autocomplete="off">
</div>
<div class="login-input-div-rest">
<input class="login-input" type="password" class="form-control" id="password" name="password" placeholder="Password" required autocomplete="off">
</div>
<div class="login-input-div-first !flex-row">
<p class="no-account">No account? </p><a class="no-account no-account-button" href="{{ url_for('register') }}"> Create one!</a>
</div>
<div id="error-message" style="color: red; margin-top: 10px;"></div>
<div class="login-input-div-first items-end">
<button class="ms-button-signin" type="submit" class="btn btn-primary">Next</button>
</div>
</form>
</div>
<!-- <div class="ms-p !w-[440px] !h-fit bg-white relative top-2 p-3 pl-10 pr-10 !flex-row !justify-start items-center">
<i class="fa-solid fa-key text-black pr-2"></i>
<p class="text-black text-sm">Sign-in options</p>
</div> -->
<script>
document.getElementById('login-form').addEventListener('submit', function(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
// Convert username to lowercase
const username = formData.get('username').toLowerCase();
formData.set('username', username);
axios.post('/login', formData)
.then(response => {
if (response.data.status === 'success') {
window.location.href = '/dashboard';
} else if (response.data.message === 'Account Disabled. Contact Support') {
alert('Account Disabled. Contact Support');
} else {
alert('Invalid credentials. Please try again.');
}
})
.catch(error => {
console.error('Error logging in:', error);
alert('An error occurred. Please try again.');
});
});
</script>
</body>
</html>