Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def result():
except Exception as e:
print(e)
# print(len(constraints))
{{ ingredient_db[selected_ingredients[i]]["Price"] }}
{% for i in range( 0, lengthOfIngredients): %}
#{{ ingredient_db[selected_ingredients[i]]["Price"] }}
#{% for i in range( 0, lengthOfIngredients): %}


# for name in ingredient_names:
Expand Down
3 changes: 1 addition & 2 deletions templates/feed_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,4 @@ <h3>Select Ingredients</h3>
}
</script>
</body>
</html>
g
</html>
168 changes: 164 additions & 4 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,169 @@
<!DOCTYPE html>
<html>
<head></head>
<head>
<title>Login</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: white;
padding: 40px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 300px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
color: #555;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.login-btn {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.login-btn:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h1>Hello Flask</h1>
<p>{{ result }}</p>
<div class="login-container">
<h1>Login</h1>
<form>
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button id="submitButton" class="login-btn">Login</button>
</form>
</div>
</body>

<script>
var submitBtn = document.querySelector('#submitButton');
var usernameInput = document.querySelector('#username');
var passwordInput = document.querySelector('#password');

submitBtn.addEventListener('click', function(e) {
e.preventDefault(); // Prevent form submission

// Clear previous error messages
clearErrorMessages();

// Get form values
var username = usernameInput.value.trim();
var password = passwordInput.value.trim();

// Validation flags
var isValid = true;

// Username validation
if (username === '') {
showError('username', 'Username is required');
isValid = false;
} else if (username.length < 3) {
showError('username', 'Username must be at least 3 characters');
isValid = false;
}

// Password validation
if (password === '') {
showError('password', 'Password is required');
isValid = false;
} else if (password.length < 6) {
showError('password', 'Password must be at least 6 characters');
isValid = false;
}

// If validation passes, redirect to form
if (isValid) {
// Show success message briefly
showSuccess('Login successful! Redirecting...');
setTimeout(function() {
window.location.href = "http://localhost:5000/form";
}, 1000);
}
});

function showError(fieldId, message) {
var field = document.getElementById(fieldId);
var errorDiv = document.createElement('div');
errorDiv.className = 'error-message';
errorDiv.textContent = message;
errorDiv.style.color = '#dc3545';
errorDiv.style.fontSize = '14px';
errorDiv.style.marginTop = '5px';

// Add red border to input
field.style.borderColor = '#dc3545';

// Insert error message after the input
field.parentNode.insertBefore(errorDiv, field.nextSibling);
}

function showSuccess(message) {
var successDiv = document.createElement('div');
successDiv.className = 'success-message';
successDiv.textContent = message;
successDiv.style.color = '#28a745';
successDiv.style.fontSize = '16px';
successDiv.style.textAlign = 'center';
successDiv.style.marginTop = '10px';
successDiv.style.fontWeight = 'bold';

// Insert success message after the form
var form = document.querySelector('form');
form.parentNode.insertBefore(successDiv, form.nextSibling);
}

function clearErrorMessages() {
// Remove existing error messages
var errorMessages = document.querySelectorAll('.error-message');
errorMessages.forEach(function(msg) {
msg.remove();
});

// Remove existing success messages
var successMessages = document.querySelectorAll('.success-message');
successMessages.forEach(function(msg) {
msg.remove();
});

// Reset input borders
usernameInput.style.borderColor = '#ddd';
passwordInput.style.borderColor = '#ddd';
}
</script>
</html>