Skip to content

Commit

Permalink
Updating local login and adding missing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
davetaz committed Jul 5, 2024
1 parent af9d46d commit 73c9376
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,45 @@ The tool will:

Please note: Suggestions from the AI assistant are provided for consideration and should be taken as presented.

## HubSpot Integration (ODI ONLY!)
### Authentication Methods

1. **Google Authentication**:
- Provides admin access.
- Admins have additional privileges, including the ability to change the local account password.
- Once logged in with Google, an option to change the local password will appear in the navigation tool bar.

2. **Django Authentication**:
- Represents users with accounts on the ODI website.
- These users have access to the tool based on their ODI membership.

3. **Local Accounts**:
- Equivalent to free accounts and are limited to the FREE_PROJECT_LIMIT.
- These accounts are designed for short-term use and demonstrations.

### Local Login for Test Accounts

The ODI Care Tool provides a local login feature for test accounts to facilitate easy demonstration and testing of the tool without requiring OAuth logins. Here's how it works:

- **Local Accounts Creation**: Local accounts can be created using a predefined password that is set for all test accounts. These accounts are intended for short-term use and demonstrations.
- **Password Reset**: The default password for local accounts can be reset through a secure form accessible after logging in with Google authentication. This reset process will also delete all existing local accounts and associated projects to ensure a clean slate for new demonstrations.
- **Daily Cleanup**: All local accounts and their associated projects are automatically deleted every day at 03:30 UTC. This cleanup ensures that local accounts are only used temporarily and do not persist beyond their intended short-term use.

#### Using the Local Login Feature

1. **Access the Reset Password Page**:
- Login with Google authentication to access the reset password option in the navigation tool bar.
- Navigate to the reset password page to view and change the current default password for local accounts.
- The current password is displayed on this page, and you can set a new password that will be applied to all local accounts.

2. **Resetting the Password**:
- Enter and confirm the new password.
- Upon submission, the current password will be updated, and all existing local accounts and projects will be deleted.
- The new password will then be used for any new local account logins.

3. **Automatic Daily Deletion**:
- Every day at 03:30 UTC, a scheduled task will run to delete all local accounts and their associated projects. This ensures that any test data does not persist longer than necessary.

### HubSpot Integration (ODI ONLY!)

The ODI Care Tool integrates with the ODI HubSpot to manage user memberships and track tool usage statistics. Ensure you have a valid HubSpot API key and set it in the `config.env` file. You can also set the FREE_PROJECT_LIMIT. This enables anyone to use the tool who has an account, no valid membership is required.

Expand Down
3 changes: 3 additions & 0 deletions config.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=/auth/google/callback

# Default local account password for demo/test accounts
DEFAULT_PASSWORD=defaultPassword1234

# Session Secret
SESSION_SECRET=your_session_secret

Expand Down
82 changes: 82 additions & 0 deletions views/pages/changeLocalPassword.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<%- include('../partials/header') %>
<section class="page-title light-blue content-block">
<h1>Reset Local Account Password</h1>
<b style="color: red;">WARNING:</b> This will also delete all existing local accounts and associated projects. This is the intended behaviour as local accounts are only to be used for short term demos. All local accounts are deleted every day at 03:30 UTC.</p>
</section>
<section class="content-block light-blue">
<div class="reset-password-form-container">
<form id="resetPasswordForm">
<div class="form-group">
<label for="currentPassword">Current Password:</label>
<input type="text" id="currentPassword" readonly>
</div>
<div class="form-group">
<label for="newPassword">New Password:</label>
<input type="text" name="newPassword" id="newPassword" required>
</div>
<div class="form-group">
<label for="confirmPassword">Confirm New Password:</label>
<input type="text" name="confirmPassword" id="confirmPassword" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Reset Password</button>
</div>
<div id="error-message" style="color: red;"></div>
<div id="success-message" style="color: green;"></div>
</form>
</div>
</section>
<%- include('../partials/footer') %>

<script>
document.addEventListener('DOMContentLoaded', async function() {
try {
const response = await fetch('/auth/local/password');
const data = await response.json();
document.getElementById('currentPassword').value = data.currentPassword;
} catch (error) {
console.error('Error fetching current password:', error);
}
});
document.getElementById('resetPasswordForm').addEventListener('submit', async function(event) {
event.preventDefault();
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
const errorMessage = document.getElementById('error-message');
const successMessage = document.getElementById('success-message');
const currentPasswordField = document.getElementById('currentPassword');
if (newPassword !== confirmPassword) {
errorMessage.textContent = 'Passwords do not match.';
return;
}
errorMessage.textContent = ''; // Clear any previous error message
try {
const response = await fetch('/auth/local/password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ newPassword })
});
if (response.ok) {
const result = await response.json();
successMessage.textContent = result.message || 'Password reset successfully.';
currentPasswordField.value = newPassword;
document.getElementById('newPassword').value = '';
document.getElementById('confirmPassword').value = '';
} else {
const result = await response.json();
errorMessage.textContent = result.message || 'An error occurred while resetting the password.';
}
} catch (error) {
console.error('Error:', error);
errorMessage.textContent = 'An unexpected error occurred.';
}
});
</script>
22 changes: 22 additions & 0 deletions views/pages/localLogin.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%- include('../partials/header') %>
<section class="page-title light-blue content-block">
<h1>Login</h1>
</section>
<section class="content-block light-blue">
<div class="login-form-container">
<form action="/auth/local" method="post">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" name="password" id="password" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</section>
<%- include('../partials/footer') %>

0 comments on commit 73c9376

Please sign in to comment.