change loading of variables on django server and add server_url to env

This commit is contained in:
2024-09-11 13:05:07 +02:00
parent 853f314992
commit f5cf64f8a7
5 changed files with 39 additions and 33 deletions

View File

@ -39,6 +39,7 @@ services:
SECRET_42: ${SECRET_42}
ICLOUD_USER: ${ICLOUD_USER}
ICLOUD_PASS: ${ICLOUD_PASS}
SERVER_URL: ${SERVER_URL}
depends_on:
- postgresql
restart: always

View File

@ -22,11 +22,10 @@ ARG UID_42
ARG SECRET_42
ARG ICLOUD_USER
ARG ICLOUD_PASS
ARG SERVER_URL
ENV DB_HOST=${DB_HOST}
ENV PYTHONUNBUFFERED=1
ENV UID_42=${UID_42}
ENV SECRET_42=${SECRET_42}
ENV DB_HOST=${DB_HOST}
COPY start.sh /root/start.sh
@ -40,11 +39,14 @@ COPY file/server /var/www/djangoserver/server
RUN chmod 755 /var/www/djangoserver/ && chown -R www-data:www-data /var/www/djangoserver/
RUN sed -i "s/VAR_DB_HOST/$DB_HOST/" /var/www/djangoserver/server/server/settings.py && \
sed -i "s/VAR_DB_NAME/$DB_NAME/" /var/www/djangoserver/server/server/settings.py && \
sed -i "s/VAR_DB_USERNAME/$DB_USERNAME/" /var/www/djangoserver/server/server/settings.py && \
sed -i "s/VAR_DB_PASSWORD/$DB_PASSWORD/" /var/www/djangoserver/server/server/settings.py
sed -i "s/VAR_DB_NAME/$DB_NAME/" /var/www/djangoserver/server/server/settings.py && \
sed -i "s/VAR_DB_USERNAME/$DB_USERNAME/" /var/www/djangoserver/server/server/settings.py && \
sed -i "s/VAR_DB_PASSWORD/$DB_PASSWORD/" /var/www/djangoserver/server/server/settings.py
RUN echo -n $UID_42:$SECRET_42 > /var/www/djangoserver/42_credentials
RUN echo -n $ICLOUD_USER:$ICLOUD_PASS > /var/www/djangoserver/icloud_credentials
RUN sed -i "s/ENV_UID_42/$UID_42/" /var/www/djangoserver/server/server/data.py && \
sed -i "s/ENV_SECRET_42/$SECRET_42/" /var/www/djangoserver/server/server/data.py && \
sed -i "s|ENV_SERVER_URL|$SERVER_URL|" /var/www/djangoserver/server/server/data.py && \
sed -i "s|ENV_ICLOUD_USER|$ICLOUD_USER|" /var/www/djangoserver/server/server/data.py && \
sed -i "s|ENV_ICLOUD_PASS|$ICLOUD_PASS|" /var/www/djangoserver/server/server/data.py
ENTRYPOINT ["sh", "/root/start.sh"]

View File

@ -0,0 +1,19 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# data.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/10 16:35:20 by tomoron #+# #+# #
# Updated: 2024/09/10 16:57:44 by tomoron ### ########.fr #
# #
# **************************************************************************** #
UID42 = "ENV_UID_42"
SECRET42 = "ENV_SECRET_42"
SERVER_URL = "ENV_SERVER_URL"
ICLOUD_PASS= "ENV_ICLOUD_PASS"
ICLOUD_USER = "ENV_ICLOUD_USER"

View File

@ -6,12 +6,13 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/09 08:08:00 by edbernar #+# #+# #
# Updated: 2024/09/10 14:02:32 by edbernar ### ########.fr #
# Updated: 2024/09/11 13:02:37 by tomoron ### ########.fr #
# #
# **************************************************************************** #
from email.mime.multipart import MIMEMultipart
from ..models import User, MailVerify
from ..data import ICLOUD_USER, ICLOUD_PASS, SERVER_URL
from email.mime.text import MIMEText
import smtplib
import random
@ -19,18 +20,9 @@ import re
import json
import hashlib
mail_pattern = "^((?!\.)[\w\-_.]*[^.])(@\w+)(\.\w+(\.\w+)?[^.\W])$"
mail_pattern = "^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$"
password_pattern = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"
URLMAIL = "https://localhost:8000/verify?token="
ICLOUD_MAIL = None
ICLOUD_PASS = None
with open("/var/www/djangoserver/icloud_credentials", 'r') as f:
creds = f.read().split(':')
ICLOUD_MAIL = creds[0]
ICLOUD_PASS = creds[1]
print(ICLOUD_MAIL)
print(ICLOUD_PASS)
URLMAIL = SERVER_URL + "/verify?token="
def createAccount(socket, content):
if (socket.logged_in):

View File

@ -1,19 +1,11 @@
from django.http import HttpResponse
from django.shortcuts import render, redirect
from .models import User, MailVerify
from .data import UID42, SECRET42, SERVER_URL
import requests
import json
import os
UID42 = None
SECRET42 = None
with open("/var/www/djangoserver/42_credentials", 'r') as f:
creds = f.read().split(':')
UID42=creds[0]
SECRET42=creds[1]
TOKENURL = 'https://api.intra.42.fr/oauth/token'
INFOURL = 'https://api.intra.42.fr/v2/me'
REDIRECT = 'https://localhost:8000/login42'
def index(request):
try:
@ -25,7 +17,7 @@ def index(request):
def homePage(request):
request.session.save()
link42 = f"https://api.intra.42.fr/oauth/authorize?client_id={UID42}&redirect_uri={REDIRECT}&response_type=code&scope=public"
link42 = f"https://api.intra.42.fr/oauth/authorize?client_id={UID42}&redirect_uri={SERVER_URL}/login42&response_type=code&scope=public"
return render(request, "homePage.html", {"link42" : link42})
def lobbyPage(request):
@ -59,10 +51,10 @@ def login42(request):
'client_id': UID42,
'client_secret': SECRET42,
'code': code,
'redirect_uri': REDIRECT
'redirect_uri': SERVER_URL+"/login42"
}
print("\033[31m",data)
response = requests.post(TOKENURL, data=data)
response = requests.post('https://api.intra.42.fr/oauth/token', data=data)
if (response.status_code != 200):
print(response.json())
return HttpResponse("couln't get authorization token, likely invalid code")
@ -70,7 +62,7 @@ def login42(request):
headers = {
'Authorization': f'Bearer {response["access_token"]}',
}
response = requests.get(INFOURL, headers=headers)
response = requests.get('https://api.intra.42.fr/v2/me', headers=headers)
if (response.status_code != 200):
return HttpResponse("couln't get user info... what, why ?")
response = response.json()