Skip to content

Commit f4f7c68

Browse files
authored
Merge pull request #72 from bertt6/42auth-fix
42 auth fix
2 parents 413bcd4 + a078bca commit f4f7c68

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

API/Apps/Profile/api/api_42.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2+
import random
23

34
import requests
45
from django.contrib.auth.models import User
56
from rest_framework.response import Response
6-
77
from Apps.Auth.serializers import RegisterWith42Serializer
88
from Apps.Auth.utils import send_email
99
from Apps.Profile.api.Serializers import UserSerializer
@@ -28,14 +28,17 @@ def api_42(code):
2828

2929

3030
def login_with_42(username, email, image):
31-
if not User.objects.filter(username=username).exists():
31+
if not User.objects.filter(email=email).exists():
32+
if User.objects.filter(username=username).exists():
33+
username = username + "_" + str(random.randint(1000, 9999))
3234
serializer = RegisterWith42Serializer(data={"username": username, "email": email})
3335
if not serializer.is_valid():
3436
return Response(serializer.errors, status=400)
3537
serializer.save()
36-
user = User.objects.get(username=username)
37-
if not user.profile.profile_picture:
38+
user = User.objects.get(email=email)
39+
if user.profile.profile_picture == 'profile-pictures/default.svg':
3840
user.profile.save_image_from_url(image)
41+
user.profile.save()
3942
if user:
4043
send_email(user)
4144
return Response(data={'user': UserSerializer(user).data}, status=200)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.0.3 on 2024-05-12 12:35
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
('Profile', '0001_initial'),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name='profile',
14+
name='is_42auth',
15+
field=models.BooleanField(default=False),
16+
),
17+
]

API/static/scripts/register.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const registerSubmit = async (event) => {
1616
spinner.render();
1717
button.disabled = true;
1818
try{
19-
const response = await fetch(`register/`, {
19+
const response = await fetch(`${API_URL}/auth/register/`, {
2020
method: 'POST',
2121
headers: {
2222
'Content-Type': 'application/json',

API/static/scripts/spa.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const routes = new Map([
108108
<div class="register-input-wrapper">
109109
<label for="password">password</label>
110110
<input
111-
type="text"
111+
type="password"
112112
class="register-input p-2"
113113
placeholder="PASSWORD"
114114
id="password"
@@ -118,7 +118,7 @@ const routes = new Map([
118118
<div class="register-input-wrapper">
119119
<label for="password">Re enter your password</label>
120120
<input
121-
type="text"
121+
type="password"
122122
class="register-input p-2"
123123
id="password2"
124124
required

API/templates/auth/register.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ <h1 style="color: white">REGISTER</h1>
5252
<div class="register-input-wrapper">
5353
<label for="password">password</label>
5454
<input
55-
type="text"
55+
type="password"
5656
class="register-input p-2"
5757
placeholder="PASSWORD"
5858
id="password"
@@ -62,7 +62,7 @@ <h1 style="color: white">REGISTER</h1>
6262
<div class="register-input-wrapper">
6363
<label for="password">Re enter your password</label>
6464
<input
65-
type="text"
65+
type="password"
6666
class="register-input p-2"
6767
id="password2"
6868
required

0 commit comments

Comments
 (0)