Added a few controllers and views
This commit is contained in:
67
Views/AuthView/Login.cshtml
Normal file
67
Views/AuthView/Login.cshtml
Normal file
@@ -0,0 +1,67 @@
|
||||
@{
|
||||
ViewData["Title"] = "Login";
|
||||
}
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow">
|
||||
<div class="card-body p-5">
|
||||
<h2 class="text-center mb-4">Login</h2>
|
||||
|
||||
<form id="loginForm">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<p class="text-center">Don't have an account? <a asp-controller="AuthView" asp-action="Register">Register here</a></p>
|
||||
|
||||
<div id="message" class="mt-3"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const email = document.getElementById('email').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const messageDiv = document.getElementById('message');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ email, password })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
messageDiv.innerHTML = '<div class="alert alert-success">Login successful! Redirecting...</div>';
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 1500);
|
||||
} else {
|
||||
const error = await response.json();
|
||||
messageDiv.innerHTML = `<div class="alert alert-danger">${error.message}</div>`;
|
||||
}
|
||||
} catch (error) {
|
||||
messageDiv.innerHTML = `<div class="alert alert-danger">An error occurred: ${error.message}</div>`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user