Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
LanguageLab
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Serge Bibauw
LanguageLab
Validations
70eee4f0
Valider
70eee4f0
rédigé
Il y a 5 mois
par
DavePk04
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
--wip--
parent
3f2ca2cd
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
frontend/src/lib/api/users.ts
+33
-0
33 ajouts, 0 suppression
frontend/src/lib/api/users.ts
frontend/src/routes/tutor/register/+page.svelte
+68
-52
68 ajouts, 52 suppressions
frontend/src/routes/tutor/register/+page.svelte
avec
101 ajouts
et
52 suppressions
frontend/src/lib/api/users.ts
+
33
−
0
Voir le fichier @
70eee4f0
...
@@ -14,6 +14,39 @@ export async function getUserAPI(fetch: fetchType, user_id: number): Promise<any
...
@@ -14,6 +14,39 @@ export async function getUserAPI(fetch: fetchType, user_id: number): Promise<any
return
await
response
.
json
();
return
await
response
.
json
();
}
}
export
async
function
loginAPI
(
fetch
:
fetchType
,
email
:
string
,
password
:
string
):
Promise
<
{
accessToken
:
string
|
null
;
refreshToken
:
string
|
null
}
>
{
const
response
=
await
fetch
(
`/tmp-api/v1/auth/login`
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
Accept
:
'
application/json
'
,
},
credentials
:
'
include
'
,
body
:
JSON
.
stringify
({
email
,
password
}),
});
if
(
!
response
.
ok
)
{
console
.
error
(
`Login failed:`
,
await
response
.
json
());
return
{
accessToken
:
null
,
refreshToken
:
null
};
}
const
cookies
=
document
.
cookie
.
split
(
'
;
'
).
reduce
((
acc
,
cookie
)
=>
{
const
[
key
,
value
]
=
cookie
.
split
(
'
=
'
);
acc
[
key
]
=
decodeURIComponent
(
value
);
return
acc
;
},
{}
as
Record
<
string
,
string
>
);
return
{
accessToken
:
cookies
[
'
access_token
'
]
||
null
,
refreshToken
:
cookies
[
'
refresh_token
'
]
||
null
,
};
}
export
async
function
createUserContactAPI
(
export
async
function
createUserContactAPI
(
fetch
:
fetchType
,
fetch
:
fetchType
,
user_id
:
number
,
user_id
:
number
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
frontend/src/routes/tutor/register/+page.svelte
+
68
−
52
Voir le fichier @
70eee4f0
...
@@ -5,13 +5,14 @@
...
@@ -5,13 +5,14 @@
import
{
onMount
}
from
'
svelte
'
;
import
{
onMount
}
from
'
svelte
'
;
import
Timeslots
from
'
$lib/components/users/timeslots.svelte
'
;
import
Timeslots
from
'
$lib/components/users/timeslots.svelte
'
;
import
User
from
'
$lib/types/user
'
;
import
User
from
'
$lib/types/user
'
;
import
{
getUsersAPI
,
patchUserAPI
,
getUserContactsAPI
,
createUser
API
}
from
'
$lib/api/users
'
;
import
{
getUsersAPI
,
patchUserAPI
,
getUserContactsAPI
,
getUserAPI
,
login
API
}
from
'
$lib/api/users
'
;
import
{
Icon
,
Envelope
,
Key
,
UserCircle
,
Calendar
,
QuestionMarkCircle
}
from
'
svelte-hero-icons
'
;
import
{
Icon
,
Envelope
,
Key
,
UserCircle
,
Calendar
,
QuestionMarkCircle
}
from
'
svelte-hero-icons
'
;
import
Typingtest
from
'
$lib/components/tests/typingtest.svelte
'
;
import
Typingtest
from
'
$lib/components/tests/typingtest.svelte
'
;
import
{
formatToUTCDate
}
from
'
$lib/utils/date
'
;
import
{
formatToUTCDate
}
from
'
$lib/utils/date
'
;
import
type
{
PageData
}
from
'
./$types
'
;
import
type
{
PageData
}
from
'
./$types
'
;
let
{
data
}:
{
data
:
PageData
}
=
$props
();
let
{
data
}:
{
data
:
PageData
}
=
$props
();
console
.
log
(
'
Data:
'
,
data
);
let
user
=
data
.
user
;
let
user
=
data
.
user
;
let
current_step
=
$state
(
0
);
let
current_step
=
$state
(
0
);
...
@@ -24,6 +25,7 @@
...
@@ -24,6 +25,7 @@
return
;
return
;
}
}
User
.
parseAll
(
await
getUsersAPI
(
fetch
));
User
.
parseAll
(
await
getUsersAPI
(
fetch
));
console
.
log
(
'
User:
'
,
user
);
if
(
!
user
.
home_language
||
!
user
.
target_language
||
!
user
.
birthdate
||
!
user
.
gender
)
{
if
(
!
user
.
home_language
||
!
user
.
target_language
||
!
user
.
birthdate
||
!
user
.
gender
)
{
current_step
=
3
;
current_step
=
3
;
...
@@ -54,59 +56,73 @@
...
@@ -54,59 +56,73 @@
let
timeslots
=
0
n
;
let
timeslots
=
0
n
;
async
function
onRegister
()
{
async
function
onRegister
()
{
// Basic validation
if
(
nickname
===
''
||
email
===
''
||
password
===
''
||
confirmPassword
===
''
)
{
if
(
nickname
==
''
||
email
==
''
||
password
==
''
||
confirmPassword
==
''
)
{
message
=
$t
(
'
register.error.emptyFields
'
);
message
=
$t
(
'
register.error.emptyFields
'
);
return
;
return
;
}
}
if
(
password
.
length
<
8
)
{
if
(
password
.
length
<
8
)
{
message
=
$t
(
'
register.error.passwordRules
'
);
message
=
$t
(
'
register.error.passwordRules
'
);
return
;
return
;
}
}
if
(
password
!==
confirmPassword
)
{
if
(
password
!=
confirmPassword
)
{
message
=
$t
(
'
register.error.differentPasswords
'
);
message
=
$t
(
'
register.error.differentPasswords
'
);
return
;
return
;
}
}
const
emailRegex
=
/^
[
a-zA-Z0-9._-
]
+@
[
a-zA-Z0-9.-
]
+
\.[
a-zA-Z
]{2,6}
$/
;
const
emailRegex
=
/^
[
a-zA-Z0-9._-
]
+@
[
a-zA-Z0-9.-
]
+
\.[
a-zA-Z
]{2,6}
$/
;
if
(
!
emailRegex
.
test
(
email
))
{
if
(
!
emailRegex
.
test
(
email
))
{
message
=
$t
(
'
register.error.emailRules
'
);
message
=
$t
(
'
register.error.emailRules
'
);
return
;
return
;
}
}
message
=
''
;
message
=
''
;
try
{
try
{
const
response
=
await
fetch
(
'
http://127.0.0.1:8000/tmp-api/v1/auth/register
'
,
{
const
response
=
await
fetch
(
'
http://127.0.0.1:8000/tmp-api/v1/auth/register
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
Accept
:
'
application/json
'
Accept
:
'
application/json
'
},
},
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
({
email
,
email
,
password
,
password
,
nickname
,
nickname
,
is_tutor
:
true
is_tutor
:
true
})
})
});
});
if
(
response
.
status
===
201
)
{
if
(
response
.
status
===
201
)
{
const
userId
=
await
response
.
text
();
const
userId
=
await
response
.
text
();
console
.
log
(
'
User created successfully with ID:
'
,
userId
);
console
.
log
(
'
User created successfully with ID:
'
,
userId
);
console
.
log
(
'
response:
'
,
response
);
message
=
$t
(
'
register.success
'
);
const
result
=
await
loginAPI
(
fetch
,
email
,
password
);
return
;
console
.
log
(
'
result:
'
,
result
);
}
else
{
const
errorData
=
await
response
.
json
();
console
.
error
(
'
Registration failed:
'
,
errorData
);
user
=
await
getUserAPI
(
fetch
,
parseInt
(
userId
));
message
=
errorData
.
detail
||
$t
(
'
register.error.generic
'
);
if
(
user
)
{
}
console
.
log
(
'
User details fetched successfully:
'
,
user
);
}
catch
(
error
)
{
message
=
$t
(
'
register.success
'
);
console
.
error
(
'
Error during registration:
'
,
error
);
current_step
++
;
// Move to the next step
message
=
$t
(
'
register.error.generic
'
);
}
else
{
}
console
.
error
(
'
Failed to fetch user details
'
);
}
toastAlert
(
'
Failed to fetch user details. Please try again.
'
);
}
}
else
{
const
errorData
=
await
response
.
json
();
console
.
error
(
'
Registration failed:
'
,
errorData
);
message
=
errorData
.
detail
||
$t
(
'
register.error.generic
'
);
}
}
catch
(
error
)
{
console
.
error
(
'
Error during registration:
'
,
error
);
message
=
$t
(
'
register.error.generic
'
);
}
}
async
function
onData
()
{
async
function
onData
()
{
const
user_id
=
user
.
id
;
console
.
log
(
'
onData:
'
,
user
);
const
user_id
=
user
?.
id
;
if
(
!
user_id
)
{
if
(
!
user_id
)
{
toastAlert
(
'
Failed to get current user ID
'
);
toastAlert
(
'
Failed to get current user ID
'
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter