File tree 5 files changed +29
-9
lines changed
5 files changed +29
-9
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
+ import random
2
3
3
4
import requests
4
5
from django .contrib .auth .models import User
5
6
from rest_framework .response import Response
6
-
7
7
from Apps .Auth .serializers import RegisterWith42Serializer
8
8
from Apps .Auth .utils import send_email
9
9
from Apps .Profile .api .Serializers import UserSerializer
@@ -28,14 +28,17 @@ def api_42(code):
28
28
29
29
30
30
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 ))
32
34
serializer = RegisterWith42Serializer (data = {"username" : username , "email" : email })
33
35
if not serializer .is_valid ():
34
36
return Response (serializer .errors , status = 400 )
35
37
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' :
38
40
user .profile .save_image_from_url (image )
41
+ user .profile .save ()
39
42
if user :
40
43
send_email (user )
41
44
return Response (data = {'user' : UserSerializer (user ).data }, status = 200 )
Original file line number Diff line number Diff line change
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
+ ]
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const registerSubmit = async (event) => {
16
16
spinner . render ( ) ;
17
17
button . disabled = true ;
18
18
try {
19
- const response = await fetch ( `register/` , {
19
+ const response = await fetch ( `${ API_URL } /auth/ register/` , {
20
20
method : 'POST' ,
21
21
headers : {
22
22
'Content-Type' : 'application/json' ,
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ const routes = new Map([
108
108
<div class="register-input-wrapper">
109
109
<label for="password">password</label>
110
110
<input
111
- type="text "
111
+ type="password "
112
112
class="register-input p-2"
113
113
placeholder="PASSWORD"
114
114
id="password"
@@ -118,7 +118,7 @@ const routes = new Map([
118
118
<div class="register-input-wrapper">
119
119
<label for="password">Re enter your password</label>
120
120
<input
121
- type="text "
121
+ type="password "
122
122
class="register-input p-2"
123
123
id="password2"
124
124
required
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ <h1 style="color: white">REGISTER</h1>
52
52
< div class ="register-input-wrapper ">
53
53
< label for ="password "> password</ label >
54
54
< input
55
- type ="text "
55
+ type ="password "
56
56
class ="register-input p-2 "
57
57
placeholder ="PASSWORD "
58
58
id ="password "
@@ -62,7 +62,7 @@ <h1 style="color: white">REGISTER</h1>
62
62
< div class ="register-input-wrapper ">
63
63
< label for ="password "> Re enter your password</ label >
64
64
< input
65
- type ="text "
65
+ type ="password "
66
66
class ="register-input p-2 "
67
67
id ="password2 "
68
68
required
You can’t perform that action at this time.
0 commit comments