Compare commits

..

158 Commits

Author SHA1 Message Date
Danhia 7887074b3d fixed merge conflict 2022-02-17 23:59:21 +01:00
mguerrea b6c36cbffb Merge branch 'challenges-description' into main 2022-02-17 23:50:28 +01:00
Danhia 60a59b23e6 fixed error 500 when requesting german or russian translation 2022-02-17 23:21:41 +01:00
Danhia 8f32ef9a6e excluded the API from the i18n patterns 2022-02-17 13:09:11 +01:00
Danhia a0b76903a7 added endpoint API for bot 2022-02-17 12:40:40 +01:00
Danhia a7de7b8054 removed language code in redirect_uri 2022-02-17 12:21:17 +01:00
Danhia 0d734e98b1 removed language code in redirect_uri 2022-02-17 12:19:52 +01:00
Danhia 3d24fe9b3b tentative for fixing url redirect 2022-02-17 12:03:52 +01:00
Danhia ba0d75c250 restored discord OAuth, not working in local, let's test on preprod if the url problem is solved 2022-02-17 11:11:36 +01:00
Danhia 3ae80ca17f fixed end of sentence in french with quote badly escaped 2022-02-16 20:14:29 +01:00
Danhia a7e75b2a43 fixed quotes that where badly escaped in resources 2022-02-16 20:07:19 +01:00
Danhia 9ea67ae2a0 Merge branch 'main' into translation 2022-02-16 19:28:39 +01:00
Danhia 899a01e472 Merge branch 'main' into challenges-description 2022-02-16 15:41:52 +01:00
Danhia c40d49c326 Merge pull request 'Ressource page translation' (#22) from Starthur/website:main into translation
Reviewed-on: #22
2022-02-16 15:37:18 +01:00
Starthur d6b1380552 Last push before pull request 2022-02-16 15:23:15 +01:00
Arthur-TRT d0c93f98a1 Correct some mistake 2022-02-16 15:19:07 +01:00
Arthur-TRT 97e120e5fc First translation of Ressources in fr 2022-02-16 15:03:40 +01:00
Danhia 494377399c Merge pull request 'Update README' (#21) from update-readme into main
Reviewed-on: #21
2022-02-16 14:34:14 +01:00
Starthur 28d8874272 Update README
Better solution to create superuser admin
2022-02-16 14:33:21 +01:00
Starthur b9704d3cb3 Update README
Add information about migrate and admin right on local dev
2022-02-16 14:13:00 +01:00
Danhia 0ac395def8 Update 'requirements.txt' 2022-02-16 13:53:57 +01:00
Danhia 7ff556a986 Update 'README.md' 2022-02-16 13:50:19 +01:00
Danhia 5e02041f0c put challenges descriptions outside of the db 2022-02-15 18:13:43 +01:00
Danhia f75a034094 replaced jp with ja for news 2022-02-15 14:27:37 +01:00
Danhia 5f28bc5d2c Merge pull request '[translation] Added Japanese version' (#9) from ysaito/website:translation-jp into translation
Reviewed-on: #9
2022-02-15 13:20:02 +01:00
ysaito 904ce1b748 feat(welcome_ctf_2021.html): Added Japanese version 2022-02-15 18:11:00 +09:00
ysaito 5b15b9cd6f feat(sql_challenges.html): Added Japanese version 2022-02-15 18:07:48 +09:00
ysaito 5d46bd6df0 feat(speed_dating_ctf_2022.html): Added Japanese version 2022-02-15 18:06:46 +09:00
ysaito 67de669459 feat(dynamic_scoring.html): Added Japanese version 2022-02-15 18:05:43 +09:00
ysaito 26aeb6d7bd feat(42ctf_vm.html): Added Japanese version 2022-02-15 18:04:30 +09:00
Danhia 1b89fa88d8 updated all .po with makemessages 2022-02-14 19:38:16 +01:00
Danhia 0bb3a8b805 Merge pull request #8 from ClemaX/translation/de
German news translation and typos fix
2022-02-14 18:34:08 +00:00
Danhia 5eec76dd00 removed start challenge button when event is over 2022-02-14 19:18:00 +01:00
Clément Hamada 6b6f264fe0 news: locale: de: Initial translation 2022-02-13 21:47:03 +01:00
Clément Hamada c4fd6d05c3 locale: de: Fix some typos 2022-02-13 21:30:40 +01:00
Danhia 901c73a4f2 Merge branch 'main' of https://github.com/Danhia/42CTF into main 2022-02-13 13:14:24 +01:00
Danhia 01c0f28b16 hotfix for 500 when joining team 2022-02-13 13:13:54 +01:00
Danhia 7174cf9edb Update README.md 2022-02-12 20:35:41 +01:00
Danhia ef0fcc5fea Merge pull request #7 from Miliviu/main
Set Spanish to done in the readme todo list
2022-02-12 19:28:07 +00:00
Danhia aabba3ea53 dynamic scoring for events, i'm pretty sure everything is gonna break 2022-02-12 19:56:46 +01:00
Miliviu 1abeabebfe Set Spanish to done in the readme todo list 2022-02-11 19:55:50 +01:00
Danhia 9f2d78ac33 challenges not yet published 2022-02-09 14:14:41 +01:00
Danhia 27ed107501 Merge pull request #6 from Miliviu/main
Add translation of news to Spanish
2022-02-09 13:36:45 +01:00
Miliviu 0dea7fb619 Add translation of news to Spanish 2022-02-09 13:08:02 +01:00
Danhia 23529b3b07 added english version of news contents 2022-02-09 12:39:12 +01:00
Danhia cb9bc7cc56 news content is now out of the db for languages other than english 2022-02-09 12:22:12 +01:00
Danhia af4912837f Merge pull request #5 from Miliviu/main
All Spanish strings translated
2022-02-09 11:12:32 +01:00
Miliviu 187579e61c Add trasnlator references and date of translation 2022-02-09 10:58:12 +01:00
Miliviu fabe417fe2 Add Spanish to availible languages in the Settings.py file 2022-02-09 10:53:11 +01:00
Miliviu a6a5e424df Added spanish translation to both django files 2022-02-09 10:44:40 +01:00
Danhia bcf0c51ba5 added option to open team to automatching 2022-02-08 15:36:06 +01:00
Danhia 241a3f2bc1 added japanese empty files 2022-02-06 23:39:46 +01:00
Danhia cb46708e5c fixed redirection when leaving team + few details in html 2022-02-04 19:28:09 +01:00
Danhia 3c166f3834 updated .po files for last modifications 2022-02-04 19:05:11 +01:00
Danhia 92a1dca27c Merge branch 'main' into events 2022-02-04 19:04:20 +01:00
Danhia 96121e401e fixed redirection in events 2022-02-04 19:04:17 +01:00
ix 97f6b99133 fix event html 2022-02-04 17:13:50 +01:00
Danhia c45cfed8d4 fixed centering flag vertically 2022-02-04 16:04:56 +01:00
ix 5dc04f888b fix flags 2022-02-04 15:43:56 +01:00
Danhia 993e1fa998 beginning of lang flag refacto 2022-02-04 15:28:06 +01:00
Danhia 9d33985fa4 Merge pull request #4 from ClemaX/translation/de
locale: de: Translate all existing messages
2022-02-04 13:05:05 +01:00
Clément Hamada 0cd862734e resources: locale: de: Translate all existing messages 2022-02-04 06:02:00 +01:00
Clément Hamada aed129b4b9 locale: de: Spellcheck 2022-02-04 05:58:07 +01:00
Clément Hamada d1ab64885e resources: locale: de: Update messages 2022-02-04 03:34:01 +01:00
Clément Hamada b2cf802ab5 locale: de: Update file references 2022-02-04 03:30:49 +01:00
Clément Hamada 266e018d83 locale: de: Translate all existing messages 2022-02-04 03:13:51 +01:00
Danhia 8fd25d8fa6 changed position of logos in footer for mobile devices + added helloasso button in resources 2022-02-04 00:27:29 +01:00
ix 53fe69aa09 Merge branch 'main' of github.com:Danhia/42CTF into main 2022-02-03 21:03:18 +01:00
Danhia aadb2ac858 hotfix for dynamic scoring 2022-02-03 21:02:55 +01:00
ix 34b8829797 Fix resources page 2022-02-03 21:00:04 +01:00
ix 619ddf3d07 fix spaces between nav elements 2022-02-03 20:49:24 +01:00
ix 5d00c5733f Fix resources page 2022-02-03 20:49:02 +01:00
ix 248cdc54d5 Fix unused html 2022-02-03 20:45:56 +01:00
Danhia f8eef0ef3d added dynamic scoring for permanent platform, let's hope nothing breaks 2022-02-03 20:27:55 +01:00
Danhia e806b23812 fixed latest flags when chall is disabled + fixed recompute_scoreboard 2022-02-03 18:46:37 +01:00
Danhia 0fbf7b77c3 added disabled attribute for challenge + fixed recomputescoreboard 2022-02-03 18:37:24 +01:00
Danhia 985f440ede hotfix for 0 division when there is an empty category in profile page 2022-02-02 19:34:22 +01:00
Danhia 29dc697bdc added different color for members almost everywhere 2022-02-02 19:23:13 +01:00
Danhia 29835348f5 replaced flags counter by flag because css is broken on medium devices 2022-01-31 19:27:20 +01:00
Danhia 04925ed5b5 you can now delete your account 2022-01-31 19:21:14 +01:00
Danhia 14763469df hotfix for command recompute_scoreboard 2022-01-31 18:46:34 +01:00
Danhia 2495de137b Merge branch 'home-refacto' into main 2022-01-30 21:43:20 +01:00
Danhia 37525bb50a fixed links css for challenges in home 2022-01-30 19:22:58 +01:00
Danhia 52893b17d0 changed timezone in settings.py 2022-01-30 18:22:59 +01:00
Danhia 9ff4e7e36b added weekly top 5 + latest flags to home page 2022-01-30 17:59:02 +01:00
Danhia 33763a13a4 hotfix for too long pseudos breaking top10 css 2022-01-24 21:11:30 +01:00
Danhia f9535dcae3 fixed broken responsive design for footer 2022-01-24 17:20:23 +01:00
Danhia 6522982975 hotfix for duplicate messages in .po files 2022-01-24 16:16:25 +01:00
Danhia 6c0cc7d5c8 replaced subscribe by register for events 2022-01-24 16:11:03 +01:00
Danhia 1081fb35b2 added event filter for teams in admin panel 2022-01-24 12:59:09 +01:00
Danhia 1258096220 added event filter for teams in admin panel 2022-01-24 12:57:14 +01:00
Danhia fb0d844781 updtaed footer with twitter and linkedin 2022-01-24 10:27:38 +01:00
Danhia 2654c87f0b fixed missing og_img for page preview 2022-01-24 09:57:03 +01:00
Danhia c5858400ba corrected typo in no solves message 2022-01-23 18:48:55 +01:00
Danhia 7e4a2a30d9 changed color in top 10 + updated resources 2022-01-23 18:45:10 +01:00
Danhia bb97f1adc1 added member and visitor status + different colors in scoreboard 2022-01-23 18:40:57 +01:00
Danhia 52b3a71caf finished first version of resources, let's deploy ! 2022-01-23 17:08:13 +01:00
Danhia 0e41087f6a Merge branch 'main' into ressources 2022-01-23 15:48:57 +01:00
Danhia e4352ccc9a Merge branch 'events' into main 2022-01-16 22:19:38 +01:00
Danhia 8fbbd2d953 split views.py in events + new field in events model for automatching 2022-01-16 22:18:39 +01:00
Danhia cd5dcd9093 added auto matching for teams in event 2022-01-15 00:44:25 +01:00
Danhia 206cdd8edb Merge branch 'events' into main 2022-01-14 23:42:53 +01:00
Danhia c360457152 removed 500 when user is not connected and want to access public event 2022-01-14 23:41:59 +01:00
Danhia 3fcd85124b first draft of resources 2022-01-08 14:12:09 +01:00
Danhia 69e245dce1 updated fr translations for events 2022-01-08 11:23:20 +01:00
Danhia 97aac9140a updated translation files 2022-01-08 10:55:57 +01:00
Danhia 39d10437f8 fixed error when displaying challenge info in solo mode 2022-01-02 21:53:38 +01:00
Danhia eb23c9fac8 fixed starting date for graph on event's profile 2022-01-02 21:46:23 +01:00
Danhia afbe7f2430 fixed case where a category has no challenge in an event and profile crash 2022-01-02 21:41:32 +01:00
Danhia 8a2dd4dc80 fixed missing team when event is not password protected 2022-01-02 21:00:02 +01:00
Danhia 36ab01765e it's possible to modify and leave team 2022-01-02 20:42:10 +01:00
Danhia ba38df3b33 you can create and join team + eventplayer and team profile 2021-12-28 20:17:39 +01:00
Danhia 46dbc7182d first draft for team events 2021-12-17 19:02:19 +01:00
Danhia caf494ca98 Merge branch 'main' of https://github.com/Danhia/42CTF into main 2021-12-14 21:22:03 +01:00
Danhia e1e6449751 added rank on profile page 2021-12-14 21:21:29 +01:00
Danhia 56c9cb62c1 Update README.md 2021-12-14 20:38:03 +01:00
Danhia e774921c52 little fix for flag length + restrict access for unpublished challenges 2021-12-14 20:35:59 +01:00
ix 8ae6d83450 fix access to event challenges when event not begun or user not connected 2021-12-10 09:47:45 +01:00
Danhia 98350ad0d7 Merge pull request #3 from Lindoriel/main
correcting syntax error
2021-10-25 21:01:04 +02:00
Maxime ROTH 5039389cbc correcting ". error 2021-10-25 20:58:59 +02:00
Danhia ca023e77ad Merge pull request #2 from Lindoriel/main
adding french translation
2021-10-25 20:52:14 +02:00
Maxime ROTH 5280139f2d adding french translation 2021-10-25 20:22:11 +02:00
ix 8e481f603c update patreon link 2021-10-25 13:22:07 +02:00
Danhia 6ee81db3b6 first draft for cgu 2021-10-24 20:26:26 +02:00
ix dd2c60a3a4 footer reworked, patreon link added, messages recompiled and cgu view added 2021-10-24 16:25:46 +02:00
ix 48f9021839 fix solve list for event challenges, fix link color 2021-10-23 11:13:02 +02:00
ix a8b5e7f61d fix template profile 2021-10-22 16:09:05 +02:00
ix 6c85d9871c fix template profile 2021-10-22 16:08:22 +02:00
ix 5ea11f9951 Merge branch 'events' into main 2021-10-22 14:21:16 +02:00
ix 0469a140cb Merge branch 'main' of github.com:Danhia/42CTF into main 2021-10-22 14:21:12 +02:00
ix 71b612babe Update fix 2021-10-22 14:21:05 +02:00
Ix 1730f1048e Merge pull request #1 from Danhia/events
Update fix
2021-10-22 13:59:27 +02:00
ix 7c5c33b31a Merge branch 'main' of github.com:Danhia/42CTF into main 2021-10-22 13:58:40 +02:00
ix fca47da223 Update fix 2021-10-22 13:58:23 +02:00
Ix f914c27a28 Update README.md 2021-10-22 11:48:28 +02:00
ix 8728d5cd3e Update todo 2021-10-22 11:46:48 +02:00
ix 6997aaf93b Events done 2021-10-22 11:45:50 +02:00
ix 06dc8188a0 events added, need to smooth html and css 2021-10-21 15:02:02 +02:00
Ix 0f231a4988 Update README.md 2021-09-21 21:42:55 +02:00
ix 2b49c995a0 category challenges listed by point decrease 2021-09-08 21:50:28 +02:00
ix 4a2504be73 Discord button removed, css fix when 0 at category stat, messages recompiled 2021-09-08 21:36:15 +02:00
ix 0f92cf3da1 Categories stats added, css modified, fix responsive display of profile page 2021-09-08 16:53:00 +02:00
ix 8a203161ed Merge branch 'graph' into main 2021-09-08 04:00:39 +02:00
ix c5dedbfc26 Charts changed to highcharts 2021-09-08 03:59:35 +02:00
ix c5713d3887 Charts added 2021-09-08 00:32:44 +02:00
Danhia 299b47f598 fixed missing translation header in password reset templates 2021-09-07 20:42:18 +00:00
ix 9f431ac4fa internationalization for news 2021-09-07 21:13:30 +02:00
ix 2f7d96ed03 Merge remote-tracking branch 'origin/traduction-fr' into main 2021-09-07 19:54:05 +02:00
ix 1caccc6428 internationalization fixed, templates url fixed, messages recompiled 2021-09-07 19:52:40 +02:00
Danhia b84349b414 changed translation for sign up 2021-09-06 21:34:45 +02:00
Danhia 04cbde8326 french translation 2021-09-06 21:04:42 +02:00
ix ebb3712702 last 2021-09-06 20:15:03 +02:00
ix 58947f2b89 local settings 2021-09-06 20:14:23 +02:00
ix f53eb4d924 local settings 2021-09-06 20:12:03 +02:00
ix f453512f4b okay it's done i think 2021-09-06 19:59:13 +02:00
ix 9e24750a1b okay it's done i think 2021-09-06 19:42:13 +02:00
Ix 8cf4c891e8 Create settings.py 2021-07-10 12:34:42 +02:00
Ix 1b112cfd45 Update .gitignore 2021-07-10 12:29:40 +02:00
14 changed files with 135 additions and 164 deletions

104
bot.py
View File

@ -1,104 +0,0 @@
import os
import discord
import discord.utils
import urllib.request, json
import asyncio
import json
import logging
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = '42ctf'
intents = discord.Intents.all()
client = discord.Client(intents=intents)
db_file = open('members.json', 'r')
users = json.load(db_file)
db_file.close()
logging.basicConfig(filename='bot.log', format='%(asctime)s %(message)s', level=logging.INFO)
guild = ''
roles = {}
def get_rank(token):
url = urllib.request.urlopen("https://www.42ctf.org/accounts/rank/" + token)
data = json.loads(url.read().decode())
rank = data['rank']
return rank
async def watch_roles():
global users
await client.wait_until_ready() # ensures cache is loaded
while not client.is_closed():
for member_id, token in users.items():
if (token == "0000"):
continue
member = discord.utils.get(guild.members, id=int(member_id))
rank = get_rank(token)
if rank == 1 and roles['top1'] not in member.roles:
await member.add_roles(roles['top1'])
await member.remove_roles(roles['top10'])
await member.remove_roles(roles['top50'])
elif rank > 1 and rank <= 10 and roles['top10'] not in member.roles:
await member.add_roles(roles['top10'])
await member.remove_roles(roles['top1'])
await member.remove_roles(roles['top50'])
elif rank > 10 and rank <= 50 and roles['top50'] not in member.roles:
await member.add_roles(roles['top50'])
await member.remove_roles(roles['top10'])
await member.remove_roles(roles['top1'])
elif rank > 50:
await member.remove_roles(roles['top1'])
await member.remove_roles(roles['top10'])
await member.remove_roles(roles['top50'])
await asyncio.sleep(60)
@client.event
async def on_ready():
global guild, roles
guild = discord.utils.get(client.guilds, name=GUILD)
roles['top10'] = discord.utils.get(guild.roles, id=801787467064672286)
roles['top1'] = discord.utils.get(guild.roles, id=798638767359524875)
roles['top50'] = discord.utils.get(guild.roles, id=803729539145924649)
logging.info('%s is connected to the following guild: %s(id: %d)', client.user, guild.name, guild.id)
client.loop.create_task(watch_roles())
@client.event
async def on_message(message):
global guild, roles
if message.author == client.user:
return
if '!connect' in message.content:
try:
user_token = message.content.split(' ')[1]
member = discord.utils.get(guild.members, name=message.author.name)
rank = get_rank(user_token)
users[str(member.id)] = user_token
logging.info("MESSAGE: from %s with token %s", message.author.name, user_token)
with open('members.json', 'w') as json_file:
json.dump(users, json_file)
if rank == 1:
await member.add_roles(roles['top1'])
response = "Congratulations, you're now Top 1. But for how long ?"
elif (rank <= 10):
await member.add_roles(roles['top10'])
response = "You've been granted the Top 10 role. Now, go away and flag !"
elif rank <= 50:
await member.add_roles(roles['top50'])
response = "You've been granted the Top 50 role. Now, go away and flag !"
else:
response = "No role for you now, but I'll keep watching you."
except IndexError:
response = 'usage: !connect 42ctf_token'
await message.author.create_dm()
await message.author.dm_channel.send(response)
client.run(TOKEN)

View File

@ -33,15 +33,38 @@
</br>Token </br>Token
<input type='text' readonly value='{{token}}'> <input type='text' readonly value='{{token}}'>
</br> </br>
<input class="form-control" type="submit" value="{% trans "Apply" %}"> <input class="form-control" type="submit" value="{% trans " Apply" %}">
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<div class="ctf-block">
<div class="ctf-head">
<h3>{% trans "Connected accounts" %}</h3>
</div> </div>
<div class="d-none d-md-block col-10 col-md-3 right-sidebar"> <div class="bloc-body">
<div class="d-flex">
{% if user.userprofileinfo.discord_id|length > 0 %}
<form action="{% url 'accounts:connections-disconnect-discord' %}" method='POST'
class="form-inline p-2">
{%csrf_token%}
<button class="btn btn-dark" type="submit">{% trans "Disconnect Discord" %}</button>
</form>
{% else %}
<form action="{% url 'accounts:connections-connect-discord' %}" method='POST'
class="form-inline p-2">
{%csrf_token%}
<button class="btn btn-dark" type="submit">{% trans "Connect Discord" %}</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item">{{ user.username }}</li> <li class="list-group-item">{{ user.username }}</li>
<li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li> <li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li>
@ -58,11 +81,10 @@
<form method='GET' action="{% url 'accounts:delete_account' %}"> <form method='GET' action="{% url 'accounts:delete_account' %}">
{%csrf_token%} {%csrf_token%}
<li class="list-group-item"> <li class="list-group-item">
<input class="form-control" type="submit" value="{% trans "Delete my account" %}"> <input class="form-control" type="submit" value="{% trans " Delete my account" %}">
</li> </li>
</form> </form>
</ul> </ul>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -4,6 +4,7 @@ from django.views.decorators.http import require_POST
from django.views.defaults import bad_request from django.views.defaults import bad_request
from django.urls import reverse from django.urls import reverse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.contrib.sites.models import Site
import os import os
oauth = OAuth() oauth = OAuth()
@ -23,8 +24,9 @@ oauth.register(
def connect(request): def connect(request):
if request.user.userprofileinfo.discord_id: if request.user.userprofileinfo.discord_id:
return bad_request(request, "Already connected") return bad_request(request, "Already connected")
site = Site.objects.get_current()
redirect_uri = reverse('accounts:connections-connect-discord-authorize') redirect_uri = reverse('accounts:connections-connect-discord-authorize')
redirect_uri = request.build_absolute_uri(redirect_uri) redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code
print(redirect_uri) print(redirect_uri)
return oauth.discord.authorize_redirect(request, redirect_uri) return oauth.discord.authorize_redirect(request, redirect_uri)

View File

@ -154,17 +154,7 @@ def profile(request, user_name):
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas, return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas,
'rank': rank, 'score' : somme, 'member' : member, 'cats':cats}) 'rank': rank, 'score' : somme, 'member' : member, 'cats':cats})
<<<<<<< HEAD
def rank(request, token):
all_users = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')
rank = 1
for elem in all_users:
if elem.token == token:
break
rank += 1
data = {"rank": rank}
return JsonResponse(data)
@login_required @login_required
def delete_account(request): def delete_account(request):
@ -182,3 +172,14 @@ def delete_account(request):
else: else:
return render(request, 'accounts/delete.html', {'deleted': False, 'bad_password': False} ) return render(request, 'accounts/delete.html', {'deleted': False, 'bad_password': False} )
def rank(request, token):
all_users = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')
rank = 1
for elem in all_users:
if elem.token == token:
break
rank += 1
data = {"rank": rank}
return JsonResponse(data)

