Skip to content

Commit

Permalink
Merge pull request #157 from SCCapstone/delete-pfp
Browse files Browse the repository at this point in the history
delete pfp
  • Loading branch information
Musa-Azeem authored Mar 31, 2024
2 parents d036f82 + 0d1b7fd commit e28ea5c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
15 changes: 15 additions & 0 deletions backend/app/account_settings_module/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,18 @@ def get_profile_picture_controller():
except:
return dict(error='Error Getting Profile Picture'), HTTPStatus.INTERNAL_SERVER_ERROR

def delete_profile_picture_controller():
try:
# Get the profile picture for the user
profile = Profile.query.get(current_user.email)

if not profile:
return dict(error='Profile picture not found'), HTTPStatus.NOT_FOUND

# Delete the profile picture from the database
db.session.delete(profile)
db.session.commit()

return dict(mssg='Profile Picture Deleted Successfully!'), HTTPStatus.OK
except:
return dict(error='Error Deleting Profile Picture'), HTTPStatus.INTERNAL_SERVER_ERROR
10 changes: 8 additions & 2 deletions backend/app/account_settings_module/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from app.account_settings_module.controller import (
update_password_controller,
update_profile_picture_controller,
get_profile_picture_controller
get_profile_picture_controller,
delete_profile_picture_controller
)

@blueprint.route('/update_password', methods=['POST'])
Expand All @@ -21,4 +22,9 @@ def update_profile_picture():
@blueprint.route('/get_profile_picture', methods=['GET'])
@login_required
def get_profile_picture():
return get_profile_picture_controller()
return get_profile_picture_controller()

@blueprint.route('/delete_profile_picture', methods=['DELETE'])
@login_required
def delete_profile_picture():
return delete_profile_picture_controller()
1 change: 1 addition & 0 deletions frontend/app/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = global.config = {

UPDATE_PROFILE_PICTURE_URL: BASE_URL + "update_profile_picture",
GET_PROFILE_PICTURE_URL: BASE_URL + "get_profile_picture",
DELETE_PROFILE_PICTURE_URL: BASE_URL + "delete_profile_picture",

USER_CREATION_URL: BASE_URL + "signup",
MANUAL_USER_CREATION_URL: BASE_URL + "manual_signup",
Expand Down
56 changes: 44 additions & 12 deletions frontend/app/src/pages/AccountSettings/AccountSettings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { UPDATE_PASSWORD_URL, UPDATE_PROFILE_PICTURE_URL, DELETE_EVALS_URL, DELETE_ALL_GRANTS_URL, DELETE_ALL_PUBS_URL, DELETE_ALL_EXPENS_URL, GET_PROFILE_PICTURE_URL } from '../../config';
import { UPDATE_PASSWORD_URL, UPDATE_PROFILE_PICTURE_URL, DELETE_EVALS_URL, DELETE_ALL_GRANTS_URL, DELETE_ALL_PUBS_URL, DELETE_ALL_EXPENS_URL, GET_PROFILE_PICTURE_URL, DELETE_PROFILE_PICTURE_URL } from '../../config';
import { useAuthContext } from '../../hooks/useAuthContext'
import { useCourseAnalyticsContext } from '../../hooks/useCourseAnalyticsContext';
import { useStudentEvalsContext } from '../../hooks/useStudentEvalsContext';
Expand Down Expand Up @@ -52,6 +52,8 @@ const AccountSettings = () => {
const [pictureFile, setPictureFile] = useState()
const [pictureProcessing, setPictureProcessing] = useState(false)

const [deletePictureError, setDeletePictureError] = useState(null)

const updatePassword = async (e) => {
e.preventDefault()

Expand Down Expand Up @@ -159,6 +161,28 @@ const AccountSettings = () => {
}
}

const handleDeletePicture = async (e) => {
const alertResponse = window.confirm("Are you sure you want to delete all student evaluation data? This cannot be undone.");
if (!alertResponse) {
return
}
e.preventDefault()
const response = await fetch(DELETE_PROFILE_PICTURE_URL, {
method: 'DELETE',
credentials: 'include',
headers: {'Content-Type': 'application/json'}
})
const json = await response.json()
if (!response.ok) {
setDeletePictureError(json.error)
}
if (response.ok) {
setDeletePictureError(null)
userDispatch({type: 'SET_PROFILE_PICTURE_URL', payload: null})
navigate('/account-settings', { state: { mssg: 'Profile picture deleted successfully', status: 'ok' }})
}
}

const deleteAllEvals = async (e) => {
e.preventDefault()
if (deleteEvalsConfirm !== confirmation_text) {
Expand Down Expand Up @@ -297,17 +321,6 @@ const AccountSettings = () => {
return (
<>
<h1 className="accountSettingsPageHeader">Account Settings</h1>
<section className="updatePasswordCard">
<h1>Update Profile Picture</h1>
<label>Please ensure your image is square for the best results</label>
<form onSubmit={handleSubmitPicture} className="evalupload-form">
<input type="file" onChange={handleChangePicture} className="evalupload-form-input" />
<button type="submit" className="evalupload-form-button">Upload</button>
{pictureError && <div className="errorField">{ pictureError }</div>}
{pictureProcessing && <p>Processing...</p>}
</form>
</section>


<section className="updatePasswordCard">
<h1>Update Password</h1>
Expand All @@ -331,6 +344,25 @@ const AccountSettings = () => {
</form>
</section>

<section className="updatePasswordCard">
<h1>Update Profile Picture</h1>
<label>Please ensure your image is square for the best results</label>
<form onSubmit={handleSubmitPicture} className="evalupload-form">
<input type="file" onChange={handleChangePicture} className="evalupload-form-input" />
<button type="submit" className="evalupload-form-button">Upload</button>
{pictureError && <div className="errorField">{ pictureError }</div>}
{pictureProcessing && <p>Processing...</p>}
</form>
</section>

<section className="updatePasswordCard">
<h1>Delete Profile Picture</h1>
<form onSubmit={handleDeletePicture} className="evalupload-form">
<button type="submit" className="evalupload-form-button">Delete Profile Picture</button>
{deletePictureError && <div className="errorField">{ deletePictureError }</div>}
</form>
</section>

<section className="updatePasswordCard">
<h1>Delete All Grants</h1>
<form className="updatePassword" onSubmit={ deleteAllGrants }>
Expand Down

0 comments on commit e28ea5c

Please sign in to comment.