From a26784cd98c33d62330816eec64185fde253cd96 Mon Sep 17 00:00:00 2001 From: Arthur-TRT Date: Tue, 29 Mar 2022 11:02:07 +0200 Subject: [PATCH 1/9] First version of 42Oauth --- .../migrations/0008_auto_20220329_1034.py | 23 +++++++ src/accounts/models.py | 2 + src/accounts/templates/accounts/edit.html | 17 ++++- src/accounts/urls.py | 9 ++- src/accounts/views/connection.py | 66 ++++++++++++++++--- src/ctfs/templates/challenges | 2 +- 6 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 src/accounts/migrations/0008_auto_20220329_1034.py diff --git a/src/accounts/migrations/0008_auto_20220329_1034.py b/src/accounts/migrations/0008_auto_20220329_1034.py new file mode 100644 index 0000000..0578d14 --- /dev/null +++ b/src/accounts/migrations/0008_auto_20220329_1034.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.11 on 2022-03-29 08:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0007_auto_20220123_1704'), + ] + + operations = [ + migrations.AddField( + model_name='userprofileinfo', + name='intra42_campus', + field=models.CharField(blank=True, max_length=50, null=True), + ), + migrations.AddField( + model_name='userprofileinfo', + name='intra42_id', + field=models.CharField(blank=True, max_length=20, null=True, unique=True), + ), + ] diff --git a/src/accounts/models.py b/src/accounts/models.py index b82988e..5f8a869 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -12,6 +12,8 @@ class UserProfileInfo(models.Model): last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now) token = models.CharField(max_length=200, blank=True) discord_id = models.CharField(max_length=20, null=True, blank=True, unique=True) + intra42_id = models.CharField(max_length=20, null=True, blank=True, unique=True) + intra42_campus = models.CharField(max_length=50, null=True, blank=True) member = models.BooleanField(default=False) member_since = models.DateTimeField('Member since', default=timezone.now) member_until = models.DateTimeField('Member until', default=timezone.now) diff --git a/src/accounts/templates/accounts/edit.html b/src/accounts/templates/accounts/edit.html index 0e1c474..2af6d04 100644 --- a/src/accounts/templates/accounts/edit.html +++ b/src/accounts/templates/accounts/edit.html @@ -60,6 +60,21 @@ {% endif %} +
+ {% if user.userprofileinfo.intra42_id|length > 0 %} +
+ {%csrf_token%} + +
+ {% else %} +
+ {%csrf_token%} + +
+ {% endif %} +
@@ -87,4 +102,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/accounts/urls.py b/src/accounts/urls.py index abf5ec9..47c07e3 100644 --- a/src/accounts/urls.py +++ b/src/accounts/urls.py @@ -10,8 +10,11 @@ urlpatterns = [ path('edit/', views.edit, name='edit'), path('logout/', views.out, name='out'), path('rank/', views.rank, name='rank'), - path('connections/connect/discord', views.connection.connect, name='connections-connect-discord'), - path('connections/connect/discord/authorize', views.connection.authorize, name='connections-connect-discord-authorize'), - path('connections/disconnect/discord', views.connection.disconnect, name='connections-disconnect-discord'), + path('connections/connect/discord', views.connection.connect_discord, name='connections-connect-discord'), + path('connections/connect/discord/authorize', views.connection.authorize_discord, name='connections-connect-discord-authorize'), + path('connections/disconnect/discord', views.connection.disconnect_discord, name='connections-disconnect-discord'), + path('connections/connect/intra42', views.connection.connect_intra42, name='connections-connect-intra42'), + path('connections/connect/intra42/authorize', views.connection.authorize_intra42, name='connections-connect-intra42-authorize'), + path('connections/disconnect/intra42', views.connection.disconnect_intra42, name='connections-disconnect-intra42'), path('delete_account/', views.delete_account, name='delete_account'), ] diff --git a/src/accounts/views/connection.py b/src/accounts/views/connection.py index 1dc3642..624ed85 100644 --- a/src/accounts/views/connection.py +++ b/src/accounts/views/connection.py @@ -7,9 +7,12 @@ from django.shortcuts import redirect from django.contrib.sites.models import Site import os -oauth = OAuth() +from local_settings import API42_SECRET, API42_UID -oauth.register( +oauth_discord = OAuth() +oauth_intra42 = OAuth() + +oauth_discord.register( name='discord', client_id=os.getenv('OAUTH2_DISCORD_CLIENT_ID'), client_secret=os.getenv('OAUTH2_DISCORD_CLIENT_SECRET'), @@ -19,26 +22,73 @@ oauth.register( api_base_url='https://discord.com/api/' ) +oauth_intra42.register( + name='intra42', + client_id=API42_UID, + client_secret=API42_SECRET, + access_token_url='https://api.intra.42.fr/oauth/token', + authorize_url='https://api.intra.42.fr/oauth/authorize', + #client_kwargs={'scope': 'identify'}, + api_base_url='https://api.intra.42.fr/' +) + @login_required @require_POST -def connect(request): +def connect_intra42(request): + if request.user.userprofileinfo.intra42_id: + return bad_request(request, "Already connected") + site = Site.objects.get_current() + redirect_uri = reverse('accounts:connections-connect-intra42-authorize') + redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code + print(redirect_uri) + return oauth_intra42.intra42.authorize_redirect(request, redirect_uri) + +@login_required +def authorize_intra42(request): + if request.user.userprofileinfo.intra42_id: + return bad_request(request, "Already connected") + try: + token = oauth_intra42.intra42.authorize_access_token(request) + except: + return redirect('accounts:edit') + response = oauth_intra42.intra42.get('v2/me', token=token) + response = response.json() + intra42_id = response['id'] + request.user.userprofileinfo.intra42_id = intra42_id + request.user.userprofileinfo.save() + return redirect('accounts:edit') + +@login_required +@require_POST +def disconnect_intra42(request): + if not request.user.userprofileinfo.intra42_id: + return bad_request(request, "Already disconnected") + request.user.userprofileinfo.intra42_id = None + request.user.userprofileinfo.intra42_campus = None + request.user.userprofileinfo.save() + return redirect('accounts:edit') + + +@login_required +@require_POST +def connect_discord(request): if request.user.userprofileinfo.discord_id: return bad_request(request, "Already connected") site = Site.objects.get_current() redirect_uri = reverse('accounts:connections-connect-discord-authorize') redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code print(redirect_uri) - return oauth.discord.authorize_redirect(request, redirect_uri) + return oauth_discord.discord.authorize_redirect(request, redirect_uri) @login_required -def authorize(request): +def authorize_discord(request): if request.user.userprofileinfo.discord_id: return bad_request(request, "Already connected") try: - token = oauth.discord.authorize_access_token(request) + token = oauth_discord.discord.authorize_access_token(request) except: return redirect('accounts:edit') - response = oauth.discord.get('users/@me', token=token) + response = oauth_discord.discord.get('users/@me', token=token) response = response.json() discord_id = response['id'] request.user.userprofileinfo.discord_id = discord_id @@ -47,7 +97,7 @@ def authorize(request): @login_required @require_POST -def disconnect(request): +def disconnect_discord(request): if not request.user.userprofileinfo.discord_id: return bad_request(request, "Already disconnected") request.user.userprofileinfo.discord_id = None diff --git a/src/ctfs/templates/challenges b/src/ctfs/templates/challenges index 18fac39..5c7b599 160000 --- a/src/ctfs/templates/challenges +++ b/src/ctfs/templates/challenges @@ -1 +1 @@ -Subproject commit 18fac3978d21dc824bcffa2bc960aa2bf6b4abd9 +Subproject commit 5c7b5995fe12c0ed1bb10f97e56ec89377c98b54 From 39e38598366567886ab424c8b9b5873dcc247336 Mon Sep 17 00:00:00 2001 From: Arthur TROUILLET Date: Tue, 29 Mar 2022 11:52:40 +0200 Subject: [PATCH 2/9] Done --- src/accounts/views/connection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/accounts/views/connection.py b/src/accounts/views/connection.py index 624ed85..c15a9ad 100644 --- a/src/accounts/views/connection.py +++ b/src/accounts/views/connection.py @@ -54,7 +54,10 @@ def authorize_intra42(request): response = oauth_intra42.intra42.get('v2/me', token=token) response = response.json() intra42_id = response['id'] + intra42_campus = response['campus'][0]['name'] + print(intra42_campus) request.user.userprofileinfo.intra42_id = intra42_id + request.user.userprofileinfo.intra42_campus = intra42_campus request.user.userprofileinfo.save() return redirect('accounts:edit') From 21f38906df4dda3a1f5ae090ec54a7ac8a539764 Mon Sep 17 00:00:00 2001 From: Arthur TROUILLET Date: Tue, 29 Mar 2022 14:19:06 +0200 Subject: [PATCH 3/9] Change OAuth secret to env --- src/accounts/admin.py | 4 +-- .../migrations/0009_auto_20220329_1339.py | 22 +++++++++++++ src/accounts/models.py | 3 +- src/accounts/views/connection.py | 32 +++++++++---------- 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 src/accounts/migrations/0009_auto_20220329_1339.py diff --git a/src/accounts/admin.py b/src/accounts/admin.py index e1fbd9b..0d9d800 100644 --- a/src/accounts/admin.py +++ b/src/accounts/admin.py @@ -7,6 +7,6 @@ from django.contrib import admin @admin.register(UserProfileInfo) class userprofile(admin.ModelAdmin): #list display - list_display = ['user', 'score', 'last_submission_date'] + list_display = ['user', 'score', 'last_submission_date', 'intra42_campus'] # search list - search_fields = ['score', 'user__username'] \ No newline at end of file + search_fields = ['score', 'user__username', 'intra42_campus'] \ No newline at end of file diff --git a/src/accounts/migrations/0009_auto_20220329_1339.py b/src/accounts/migrations/0009_auto_20220329_1339.py new file mode 100644 index 0000000..e23fec4 --- /dev/null +++ b/src/accounts/migrations/0009_auto_20220329_1339.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.11 on 2022-03-29 11:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0008_auto_20220329_1034'), + ] + + operations = [ + migrations.AlterModelOptions( + name='userprofileinfo', + options={'ordering': ['-score', 'last_submission_date', 'user__username', 'intra42_campus'], 'permissions': (('view_info', 'View user info'),), 'verbose_name': 'profile', 'verbose_name_plural': 'profiles'}, + ), + migrations.AddField( + model_name='userprofileinfo', + name='intra42_campus_id', + field=models.CharField(blank=True, max_length=10, null=True), + ), + ] diff --git a/src/accounts/models.py b/src/accounts/models.py index 5f8a869..99cf388 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -14,13 +14,14 @@ class UserProfileInfo(models.Model): discord_id = models.CharField(max_length=20, null=True, blank=True, unique=True) intra42_id = models.CharField(max_length=20, null=True, blank=True, unique=True) intra42_campus = models.CharField(max_length=50, null=True, blank=True) + intra42_campus_id = models.CharField(max_length=10, null=True, blank=True) member = models.BooleanField(default=False) member_since = models.DateTimeField('Member since', default=timezone.now) member_until = models.DateTimeField('Member until', default=timezone.now) def __str__(self): return self.user.username class Meta: - ordering = ['-score', 'last_submission_date', 'user__username'] + ordering = ['-score', 'last_submission_date', 'user__username', 'intra42_campus'] verbose_name = 'profile' verbose_name_plural = 'profiles' permissions = (("view_info", "View user info"),) diff --git a/src/accounts/views/connection.py b/src/accounts/views/connection.py index c15a9ad..93a21ba 100644 --- a/src/accounts/views/connection.py +++ b/src/accounts/views/connection.py @@ -7,12 +7,9 @@ from django.shortcuts import redirect from django.contrib.sites.models import Site import os -from local_settings import API42_SECRET, API42_UID +oauth = OAuth() -oauth_discord = OAuth() -oauth_intra42 = OAuth() - -oauth_discord.register( +oauth.register( name='discord', client_id=os.getenv('OAUTH2_DISCORD_CLIENT_ID'), client_secret=os.getenv('OAUTH2_DISCORD_CLIENT_SECRET'), @@ -22,13 +19,12 @@ oauth_discord.register( api_base_url='https://discord.com/api/' ) -oauth_intra42.register( +oauth.register( name='intra42', - client_id=API42_UID, - client_secret=API42_SECRET, + client_id=os.getenv('OAUTH2_INTRA42_CLIENT_ID'), + client_secret=os.getenv('OAUTH2_INTRA42_CLIENT_SECRET'), access_token_url='https://api.intra.42.fr/oauth/token', authorize_url='https://api.intra.42.fr/oauth/authorize', - #client_kwargs={'scope': 'identify'}, api_base_url='https://api.intra.42.fr/' ) @@ -41,23 +37,24 @@ def connect_intra42(request): redirect_uri = reverse('accounts:connections-connect-intra42-authorize') redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code print(redirect_uri) - return oauth_intra42.intra42.authorize_redirect(request, redirect_uri) + return oauth.intra42.authorize_redirect(request, redirect_uri) @login_required def authorize_intra42(request): if request.user.userprofileinfo.intra42_id: return bad_request(request, "Already connected") try: - token = oauth_intra42.intra42.authorize_access_token(request) + token = oauth.intra42.authorize_access_token(request) except: return redirect('accounts:edit') - response = oauth_intra42.intra42.get('v2/me', token=token) + response = oauth.intra42.get('v2/me', token=token) response = response.json() intra42_id = response['id'] intra42_campus = response['campus'][0]['name'] - print(intra42_campus) + intra42_campus_id = response['campus'][0]['id'] request.user.userprofileinfo.intra42_id = intra42_id request.user.userprofileinfo.intra42_campus = intra42_campus + request.user.userprofileinfo.intra42_campus_id = intra42_campus_id request.user.userprofileinfo.save() return redirect('accounts:edit') @@ -80,19 +77,20 @@ def connect_discord(request): site = Site.objects.get_current() redirect_uri = reverse('accounts:connections-connect-discord-authorize') redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code - print(redirect_uri) - return oauth_discord.discord.authorize_redirect(request, redirect_uri) + return oauth.discord.authorize_redirect(request, redirect_uri) @login_required def authorize_discord(request): if request.user.userprofileinfo.discord_id: + print("Already") return bad_request(request, "Already connected") try: - token = oauth_discord.discord.authorize_access_token(request) + token = oauth.discord.authorize_access_token(request) except: return redirect('accounts:edit') - response = oauth_discord.discord.get('users/@me', token=token) + response = oauth.discord.get('users/@me', token=token) response = response.json() + print(response) discord_id = response['id'] request.user.userprofileinfo.discord_id = discord_id request.user.userprofileinfo.save() From ea691204c4b91758c84fe960d670eeb2bb2a9de9 Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 16:46:03 +0200 Subject: [PATCH 4/9] Upgrad po file --- src/locale/de/LC_MESSAGES/django.po | 16 +++++++--- src/locale/en/LC_MESSAGES/django.po | 16 +++++++--- src/locale/es/LC_MESSAGES/django.po | 16 +++++++--- src/locale/fr/LC_MESSAGES/django.po | 20 ++++++++++--- src/locale/ja/LC_MESSAGES/django.po | 16 +++++++--- src/locale/ru/LC_MESSAGES/django.po | 30 ++++++++++++++----- src/resources/locale/de/LC_MESSAGES/django.po | 4 ++- src/resources/locale/en/LC_MESSAGES/django.po | 4 ++- src/resources/locale/es/LC_MESSAGES/django.po | 4 ++- src/resources/locale/fr/LC_MESSAGES/django.po | 4 ++- src/resources/locale/ja/LC_MESSAGES/django.po | 4 ++- src/resources/locale/ru/LC_MESSAGES/django.po | 4 ++- 12 files changed, 104 insertions(+), 34 deletions(-) diff --git a/src/locale/de/LC_MESSAGES/django.po b/src/locale/de/LC_MESSAGES/django.po index a75888d..74db037 100644 --- a/src/locale/de/LC_MESSAGES/django.po +++ b/src/locale/de/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: 2022-02-10 19:50+0100\n" "Last-Translator: Clément Hamada \n" "Language-Team: \n" @@ -87,7 +87,15 @@ msgstr "" msgid "Connect Discord" msgstr "" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +msgid "Disconnect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:74 +msgid "Connect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -98,12 +106,12 @@ msgstr "" msgid "Score" msgstr "Punktzahl" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "Registriert seit" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 #, fuzzy #| msgid "Delete my account" msgid " Delete my account" diff --git a/src/locale/en/LC_MESSAGES/django.po b/src/locale/en/LC_MESSAGES/django.po index 813ce58..f0a4207 100644 --- a/src/locale/en/LC_MESSAGES/django.po +++ b/src/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -84,7 +84,15 @@ msgstr "" msgid "Connect Discord" msgstr "" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +msgid "Disconnect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:74 +msgid "Connect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -95,12 +103,12 @@ msgstr "" msgid "Score" msgstr "" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 msgid " Delete my account" msgstr "" diff --git a/src/locale/es/LC_MESSAGES/django.po b/src/locale/es/LC_MESSAGES/django.po index f957809..653bf1e 100644 --- a/src/locale/es/LC_MESSAGES/django.po +++ b/src/locale/es/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: 2022-02-09 10:55+0100\n" "Last-Translator: Javier Uhagón (uhagontorralvojavier@gmail.com)\n" "Language-Team: \n" @@ -88,7 +88,15 @@ msgstr "" msgid "Connect Discord" msgstr "" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +msgid "Disconnect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:74 +msgid "Connect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -99,12 +107,12 @@ msgstr "" msgid "Score" msgstr "Puntuación" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "Registrado desde" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 #, fuzzy #| msgid "Delete my account" msgid " Delete my account" diff --git a/src/locale/fr/LC_MESSAGES/django.po b/src/locale/fr/LC_MESSAGES/django.po index 0b38e57..126f967 100644 --- a/src/locale/fr/LC_MESSAGES/django.po +++ b/src/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -92,7 +92,19 @@ msgstr "Déconnecter Discord" msgid "Connect Discord" msgstr "Connecter Discord" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +#, fuzzy +#| msgid "Disconnect Discord" +msgid "Disconnect 42" +msgstr "Déconnecter Discord" + +#: accounts/templates/accounts/edit.html:74 +#, fuzzy +#| msgid "Connect Discord" +msgid "Connect 42" +msgstr "Connecter Discord" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -103,12 +115,12 @@ msgstr "Connecter Discord" msgid "Score" msgstr "Score" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "Inscrit depuis" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 #, fuzzy #| msgid "Connected accounts" msgid " Delete my account" diff --git a/src/locale/ja/LC_MESSAGES/django.po b/src/locale/ja/LC_MESSAGES/django.po index 702284e..f421f63 100644 --- a/src/locale/ja/LC_MESSAGES/django.po +++ b/src/locale/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -88,7 +88,15 @@ msgstr "" msgid "Connect Discord" msgstr "" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +msgid "Disconnect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:74 +msgid "Connect 42" +msgstr "" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -99,12 +107,12 @@ msgstr "" msgid "Score" msgstr "スコア" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "登録日" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 #, fuzzy #| msgid "Delete my account" msgid " Delete my account" diff --git a/src/locale/ru/LC_MESSAGES/django.po b/src/locale/ru/LC_MESSAGES/django.po index 54fb9c0..6c9330e 100644 --- a/src/locale/ru/LC_MESSAGES/django.po +++ b/src/locale/ru/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -86,7 +86,19 @@ msgstr "Отключить Discord" msgid "Connect Discord" msgstr "Подключить Discord" -#: accounts/templates/accounts/edit.html:70 +#: accounts/templates/accounts/edit.html:68 +#, fuzzy +#| msgid "Disconnect Discord" +msgid "Disconnect 42" +msgstr "Отключить Discord" + +#: accounts/templates/accounts/edit.html:74 +#, fuzzy +#| msgid "Connect Discord" +msgid "Connect 42" +msgstr "Подключить Discord" + +#: accounts/templates/accounts/edit.html:85 #: accounts/templates/accounts/profile.html:46 #: ctfs/templates/ctfs/ctf_info.html:65 ctfs/templates/ctfs/ctfs_list.html:13 #: events/templates/events/event_info.html:66 @@ -97,12 +109,12 @@ msgstr "Подключить Discord" msgid "Score" msgstr "Счет" -#: accounts/templates/accounts/edit.html:78 +#: accounts/templates/accounts/edit.html:93 #: accounts/templates/accounts/profile.html:60 msgid "Registered since" msgstr "Зарегистрирован с" -#: accounts/templates/accounts/edit.html:84 +#: accounts/templates/accounts/edit.html:99 msgid " Delete my account" msgstr " Удалить мой аккаунт" @@ -381,7 +393,8 @@ msgstr "Событие" msgid "" "No translation available. Please try another language (English or French)." msgstr "" -"Перевод недоступен. Пожалуйста, попобуй другой язык (английский или французский)." +"Перевод недоступен. Пожалуйста, попобуй другой язык (английский или " +"французский)." #: events/templates/events/ctf_info.html:28 #: events/templates/events/event_info.html:18 @@ -400,7 +413,8 @@ msgstr "Перед вводом флагов необходимо зарегис msgid "" "This is a team event, please create or join a team before submitting flags." msgstr "" -"Это командное соревнование, пожалуйста, создай или вступи в команду перед тем как отправить флаги." +"Это командное соревнование, пожалуйста, создай или вступи в команду перед " +"тем как отправить флаги." #: events/templates/events/event_info.html:9 msgid "Subscriptions is over." @@ -635,8 +649,8 @@ msgid "" "We've emailed you instructions for setting your password. You should receive " "the email shortly!" msgstr "" -"Мы отправили тебе по электронной почте инструкции по установке пароля." -"Письмо будет получено совсем скоро!" +"Мы отправили тебе по электронной почте инструкции по установке пароля.Письмо " +"будет получено совсем скоро!" #: templates/registration/password_reset_form.html:16 msgid "Reset" diff --git a/src/resources/locale/de/LC_MESSAGES/django.po b/src/resources/locale/de/LC_MESSAGES/django.po index b24ad5b..3dd28eb 100644 --- a/src/resources/locale/de/LC_MESSAGES/django.po +++ b/src/resources/locale/de/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: 2022-02-10 19:27+0100\n" "Last-Translator: Clément Hamada \n" "Language-Team: \n" @@ -255,11 +255,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" diff --git a/src/resources/locale/en/LC_MESSAGES/django.po b/src/resources/locale/en/LC_MESSAGES/django.po index 3c855f0..144bafe 100644 --- a/src/resources/locale/en/LC_MESSAGES/django.po +++ b/src/resources/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -210,11 +210,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" diff --git a/src/resources/locale/es/LC_MESSAGES/django.po b/src/resources/locale/es/LC_MESSAGES/django.po index 800ee4e..61c4f23 100644 --- a/src/resources/locale/es/LC_MESSAGES/django.po +++ b/src/resources/locale/es/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: 2022-02-09 10:55+0100\n" "Last-Translator: Javier Uhagón (uhagontorralvojavier@gmail.com)\n" "Language-Team: \n" @@ -244,11 +244,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" diff --git a/src/resources/locale/fr/LC_MESSAGES/django.po b/src/resources/locale/fr/LC_MESSAGES/django.po index cc10f9e..bf29a8d 100644 --- a/src/resources/locale/fr/LC_MESSAGES/django.po +++ b/src/resources/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -254,11 +254,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" diff --git a/src/resources/locale/ja/LC_MESSAGES/django.po b/src/resources/locale/ja/LC_MESSAGES/django.po index ffd0706..35079f7 100644 --- a/src/resources/locale/ja/LC_MESSAGES/django.po +++ b/src/resources/locale/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -248,11 +248,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" diff --git a/src/resources/locale/ru/LC_MESSAGES/django.po b/src/resources/locale/ru/LC_MESSAGES/django.po index af459a6..ab93d9a 100644 --- a/src/resources/locale/ru/LC_MESSAGES/django.po +++ b/src/resources/locale/ru/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-13 18:04+0100\n" +"POT-Creation-Date: 2022-03-29 16:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -212,11 +212,13 @@ msgid "What will we do with your money ?" msgstr "" #: resources/templates/resources/donate.html:51 +#, python-format msgid "" "Hosting a website - and especially a CTF platform - costs money:\n" " more precisely, it costs us 50 euros per month.
\n" " If we had 40 members each year, it would be enough to " "cover the hosting of 42CTF.
\n" +" We currently have %(nb_members)s members.
\n" " With the additional money, we could for example offer prizes " "for limited-time events, but we will update this page as soon as we reach " "this threshold :)" From e8575d559e592b9cce54f5628aad67721e5d0f3f Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 18:46:19 +0200 Subject: [PATCH 5/9] Add campuses scoreboard --- src/scoreboard/templates/scoreboard/scoreboard.html | 7 +++++++ src/scoreboard/urls.py | 3 ++- src/scoreboard/views.py | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/scoreboard.html b/src/scoreboard/templates/scoreboard/scoreboard.html index c00c8d1..ff3064f 100644 --- a/src/scoreboard/templates/scoreboard/scoreboard.html +++ b/src/scoreboard/templates/scoreboard/scoreboard.html @@ -12,6 +12,7 @@ {% trans "Rank" %} {% trans "Username" %} {% trans "Website" %} + {% trans "Campus" %} {% trans "Score" %} @@ -26,6 +27,12 @@ {{ s.user.userprofileinfo.portfolio_site }} {% endif %} + + {% if s.user.userprofileinfo.intra42_campus %} + + {{ s.user.userprofileinfo.intra42_campus }} + + {% endif %} {{ s.user.userprofileinfo.score }} {% endfor %} diff --git a/src/scoreboard/urls.py b/src/scoreboard/urls.py index ee31136..5f95344 100644 --- a/src/scoreboard/urls.py +++ b/src/scoreboard/urls.py @@ -4,5 +4,6 @@ from . import views app_name = "scoreboard" urlpatterns = [ - path('', views.scoreboard, name='scoreboard') + path('', views.scoreboard, name='scoreboard'), + path('campus/', views.campus, name='campus') ] diff --git a/src/scoreboard/views.py b/src/scoreboard/views.py index edeb925..1aeb356 100644 --- a/src/scoreboard/views.py +++ b/src/scoreboard/views.py @@ -8,5 +8,12 @@ def scoreboard(request): page = request.GET.get('page') scores_p = paginator.get_page(page) return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p}) - + +def campus(request, campus): + scores = UserProfileInfo.objects.filter(score__gt=0, intra42_campus__exact=campus).select_related().order_by('-score', 'last_submission_date', 'user__username') + paginator = Paginator(scores, 20) + page = request.GET.get('page') + scores_p = paginator.get_page(page) + return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p}) + # Create your views here. From 3991dda7d3852dde27538adcd176056aa9a214af Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 18:55:54 +0200 Subject: [PATCH 6/9] HTML typo --- src/scoreboard/templates/scoreboard/scoreboard.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/scoreboard.html b/src/scoreboard/templates/scoreboard/scoreboard.html index ff3064f..af7442b 100644 --- a/src/scoreboard/templates/scoreboard/scoreboard.html +++ b/src/scoreboard/templates/scoreboard/scoreboard.html @@ -29,10 +29,11 @@ {% if s.user.userprofileinfo.intra42_campus %} - - {{ s.user.userprofileinfo.intra42_campus }} - + + {{ s.user.userprofileinfo.intra42_campus }} + {% endif %} + {{ s.user.userprofileinfo.score }} {% endfor %} From e480aec493e02d390bb5bc929e512a6d3a6cb787 Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 19:49:52 +0200 Subject: [PATCH 7/9] Remove debug --- src/accounts/views/connection.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/accounts/views/connection.py b/src/accounts/views/connection.py index 93a21ba..d83c20b 100644 --- a/src/accounts/views/connection.py +++ b/src/accounts/views/connection.py @@ -36,7 +36,6 @@ def connect_intra42(request): site = Site.objects.get_current() redirect_uri = reverse('accounts:connections-connect-intra42-authorize') redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code - print(redirect_uri) return oauth.intra42.authorize_redirect(request, redirect_uri) @login_required @@ -90,7 +89,6 @@ def authorize_discord(request): return redirect('accounts:edit') response = oauth.discord.get('users/@me', token=token) response = response.json() - print(response) discord_id = response['id'] request.user.userprofileinfo.discord_id = discord_id request.user.userprofileinfo.save() From 978dd24a0055d9be45135e461cedc1206702ed4b Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 18:46:19 +0200 Subject: [PATCH 8/9] Add campuses scoreboard --- src/scoreboard/templates/scoreboard/scoreboard.html | 7 +++++++ src/scoreboard/urls.py | 3 ++- src/scoreboard/views.py | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/scoreboard.html b/src/scoreboard/templates/scoreboard/scoreboard.html index c00c8d1..ff3064f 100644 --- a/src/scoreboard/templates/scoreboard/scoreboard.html +++ b/src/scoreboard/templates/scoreboard/scoreboard.html @@ -12,6 +12,7 @@ {% trans "Rank" %} {% trans "Username" %} {% trans "Website" %} + {% trans "Campus" %} {% trans "Score" %} @@ -26,6 +27,12 @@ {{ s.user.userprofileinfo.portfolio_site }} {% endif %} + + {% if s.user.userprofileinfo.intra42_campus %} + + {{ s.user.userprofileinfo.intra42_campus }} + + {% endif %} {{ s.user.userprofileinfo.score }} {% endfor %} diff --git a/src/scoreboard/urls.py b/src/scoreboard/urls.py index ee31136..5f95344 100644 --- a/src/scoreboard/urls.py +++ b/src/scoreboard/urls.py @@ -4,5 +4,6 @@ from . import views app_name = "scoreboard" urlpatterns = [ - path('', views.scoreboard, name='scoreboard') + path('', views.scoreboard, name='scoreboard'), + path('campus/', views.campus, name='campus') ] diff --git a/src/scoreboard/views.py b/src/scoreboard/views.py index edeb925..1aeb356 100644 --- a/src/scoreboard/views.py +++ b/src/scoreboard/views.py @@ -8,5 +8,12 @@ def scoreboard(request): page = request.GET.get('page') scores_p = paginator.get_page(page) return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p}) - + +def campus(request, campus): + scores = UserProfileInfo.objects.filter(score__gt=0, intra42_campus__exact=campus).select_related().order_by('-score', 'last_submission_date', 'user__username') + paginator = Paginator(scores, 20) + page = request.GET.get('page') + scores_p = paginator.get_page(page) + return render(request, 'scoreboard/scoreboard.html', {'scores':scores_p}) + # Create your views here. From e23d6d7f4980c1ce216488489beb88fe96a8a5dd Mon Sep 17 00:00:00 2001 From: Starthur Date: Tue, 29 Mar 2022 18:55:54 +0200 Subject: [PATCH 9/9] HTML typo --- src/scoreboard/templates/scoreboard/scoreboard.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scoreboard/templates/scoreboard/scoreboard.html b/src/scoreboard/templates/scoreboard/scoreboard.html index ff3064f..af7442b 100644 --- a/src/scoreboard/templates/scoreboard/scoreboard.html +++ b/src/scoreboard/templates/scoreboard/scoreboard.html @@ -29,10 +29,11 @@ {% if s.user.userprofileinfo.intra42_campus %} - - {{ s.user.userprofileinfo.intra42_campus }} - + + {{ s.user.userprofileinfo.intra42_campus }} + {% endif %} + {{ s.user.userprofileinfo.score }} {% endfor %}