0
src/api/__init__.py Normal file
View File

3
src/api/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
src/api/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'

View File

3
src/api/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
src/api/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
src/api/urls.py Normal file
View File

@ -0,0 +1,6 @@
from django.urls import path
from . import views
urlpatterns = [
path('bot/discord', views.discord_bot, name='discord_bot'),
]

27
src/api/views.py Normal file
View File

@ -0,0 +1,27 @@
from django.shortcuts import render
from accounts.models import UserProfileInfo
from django.http import JsonResponse
import os
# Create your views here.
def discord_bot(request):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
token = request.GET.get('token')
auth_token = os.getenv('BOT_TOKEN')
if (token != auth_token or not auth_token):
return JsonResponse({'error':'not authorized'})
all_users = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')
data = {}
rank = 1
for user in all_users:
if user.discord_id:
data[user.discord_id] = rank
rank += 1
return JsonResponse(data)

View File

@ -38,6 +38,7 @@ INSTALLED_APPS = [
'scoreboard.apps.ScoreboardConfig', 'scoreboard.apps.ScoreboardConfig',
'resources.apps.ResourcesConfig', 'resources.apps.ResourcesConfig',
'django.contrib.sites', 'django.contrib.sites',
'api.apps.ApiConfig',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -24,6 +24,7 @@ urlpatterns = [
path('', include('home.urls')), path('', include('home.urls')),
path('set_lang/<str:lang_code>', home.views.set_language, name="set_language"), path('set_lang/<str:lang_code>', home.views.set_language, name="set_language"),
path('dashboard/secret/admin', admin.site.urls), path('dashboard/secret/admin', admin.site.urls),
path('api/', include('api.urls'))
] ]
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(