Skip to content

Commit

Permalink
2fa finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Ville Mustonen authored and Ville Mustonen committed Aug 22, 2024
1 parent abe3539 commit d59a4c8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Frontend/src/js/modals/changeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function handleEmailUpdate(userData) {
})
.catch(error => {
console.error('Error:', error);
showMessage('Error updating email', '#ProfileModal', 'error');
showMessage('Error sending verification code', '#ProfileModal', 'error');
});
});

Expand Down
66 changes: 66 additions & 0 deletions Frontend/src/js/modals/changeProfilePicture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { showMessage } from './messages.js';

// Function to toggle the profile picture update form visibility
export function toggleProfilePictureForm() {
const imageUploadForm = document.getElementById('imageUploadForm');
if (imageUploadForm.style.display === 'none' || imageUploadForm.style.display === '') {
imageUploadForm.style.display = 'flex';
imageUploadForm.style.flexDirection = 'column';
} else {
imageUploadForm.style.display = 'none';
}
}

// Function to handle the profile picture update process
export function handleProfilePictureUpdate(userData) {
document.getElementById('imageInput').addEventListener('change', (event) => {
const fileInput = event.target;
const fileNameDisplay = document.getElementById('fileName');
if (fileInput.files.length > 0) {
fileNameDisplay.textContent = fileInput.files[0].name;
} else {
fileNameDisplay.textContent = 'No file chosen';
}
});

document.getElementById('imageUploadForm').addEventListener('submit', (event) => {
event.preventDefault();
const imageInput = document.getElementById('imageInput');
const file = imageInput.files[0];
if (!file) {
console.error('No image selected');
showMessage('No image selected', '#ProfileModal', 'error');
return;
}
const formData = new FormData();
formData.append('avatar', file);

fetch(`/user/${userData.id}/`, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${userData.token}`
},
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Image uploaded successfully:', data);
showMessage('Profile picture updated successfully', '#ProfileModal', 'accept');
document.getElementById('avatar').src = `${data.avatar}?t=${new Date().getTime()}`;
document.getElementById('imageUploadForm').style.display = 'none';
document.getElementById('imageInput').value = '';
document.getElementById('fileName').textContent = 'No file chosen';
})
.catch(error => {
console.error('Error uploading image:', error);
showMessage('Error uploading image', '#ProfileModal', 'error');
document.getElementById('imageInput').value = '';
document.getElementById('fileName').textContent = 'No file chosen';
});
});
}
2 changes: 1 addition & 1 deletion Frontend/src/js/modals/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ function handleOtpVerification(event, username, password) {
}

function completeLogin(data) {
document.getElementById('loginVerificationCode').value = '';
showMessage('Login successful', '#loginModal', 'accept');
sessionStorage.setItem('userData', JSON.stringify({ id: data.id, token: data.access, refresh: data.refresh }));
sessionStorage.setItem('isLoggedIn', 'true');
setTimeout(() => {
document.getElementById('loginVerificationCode').value = '';
document.getElementById('loginModal').querySelector('.close').click();
document.getElementById('loginForm').reset();
document.getElementById('loginVerification').style.display = 'none';
Expand Down
Empty file removed Frontend/src/js/modals/logout.js
Empty file.

0 comments on commit d59a4c8

Please sign in to comment.