From 327034b6b9f3a2870f51ebe741aeb053ca5f1c5b Mon Sep 17 00:00:00 2001 From: Mathias Gagnepain Date: Thu, 20 Jun 2024 18:49:39 +0200 Subject: [PATCH] fix register username, picture, color and redirection to home --- .../lib/modules/database.dart | 30 +++++++++++++++---- src/adopte_un_candidat/lib/register.dart | 15 +++++++--- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/adopte_un_candidat/lib/modules/database.dart b/src/adopte_un_candidat/lib/modules/database.dart index 536a02e..b124e63 100644 --- a/src/adopte_un_candidat/lib/modules/database.dart +++ b/src/adopte_un_candidat/lib/modules/database.dart @@ -438,9 +438,8 @@ class Database { } return ["FFFFFF", "FFFFFF"]; } - - initializeUser(String email, String password, String firstName, String lastName, String userName, String picture, List colors) async { - FirebaseAuth.instance.createUserWithEmailAndPassword( + Future initializeUser(String email, String password, String firstName, String lastName, String userName, String picture, List colors) async { + return FirebaseAuth.instance.createUserWithEmailAndPassword( email: email, password: password, ).then((userCredential) { @@ -448,10 +447,11 @@ class Database { User? user = userCredential.user; // Add additional user data to Firestore createUser(user!.uid, email, firstName, lastName, userName, picture, colors); + return user.uid; }).catchError((error) { - // User creation failed + // User creation fail if (kDebugMode) { - print("Error creating user: $error"); + print("Error creating ur: $error"); } }); } @@ -471,7 +471,12 @@ class Database { 'colors': colors, 'professional_status': '', 'profile_picture': picture, - 'soft_skills': {} + 'soft_skills': { + 'Analytical': [], + 'Self-management': [], + 'Interpersonal': [], + 'Social': [] + } }); } @@ -560,6 +565,19 @@ class Database { }); } + updatePictureAndColors(String id, String picture, List colors) async { + await FirebaseFirestore.instance.collection("user").doc(id).update({ + 'profile_picture': picture, + 'colors': colors, + }); + } + + updateUsername(String id, String username) async { + await FirebaseFirestore.instance.collection("user").doc(id).update({ + 'name': username, + }); + } + // Future softSkillsUpdate(String id, Map softSkills) async { // await FirebaseFirestore.instance.collection("user").doc(id).update({ // 'soft_skills': softSkills, diff --git a/src/adopte_un_candidat/lib/register.dart b/src/adopte_un_candidat/lib/register.dart index 25e4fdb..8dd37f9 100644 --- a/src/adopte_un_candidat/lib/register.dart +++ b/src/adopte_un_candidat/lib/register.dart @@ -45,6 +45,7 @@ class RegisterState extends State { List colors = ["FFFFFF", "FFFFFF"]; String pictureLink = ""; String userName = "River Stone"; + String userId = ""; @override void initState() { @@ -681,9 +682,11 @@ class RegisterState extends State { child: NextButton( onPressed: () async { if (userInformation()) { - await Database().initializeUser(emailController.text.trim(), passwordController.text.trim(), firstNameController.text.trim(), lastNameController.text.trim(), userName, pictureLink, colors); - setState(() { - page = 6; + await Database().initializeUser(emailController.text.trim(), passwordController.text.trim(), firstNameController.text.trim(), lastNameController.text.trim(), userName, pictureLink, colors).then((value) { + setState(() { + page = 6; + userId = value; + }); }); } else { if (kDebugMode) { @@ -829,6 +832,7 @@ class RegisterState extends State { setState(() { page = 7; }); + Database().updateUsername(userId, userName); }, ), ), @@ -962,6 +966,7 @@ class RegisterState extends State { onPressed: () { setState(() { page = 8; + Database().updatePictureAndColors(userId, pictureLink, colors); }); }, ), @@ -1185,7 +1190,9 @@ class RegisterState extends State { alignment: Alignment.centerRight, padding: const EdgeInsets.only(right: 40), child: NextButton( - onPressed: () {}, + onPressed: () { + context.replaceNamed('home'); + }, ), ), )