change loading of variables on django server and add server_url to env
This commit is contained in:
@ -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"
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user