Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body {
height: 100vh;
}

.form {
.login-mask {
background-color: #fff;
padding: 2em;
border-radius: 5px;
Expand All @@ -28,7 +28,7 @@ h1 {
margin-bottom: 1em;
}

.form-control {
.login-mask-control {
margin-bottom: 1em;
display: flex;
flex-direction: column;
Expand Down
26 changes: 14 additions & 12 deletions assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
</head>
<body>
<div class="container">
<div class="form" id="form">
<div class="login-mask" id="login-mask">
<div class="alert">
<p id="alert-message"></p>
</div>
<h1>Login</h1>
<div class="form-control">
<label for="username">Username</label>
<input type="text" id="username" name="username" autocomplete="username" required autofocus>
</div>
<div class="form-control">
<label for="password">Password</label>
<input type="password" id="password" name="password" autocomplete="current-password" required>
</div>
<div class="button-container">
<button id="submit">Submit</button>
</div>
<form>
<div class="login-mask-control">
<label for="username">Username</label>
<input type="text" id="username" name="username" autocomplete="username" required autofocus>
</div>
<div class="login-mask-control">
<label for="password">Password</label>
<input type="password" id="password" name="password" autocomplete="current-password" required>
</div>
<div class="button-container">
<button id="submit" type="submit">Submit</button>
</div>
</form>
</div>
</body>
</html>
6 changes: 4 additions & 2 deletions assets/html/logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
</head>
<body>
<div class="container">
<div class="form">
<div class="login-mask">
<div class="alert">
<p id="alert-message"></p>
</div>
<h1>Authorized</h1>
<div class="button-container">
<button id="submit">Logout</button>
<form>
<button id="submit" type="submit">Logout</button>
</form>
</div>
</div>
</body>
Expand Down
12 changes: 8 additions & 4 deletions assets/js/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const handleError = (err) => {
// Unexpected error occurred, show alert
displayAlert("Unexpected error occurred.", "error");
console.log("Error occurred", err);
setFieldsDisabled(false);
};

const handleResponse = (res) => {
Expand All @@ -43,7 +44,10 @@ const handleResponse = (res) => {
};

// Logout function
const logout = () => {
const logout = (event) => {
// override default form behaviour
event.preventDefault();

// Disable fields until after request
setFieldsDisabled(true);

Expand All @@ -62,9 +66,9 @@ const setFieldsDisabled = (disabled) => {
document.getElementById("submit").disabled = disabled;
};

// Configure submit button click to trigger login
const submitButton = document.getElementById("submit");
submitButton.onclick = logout;
// Configure form to trigger logout
var form = document.querySelector("form");
form.onsubmit = logout;

// Set banner if just logged in
if (params.success) {
Expand Down
32 changes: 10 additions & 22 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const displayAlert = (msg, variant) => {
}, 10);
};

const handleError = () => {
const handleError = (err) => {
// Unexpected error occurred, show alert
displayAlert("Unexpected error occurred.", "error");
console.log("Error occurred", err);
setFieldsDisabled(false);
};

const handleResponse = (res) => {
Expand Down Expand Up @@ -47,17 +49,14 @@ const handleResponse = (res) => {
};

// Login function
const login = () => {
const login = (event) => {
// override default form behaviour
event.preventDefault();

// Get form values
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;

// Validation
if (username == "" || password == "") {
alert("Please make sure all fields are filled.");
return;
}

// Create data object to send
const data = {
username,
Expand All @@ -84,17 +83,6 @@ const setFieldsDisabled = (disabled) => {
document.getElementById("submit").disabled = disabled;
};

// Configure submit button click to trigger login
const submitButton = document.getElementById("submit");
submitButton.onclick = login;

// Configure ENTER key-press to trigger login
const form = document.getElementById("form");
form.addEventListener('keydown', (e) => {
// Listen to 'keydown' event and check if Enter key
if (e.key === 'Enter') {
// Prevent default and trigger login
e.preventDefault();
login();
}
});
// Configure form to trigger login
var form = document.querySelector("form");
form.onsubmit = login;