Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

91 implements avatar for users #247

Merged
merged 28 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1ab26c2
feat: add avatar ImageField to user model
aurlic Oct 9, 2024
c400d12
feat: profile file
aurlic Oct 9, 2024
b338e03
feat: views and url for profile
aurlic Oct 9, 2024
17d5b37
tmp
aurlic Oct 9, 2024
06b447d
close profile template block
Neffi42 Oct 9, 2024
7535cb9
wip: with code
aurlic Oct 10, 2024
c842cac
feat: migration for avatars
aurlic Oct 10, 2024
5dd449f
Serve media with Django
aurlic Oct 10, 2024
507d1bb
remove useless line
aurlic Oct 10, 2024
a028803
feat: front for profile card
aurlic Oct 13, 2024
fd6009c
fix: merge from main, need to fix appearance
aurlic Oct 14, 2024
e6f9b37
feat: fron for profile page done
aurlic Oct 14, 2024
e061b4f
refactor: new password forms, modal for avatar change
aurlic Oct 14, 2024
30ae14c
feat: password change form
aurlic Oct 15, 2024
64f527a
feat: front for modal done
aurlic Oct 15, 2024
f038719
wip
aurlic Oct 15, 2024
801d561
fix MEDIA_ROOT
Neffi42 Oct 15, 2024
b58206e
fix: spaces to tabs
aurlic Oct 15, 2024
7709407
change default avatar
aurlic Oct 16, 2024
21966af
feat: image size limit set to 2mb
aurlic Oct 16, 2024
cab32b9
refactor: name change for settings
aurlic Oct 16, 2024
1e33521
merge with main
aurlic Oct 16, 2024
438d1b0
fix: duplicate attributes
aurlic Oct 16, 2024
7f37c2b
removed duplicate function
aurlic Oct 16, 2024
c237b06
fix: display change to hidden
aurlic Oct 16, 2024
d42776c
fix: protecting max file size in views
aurlic Oct 16, 2024
88e7c23
deletion of useless check
aurlic Oct 16, 2024
6049901
fix: remove unecessary display attribute
aurlic Oct 16, 2024
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
6 changes: 3 additions & 3 deletions django/src/ft_auth/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
</div>

<div id="avatarModal" class="modal-overlay" style="display:none;">
<div id="avatarModal" class="modal-overlay hidden">
<div class="modal-content">
<button type="button" class="close-button" id="closeModalBtn">&times;</button>
<h2 class="form-title">Upload New Avatar</h2>
Expand All @@ -66,12 +66,12 @@ <h2 class="form-title">Upload New Avatar</h2>
<script>
function showModal() {
const modal = document.getElementById('avatarModal');
modal.style.display = 'block';
modal.classList.remove("hidden");
}

function hideModal() {
const modal = document.getElementById('avatarModal');
modal.style.display = 'none';
modal.classList.add("hidden");
}

function validate() {
Expand Down
9 changes: 5 additions & 4 deletions django/src/ft_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ def password_update(request: HttpRequest):
logger.info(f"Updated password of {request.user.username}.")
return HttpResponse(status=200)

@require_POST
def upload_avatar(request):
max_file_size = 2 * 1024 * 1024
if request.FILES.get('avatar'):
antoineverin marked this conversation as resolved.
Show resolved Hide resolved
avatar_file = request.FILES['avatar']
if avatar_file.size > max_file_size:
return JsonResponse({'error': 'File size exceeds 2MB limit.'}, status=400)
user = request.user
user.avatar = avatar_file
user.avatar.save(avatar_file.name, avatar_file)
user.save()
return JsonResponse({'avatar_url': user.avatar.url}, status=200)

return JsonResponse({'error': 'No avatar file provided'}, status=400)
return JsonResponse({'error': 'Invalid request'}, status=400)

@require_POST
def authorize(request: HttpRequest):
Expand Down
2 changes: 0 additions & 2 deletions django/src/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,5 @@ def profiles(request: HttpRequest, username: str):

@require_GET
def settings(request: HttpRequest):
if not request.user.is_authenticated:
return JsonResponse({'redirect': '/'}, status=403)
return create_response(request, 'settings.html', title="Settings", need_authentication=True)

5 changes: 1 addition & 4 deletions nginx/src/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
justify-content: center;
align-items: center;
z-index: 1000;
display: none;
display: hidden;
aurlic marked this conversation as resolved.
Show resolved Hide resolved
}

.modal-content {
Expand Down Expand Up @@ -242,14 +242,11 @@
.file-name {
display: inline-block;
max-width: 200px;
/* Adjust this width as needed */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
margin-left: 10px;
/* Add space between the label and the file name */
font-size: 0.9em;
color: #555;
/* Optional: adjust the text color */
}
Loading