Merge pull request '🔀 add support for password, email and username modifications + const and fixes' (#3) from profile into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #3
pull/4/head
remrem 1 year ago
commit bc89324f2a

@ -35,8 +35,8 @@ class MyApp extends StatelessWidget {
// tested with just a hot reload. // tested with just a hot reload.
primaryColor: TColor.primaryColor1, primaryColor: TColor.primaryColor1,
fontFamily: "Poppins"), fontFamily: "Poppins"),
//home: const StartedView(),
home: const SignUpView(), home: const SignUpView(),
//home: const ProfileView(),
); );
} }
} }

@ -0,0 +1,55 @@
import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart';
import 'package:smartfit_app_mobile/modele/api/request_api.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
import 'package:email_validator/email_validator.dart';
import 'package:tuple/tuple.dart';
import 'dart:convert';
import 'package:crypto/crypto.dart';
class ApiWrapper {
IDataStrategy api = RequestApi();
Future<bool> modifyUserInfo(String infoToModify, String value, String token,
InfoMessage infoManager) async {
if (infoToModify == 'email' && EmailValidator.validate(value) ||
infoToModify == 'password' ||
infoToModify == 'username') {
Tuple2<bool, String> res =
await api.modifAttribut(token, infoToModify, value);
if (res.item1 == true) {
infoManager.displayMessage(
"${infoToModify.capitalize()} modified succesfully !", false);
return true;
} else {
infoManager.displayMessage(
"An error occured :/ Please try again.", true);
return false;
}
} else {
infoManager.displayMessage(
"This is not a valid $infoToModify :/ Please try again.", true);
return false;
}
}
Future<Tuple2<bool, String>> login(
String password, String email, InfoMessage infoManager) async {
String hash = sha256.convert(utf8.encode(password)).toString();
Tuple2<bool, String> res = await api.connexion(email, hash);
if (res.item1) {
return Tuple2(true, res.item2); // return token
} else {
infoManager.displayMessage(
"Authentification failed! Enter your actual password carefully.",
true);
return const Tuple2(false, "An error occured during connexion!");
} // need to be better
}
}
extension StringExtension on String {
String capitalize() {
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
}
}

@ -37,6 +37,6 @@ abstract class IDataStrategy {
Future<void> updateUsername(String token, String username); Future<void> updateUsername(String token, String username);
*/ */
Future<Tuple2> modifAttribut( Future<Tuple2<bool, String>> modifAttribut(
String token, String nameAttribut, String newValue); String token, String nameAttribut, String newValue);
} }

@ -123,7 +123,7 @@ class RequestApi extends IDataStrategy {
} }
@override @override
Future<Tuple2> modifAttribut( Future<Tuple2<bool, String>> modifAttribut(
String token, String nameAttribut, String newValue) async { String token, String nameAttribut, String newValue) async {
final response = await http.put(Uri.parse('$urlApi/user/$nameAttribut'), final response = await http.put(Uri.parse('$urlApi/user/$nameAttribut'),
headers: <String, String>{ headers: <String, String>{
@ -133,8 +133,8 @@ class RequestApi extends IDataStrategy {
body: jsonEncode(<String, String>{nameAttribut: newValue})); body: jsonEncode(<String, String>{nameAttribut: newValue}));
if (response.statusCode == 200) { if (response.statusCode == 200) {
Map<String, dynamic> json = jsonDecode(response.body); //Map<String, dynamic> json = jsonDecode(response.body);
return Tuple2(true, json); return const Tuple2(true, "200 - OK");
} }
if (response.statusCode == 400) { if (response.statusCode == 400) {
return const Tuple2(false, "400 - BAD REQUEST"); return const Tuple2(false, "400 - BAD REQUEST");

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class InfoMessage {
String message = "";
Color messageColor = Colors.transparent;
bool isVisible = false;
void displayMessage(String message, bool isError) {
this.message = message;
isVisible = true;
if (isError) {
messageColor = Colors.red;
} else {
messageColor = Colors.green;
}
}
}

@ -72,217 +72,214 @@ class _MobileLoginView extends State<MobileLoginView> {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: SingleChildScrollView( body: SafeArea(
child: SafeArea( child: Container(
child: Container( height: media.height * 0.9,
height: media.height * 0.9, padding: const EdgeInsets.symmetric(horizontal: 20),
padding: const EdgeInsets.symmetric(horizontal: 20), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ Text(
Text( "Bienvenue",
"Bienvenue", style: TextStyle(color: TColor.gray, fontSize: 16),
style: TextStyle(color: TColor.gray, fontSize: 16), ),
), Text(
Text( "Se connecter",
"Se connecter", style: TextStyle(
style: TextStyle( color: TColor.black,
color: TColor.black, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.w700),
fontWeight: FontWeight.w700), ),
), SizedBox(
SizedBox( height: media.width * 0.05,
height: media.width * 0.05, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Email",
hitText: "Email", icon: "assets/img/email.svg",
icon: "assets/img/email.svg", keyboardType: TextInputType.emailAddress,
keyboardType: TextInputType.emailAddress, controller: controllerTextEmail,
controller: controllerTextEmail, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( controller: controllerTextPassword,
controller: controllerTextPassword, hitText: "Mot de passe",
hitText: "Mot de passe", icon: "assets/img/lock.svg",
icon: "assets/img/lock.svg", obscureText: _obscureText,
obscureText: _obscureText, rigtIcon: TextButton(
rigtIcon: TextButton( onPressed: _toggle,
onPressed: _toggle, child: Container(
child: Container( alignment: Alignment.center,
alignment: Alignment.center, width: 20,
height: 20,
child: SvgPicture.asset(
"assets/img/show_password.svg",
width: 20, width: 20,
height: 20, height: 20,
child: SvgPicture.asset( fit: BoxFit.contain,
"assets/img/show_password.svg", ))),
width: 20, ),
height: 20, Row(
fit: BoxFit.contain, mainAxisAlignment: MainAxisAlignment.center,
))), children: [
), Text(
Row( "Mot de passe oublié ?",
mainAxisAlignment: MainAxisAlignment.center, style: TextStyle(
children: [ color: TColor.gray,
Text( fontSize: 15,
"Mot de passe oublié ?", decoration: TextDecoration.underline),
style: TextStyle( ),
color: TColor.gray, ],
fontSize: 15, ),
decoration: TextDecoration.underline), SizedBox(
), height: media.width * 0.04,
], ),
), Visibility(
SizedBox( visible: _errorLogin,
height: media.width * 0.04, child: Text("Error - $_msgError",
), style: TextStyle(color: TColor.red))),
Visibility( const Spacer(),
visible: _errorLogin, RoundButton(
child: Text("Error - $_msgError", title: "Se connecter",
style: TextStyle(color: TColor.red))), onPressed: () async {
const Spacer(), if (!emailValidate || !passwordValidate) {
RoundButton( _printMsgError("Les champs renseigné ne sont pas valide");
title: "Se connecter", return;
onPressed: () async { }
if (!emailValidate || !passwordValidate) { Tuple2<bool, String> result =
_printMsgError( await util.checkLoginAndPassword(
"Les champs renseigné ne sont pas valide"); controllerTextEmail.text,
return; controllerTextPassword.text);
}
Tuple2<bool, String> result =
await util.checkLoginAndPassword(
controllerTextEmail.text,
controllerTextPassword.text);
if (result.item1 == true) {
Tuple2 infoUser = await util.getUserInfo(result.item2);
if (infoUser.item1 == false) { if (result.item1 == true) {
//print("Erreur - Impossible de récupéré les données de l'utilisateur"); Tuple2 infoUser = await util.getUserInfo(result.item2);
_printMsgError(
"Impossible de récupéré les données de l'utilisateur - {$infoUser.item2}");
} else {
util.fillUser(context, infoUser.item2, result.item2);
Navigator.push( if (infoUser.item1 == false) {
context, //print("Erreur - Impossible de récupéré les données de l'utilisateur");
MaterialPageRoute( _printMsgError(
builder: (context) => const MainTabView())); "Impossible de récupéré les données de l'utilisateur - {$infoUser.item2}");
}
} else { } else {
_printMsgError("Connexion refuser - ${result.item2}"); util.fillUser(context, infoUser.item2, result.item2);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MainTabView()));
} }
}), } else {
SizedBox( _printMsgError("Connexion refuser - ${result.item2}");
height: media.width * 0.04, }
), }),
Row( SizedBox(
// crossAxisAlignment: CrossAxisAlignment., height: media.width * 0.04,
children: [ ),
Expanded( Row(
child: Container( // crossAxisAlignment: CrossAxisAlignment.,
height: 1, children: [
color: TColor.gray.withOpacity(0.5), Expanded(
)),
Text(
" Or ",
style: TextStyle(color: TColor.black, fontSize: 12),
),
Expanded(
child: Container(
height: 1,
color: TColor.gray.withOpacity(0.5),
)),
],
),
SizedBox(
height: media.width * 0.04,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {},
child: Container( child: Container(
width: 50, height: 1,
height: 50, color: TColor.gray.withOpacity(0.5),
alignment: Alignment.center, )),
decoration: BoxDecoration( Text(
color: TColor.white, " Or ",
border: Border.all( style: TextStyle(color: TColor.black, fontSize: 12),
width: 1, ),
color: TColor.gray.withOpacity(0.4), Expanded(
), child: Container(
borderRadius: BorderRadius.circular(15), height: 1,
), color: TColor.gray.withOpacity(0.5),
child: Image.asset( )),
"assets/img/google.png", ],
width: 20, ),
height: 20, SizedBox(
height: media.width * 0.04,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {},
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: TColor.white,
border: Border.all(
width: 1,
color: TColor.gray.withOpacity(0.4),
), ),
borderRadius: BorderRadius.circular(15),
),
child: Image.asset(
"assets/img/google.png",
width: 20,
height: 20,
), ),
), ),
SizedBox( ),
width: media.width * 0.04, SizedBox(
), width: media.width * 0.04,
GestureDetector( ),
onTap: () {}, GestureDetector(
child: Container( onTap: () {},
width: 50, child: Container(
height: 50, width: 50,
alignment: Alignment.center, height: 50,
decoration: BoxDecoration( alignment: Alignment.center,
color: TColor.white, decoration: BoxDecoration(
border: Border.all( color: TColor.white,
width: 1, border: Border.all(
color: TColor.gray.withOpacity(0.4), width: 1,
), color: TColor.gray.withOpacity(0.4),
borderRadius: BorderRadius.circular(15),
),
child: Image.asset(
"assets/img/suunto.png",
width: 35,
height: 35,
), ),
borderRadius: BorderRadius.circular(15),
), ),
) child: Image.asset(
], "assets/img/suunto.png",
), width: 35,
SizedBox( height: 35,
height: media.width * 0.04, ),
), ),
TextButton( )
onPressed: () { ],
Navigator.pop(context); ),
}, SizedBox(
child: Column( height: media.width * 0.04,
mainAxisSize: MainAxisSize.min, ),
children: [ TextButton(
Text( onPressed: () {
"Vous n'avez pas toujours pas de compte ? ", Navigator.pop(context);
style: TextStyle( },
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Vous n'avez pas toujours pas de compte ? ",
style: TextStyle(
color: TColor.black,
fontSize: 14,
),
),
Text(
"Créer un compte",
style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
), fontWeight: FontWeight.w700),
), )
Text( ],
"Créer un compte",
style: TextStyle(
color: TColor.black,
fontSize: 14,
fontWeight: FontWeight.w700),
)
],
),
),
SizedBox(
height: media.width * 0.04,
), ),
], ),
), SizedBox(
height: media.width * 0.04,
),
],
), ),
), ),
), ),

@ -91,230 +91,227 @@ class _MobileSignUpView extends State<MobileSignUpView> {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: SingleChildScrollView( body: SafeArea(
child: SafeArea( child: Padding(
child: Padding( padding: const EdgeInsets.symmetric(horizontal: 20),
padding: const EdgeInsets.symmetric(horizontal: 20), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ Text(
Text( "Bienvenue,",
"Bienvenue,", style: TextStyle(color: TColor.gray, fontSize: 16),
style: TextStyle(color: TColor.gray, fontSize: 16), ),
), Text(
Text( "Créer un compte",
"Créer un compte", style: TextStyle(
style: TextStyle( color: TColor.black,
color: TColor.black, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.w700),
fontWeight: FontWeight.w700), ),
), SizedBox(
SizedBox( height: media.width * 0.05,
height: media.width * 0.05, ),
), RoundTextField(
RoundTextField( hitText: "Prénom",
hitText: "Prénom", icon: "assets/img/user_text.svg",
icon: "assets/img/user_text.svg", controller: controllerUsername,
controller: controllerUsername, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Email",
hitText: "Email", icon: "assets/img/email.svg",
icon: "assets/img/email.svg", keyboardType: TextInputType.emailAddress,
keyboardType: TextInputType.emailAddress, controller: controllerTextEmail,
controller: controllerTextEmail, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Mot de passe",
hitText: "Mot de passe", icon: "assets/img/lock.svg",
icon: "assets/img/lock.svg", obscureText: _obscureText,
obscureText: _obscureText, controller: controllerTextPassword,
controller: controllerTextPassword, rigtIcon: TextButton(
rigtIcon: TextButton( onPressed: _toggle,
onPressed: _toggle, child: Container(
child: Container( alignment: Alignment.center,
alignment: Alignment.center, width: 20,
height: 20,
child: SvgPicture.asset(
"assets/img/show_password.svg",
width: 20, width: 20,
height: 20, height: 20,
child: SvgPicture.asset( fit: BoxFit.contain,
"assets/img/show_password.svg", ))),
width: 20, ),
height: 20, Row(
fit: BoxFit.contain, // crossAxisAlignment: CrossAxisAlignment.,
))), children: [
), IconButton(
Row( onPressed: () {
// crossAxisAlignment: CrossAxisAlignment., _check();
children: [ },
IconButton( icon: Icon(
onPressed: () { _isCheck
_check(); ? Icons.check_box_outlined
}, : Icons.check_box_outline_blank_outlined,
icon: Icon( color: TColor.gray,
_isCheck size: 20,
? Icons.check_box_outlined
: Icons.check_box_outline_blank_outlined,
color: TColor.gray,
size: 20,
),
), ),
Padding( ),
padding: const EdgeInsets.only(top: 8), Padding(
child: Text( padding: const EdgeInsets.only(top: 8),
"En continuant, vous acceptez notre Politique de\nconfidentialité et nos Conditions d'utilisation.", child: Text(
style: TextStyle(color: TColor.gray, fontSize: 10), "En continuant, vous acceptez notre Politique de\nconfidentialité et nos Conditions d'utilisation.",
), style: TextStyle(color: TColor.gray, fontSize: 10),
)
],
),
SizedBox(
height: media.width * 0.05,
),
Visibility(
visible: _errorCreateUser,
child: Text("Error - $_msgError",
style: TextStyle(color: TColor.red))),
SizedBox(
height: media.width * 0.4,
),
RoundButton(
title: "Créer un compte",
onPressed: () async {
if (!emailValidate ||
!passwordValidate ||
!usernameValidate) {
_printMsgError(
"Les champs renseigné ne sont pas valide");
return;
}
Tuple2<bool, String> result = await util.createUser(
controllerTextEmail.text,
controllerUsername.text,
controllerTextPassword.text);
if (result.item1) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
} else {
_printMsgError(result.item2);
}
}),
SizedBox(
height: media.width * 0.04,
),
Row(
// crossAxisAlignment: CrossAxisAlignment.,
children: [
Expanded(
child: Container(
height: 1,
color: TColor.gray.withOpacity(0.5),
)),
Text(
" Ou ",
style: TextStyle(color: TColor.black, fontSize: 12),
), ),
Expanded( )
child: Container( ],
height: 1, ),
color: TColor.gray.withOpacity(0.5), SizedBox(
)), height: media.width * 0.05,
], ),
), Visibility(
SizedBox( visible: _errorCreateUser,
height: media.width * 0.04, child: Text("Error - $_msgError",
), style: TextStyle(color: TColor.red))),
Row( SizedBox(
mainAxisAlignment: MainAxisAlignment.center, height: media.width * 0.4,
children: [ ),
GestureDetector( RoundButton(
onTap: () {}, title: "Créer un compte",
onPressed: () async {
if (!emailValidate ||
!passwordValidate ||
!usernameValidate) {
_printMsgError("Les champs renseigné ne sont pas valide");
return;
}
Tuple2<bool, String> result = await util.createUser(
controllerTextEmail.text,
controllerUsername.text,
controllerTextPassword.text);
if (result.item1) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
} else {
_printMsgError(result.item2);
}
}),
SizedBox(
height: media.width * 0.04,
),
Row(
// crossAxisAlignment: CrossAxisAlignment.,
children: [
Expanded(
child: Container( child: Container(
width: 50, height: 1,
height: 50, color: TColor.gray.withOpacity(0.5),
alignment: Alignment.center, )),
decoration: BoxDecoration( Text(
color: TColor.white, " Ou ",
border: Border.all( style: TextStyle(color: TColor.black, fontSize: 12),
width: 1, ),
color: TColor.gray.withOpacity(0.4), Expanded(
), child: Container(
borderRadius: BorderRadius.circular(15), height: 1,
), color: TColor.gray.withOpacity(0.5),
child: Image.asset( )),
"assets/img/google.png", ],
width: 20, ),
height: 20, SizedBox(
height: media.width * 0.04,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {},
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: TColor.white,
border: Border.all(
width: 1,
color: TColor.gray.withOpacity(0.4),
), ),
borderRadius: BorderRadius.circular(15),
),
child: Image.asset(
"assets/img/google.png",
width: 20,
height: 20,
), ),
), ),
SizedBox( ),
width: media.width * 0.04, SizedBox(
), width: media.width * 0.04,
GestureDetector( ),
onTap: () {}, GestureDetector(
child: Container( onTap: () {},
width: 50, child: Container(
height: 50, width: 50,
alignment: Alignment.center, height: 50,
decoration: BoxDecoration( alignment: Alignment.center,
color: TColor.white, decoration: BoxDecoration(
border: Border.all( color: TColor.white,
width: 1, border: Border.all(
color: TColor.gray.withOpacity(0.4), width: 1,
), color: TColor.gray.withOpacity(0.4),
borderRadius: BorderRadius.circular(15),
),
child: Image.asset(
"assets/img/suunto.png",
width: 35,
height: 35,
), ),
borderRadius: BorderRadius.circular(15),
), ),
) child: Image.asset(
], "assets/img/suunto.png",
), width: 35,
SizedBox( height: 35,
height: media.width * 0.04, ),
), ),
TextButton( )
onPressed: () { ],
Navigator.push( ),
context, SizedBox(
MaterialPageRoute( height: media.width * 0.04,
builder: (context) => const LoginView())); ),
}, TextButton(
child: Row( onPressed: () {
mainAxisSize: MainAxisSize.min, Navigator.push(
children: [ context,
Text( MaterialPageRoute(
"Vous avez déjà un compte ? ", builder: (context) => const LoginView()));
style: TextStyle( },
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Vous avez déjà un compte ? ",
style: TextStyle(
color: TColor.black,
fontSize: 14,
),
),
Text(
"Se connecter",
style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
), fontWeight: FontWeight.w700),
), )
Text( ],
"Se connecter",
style: TextStyle(
color: TColor.black,
fontSize: 14,
fontWeight: FontWeight.w700),
)
],
),
),
SizedBox(
height: media.width * 0.04,
), ),
], ),
), SizedBox(
height: media.width * 0.04,
),
],
), ),
), ),
), ),

@ -73,148 +73,144 @@ class _WebLoginView extends State<WebLoginView> {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: SingleChildScrollView( body: SafeArea(
child: SafeArea( child: Container(
child: Container( padding: const EdgeInsets.symmetric(horizontal: 300),
padding: const EdgeInsets.symmetric(horizontal: 300), height: media.height,
height: media.height, child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ SizedBox(
SizedBox( height: media.width * 0.03,
height: media.width * 0.03, ),
), Text(
Text( "Bienvenue sur SmartFit",
"Bienvenue", style: TextStyle(color: TColor.gray, fontSize: 16),
style: TextStyle(color: TColor.gray, fontSize: 16), ),
), Text(
Text( "Se connecter",
"Se connecter", style: TextStyle(
style: TextStyle( color: TColor.black,
color: TColor.black, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.w700),
fontWeight: FontWeight.w700), ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Email",
hitText: "Email", icon: "assets/img/email.svg",
icon: "assets/img/email.svg", keyboardType: TextInputType.emailAddress,
keyboardType: TextInputType.emailAddress, controller: controllerTextEmail,
controller: controllerTextEmail, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( controller: controllerTextPassword,
controller: controllerTextPassword, hitText: "Mot de passe",
hitText: "Mot de passe", icon: "assets/img/lock.svg",
icon: "assets/img/lock.svg", obscureText: _obscureText,
obscureText: _obscureText, rigtIcon: TextButton(
rigtIcon: TextButton( onPressed: _toggle,
onPressed: _toggle, child: Container(
child: Container( alignment: Alignment.center,
alignment: Alignment.center, width: 20,
height: 20,
child: SvgPicture.asset(
"assets/img/show_password.svg",
width: 20, width: 20,
height: 20, height: 20,
child: SvgPicture.asset( fit: BoxFit.contain,
"assets/img/show_password.svg", ))),
width: 20, ),
height: 20, SizedBox(
fit: BoxFit.contain, height: media.width * 0.01,
))), ),
), Row(
SizedBox( mainAxisAlignment: MainAxisAlignment.center,
height: media.width * 0.01, children: [
), Text(
Row( "Mot de passe oublié ?",
mainAxisAlignment: MainAxisAlignment.center, style: TextStyle(
children: [ color: TColor.gray,
Text( fontSize: 15,
"Mot de passe oublié ?", decoration: TextDecoration.underline),
style: TextStyle( ),
color: TColor.gray, ],
fontSize: 15, ),
decoration: TextDecoration.underline), SizedBox(
), height: media.width * 0.04,
], ),
), Visibility(
SizedBox( visible: _errorLogin,
height: media.width * 0.04, child: Text("Error - $_msgError",
), style: TextStyle(color: TColor.red))),
Visibility( const Spacer(),
visible: _errorLogin, RoundButton(
child: Text("Error - $_msgError", title: "Se connecter",
style: TextStyle(color: TColor.red))), onPressed: () async {
const Spacer(), if (!emailValidate || !passwordValidate) {
RoundButton( _printMsgError("Les champs renseigné ne sont pas valide");
title: "Se connecter", return;
onPressed: () async { }
if (!emailValidate || !passwordValidate) { Tuple2<bool, String> result =
_printMsgError( await util.checkLoginAndPassword(
"Les champs renseigné ne sont pas valide"); controllerTextEmail.text,
return; controllerTextPassword.text);
}
Tuple2<bool, String> result =
await util.checkLoginAndPassword(
controllerTextEmail.text,
controllerTextPassword.text);
if (result.item1 == true) { if (result.item1 == true) {
Tuple2 infoUser = await util.getUserInfo(result.item2); Tuple2 infoUser = await util.getUserInfo(result.item2);
if (infoUser.item1 == false) { if (infoUser.item1 == false) {
//print("Erreur - Impossible de récupéré les données de l'utilisateur"); //print("Erreur - Impossible de récupéré les données de l'utilisateur");
_printMsgError( _printMsgError(
"Impossible de récupéré les données de l'utilisateur - {$infoUser.item2}"); "Impossible de récupéré les données de l'utilisateur - {$infoUser.item2}");
} else {
util.fillUser(context, infoUser.item2, result.item2);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MainTabView()));
}
} else { } else {
_printMsgError("Connexion refuser - ${result.item2}"); util.fillUser(context, infoUser.item2, result.item2);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MainTabView()));
} }
}), } else {
SizedBox( _printMsgError("Connexion refuser - ${result.item2}");
height: media.width * 0.04, }
), }),
SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), SizedBox(
TextButton( height: media.width * 0.04,
onPressed: () { ),
Navigator.pop(context); TextButton(
}, onPressed: () {
child: Column( Navigator.pop(context);
mainAxisSize: MainAxisSize.min, },
children: [ child: Column(
Text( mainAxisSize: MainAxisSize.min,
"Vous n'avez pas toujours pas de compte ? ", children: [
style: TextStyle( Text(
"Vous n'avez pas toujours pas de compte ? ",
style: TextStyle(
color: TColor.black,
fontSize: 14,
),
),
Text(
"Créer un compte",
style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
), fontWeight: FontWeight.w700),
), )
Text( ],
"Créer un compte",
style: TextStyle(
color: TColor.black,
fontSize: 14,
fontWeight: FontWeight.w700),
)
],
),
),
SizedBox(
height: media.width * 0.04,
), ),
], ),
), SizedBox(
height: media.width * 0.04,
),
],
), ),
), ),
), ),

@ -90,159 +90,148 @@ class _WebSignUpView extends State<WebSignUpView> {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: SingleChildScrollView( body: SafeArea(
child: SafeArea( child: Padding(
child: Padding( padding: const EdgeInsets.symmetric(horizontal: 300),
padding: const EdgeInsets.symmetric(horizontal: 300), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), Text(
Text( "Bienvenue,",
"Bienvenue,", style: TextStyle(color: TColor.gray, fontSize: 16),
style: TextStyle(color: TColor.gray, fontSize: 16), ),
), Text(
Text( "Créer un compte",
"Créer un compte", style: TextStyle(
style: TextStyle( color: TColor.black,
color: TColor.black, fontSize: 20,
fontSize: 20, fontWeight: FontWeight.w700),
fontWeight: FontWeight.w700), ),
), SizedBox(
SizedBox( height: media.width * 0.05,
height: media.width * 0.05, ),
), RoundTextField(
RoundTextField( hitText: "Prénom",
hitText: "Prénom", icon: "assets/img/user_text.svg",
icon: "assets/img/user_text.svg", controller: controllerUsername,
controller: controllerUsername, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Email",
hitText: "Email", icon: "assets/img/email.svg",
icon: "assets/img/email.svg", keyboardType: TextInputType.emailAddress,
keyboardType: TextInputType.emailAddress, controller: controllerTextEmail,
controller: controllerTextEmail, ),
), SizedBox(
SizedBox( height: media.width * 0.04,
height: media.width * 0.04, ),
), RoundTextField(
RoundTextField( hitText: "Mot de passe",
hitText: "Mot de passe", icon: "assets/img/lock.svg",
icon: "assets/img/lock.svg", obscureText: _obscureText,
obscureText: _obscureText, controller: controllerTextPassword,
controller: controllerTextPassword, rigtIcon: TextButton(
rigtIcon: TextButton( onPressed: _toggle,
onPressed: _toggle, child: Container(
child: Container( alignment: Alignment.center,
alignment: Alignment.center, width: 20,
height: 20,
child: SvgPicture.asset(
"assets/img/show_password.svg",
width: 20, width: 20,
height: 20, height: 20,
child: SvgPicture.asset( fit: BoxFit.contain,
"assets/img/show_password.svg", ))),
width: 20, ),
height: 20, Row(
fit: BoxFit.contain, // crossAxisAlignment: CrossAxisAlignment.,
))), children: [
), IconButton(
Row( onPressed: () {
// crossAxisAlignment: CrossAxisAlignment., _check();
},
icon: Icon(
_isCheck
? Icons.check_box_outlined
: Icons.check_box_outline_blank_outlined,
color: TColor.gray,
size: 20,
),
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"En continuant, vous acceptez notre Politique de\nconfidentialité et nos Conditions d'utilisation.",
style: TextStyle(color: TColor.gray, fontSize: 10),
),
)
],
),
Visibility(
visible: _errorCreateUser,
child: Text("Error - $_msgError",
style: TextStyle(color: TColor.red))),
SizedBox(
height: media.width * 0.05,
),
RoundButton(
title: "Créer un compte",
onPressed: () async {
if (!emailValidate ||
!passwordValidate ||
!usernameValidate) {
_printMsgError("Les champs renseigné ne sont pas valide");
return;
}
Tuple2<bool, String> result = await util.createUser(
controllerTextEmail.text,
controllerUsername.text,
controllerTextPassword.text);
if (result.item1) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
} else {
_printMsgError(result.item2);
}
}),
SizedBox(
height: media.width * 0.04,
),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [ children: [
IconButton( Text(
onPressed: () { "Vous avez déjà un compte ? ",
_check(); style: TextStyle(
}, color: TColor.black,
icon: Icon( fontSize: 14,
_isCheck
? Icons.check_box_outlined
: Icons.check_box_outline_blank_outlined,
color: TColor.gray,
size: 20,
), ),
), ),
Padding( Text(
padding: const EdgeInsets.only(top: 8), "Se connecter",
child: Text( style: TextStyle(
"En continuant, vous acceptez notre Politique de\nconfidentialité et nos Conditions d'utilisation.",
style: TextStyle(color: TColor.gray, fontSize: 10),
),
)
],
),
Visibility(
visible: _errorCreateUser,
child: Text("Error - $_msgError",
style: TextStyle(color: TColor.red))),
SizedBox(
height: media.width * 0.05,
),
RoundButton(
title: "Créer un compte",
onPressed: () async {
if (!emailValidate ||
!passwordValidate ||
!usernameValidate) {
_printMsgError(
"Les champs renseigné ne sont pas valide");
return;
}
Tuple2<bool, String> result = await util.createUser(
controllerTextEmail.text,
controllerUsername.text,
controllerTextPassword.text);
if (result.item1) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
} else {
_printMsgError(result.item2);
}
}),
SizedBox(
height: media.width * 0.04,
),
SizedBox(
height: media.width * 0.04,
),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginView()));
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Vous avez déjà un compte ? ",
style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
), fontWeight: FontWeight.w700),
), )
Text( ],
"Se connecter",
style: TextStyle(
color: TColor.black,
fontSize: 14,
fontWeight: FontWeight.w700),
)
],
),
),
SizedBox(
height: media.width * 0.04,
), ),
], ),
), ],
), ),
), ),
), ),

@ -1,10 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:responsive_builder/responsive_builder.dart'; import 'package:responsive_builder/responsive_builder.dart';
import 'package:smartfit_app_mobile/view/profile/mobile/mobile_change_email.dart'; import 'package:smartfit_app_mobile/view/profile/mobile/mobile_change_email.dart';
import 'package:smartfit_app_mobile/view/profile/mobile/mobile_change_username.dart';
import 'package:smartfit_app_mobile/view/profile/web/web_change_email.dart'; import 'package:smartfit_app_mobile/view/profile/web/web_change_email.dart';
import 'package:smartfit_app_mobile/view/profile/web/web_change_username.dart';
class ChangeEmailView extends StatefulWidget { class ChangeEmailView extends StatefulWidget {
const ChangeEmailView({super.key}); const ChangeEmailView({super.key});
@ -14,7 +11,7 @@ class ChangeEmailView extends StatefulWidget {
} }
class _ChangeEmailViewState extends State<ChangeEmailView> { class _ChangeEmailViewState extends State<ChangeEmailView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ScreenTypeLayout.builder( return ScreenTypeLayout.builder(
mobile: (_) => const MobileChangeEmailView(), mobile: (_) => const MobileChangeEmailView(),

@ -1,9 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class MobileChangeEmailView extends StatefulWidget { class MobileChangeEmailView extends StatefulWidget {
const MobileChangeEmailView({super.key}); const MobileChangeEmailView({super.key});
@ -14,12 +16,13 @@ class MobileChangeEmailView extends StatefulWidget {
class _MobileChangeEmailViewState extends State<MobileChangeEmailView> { class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextEmail = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final InfoMessage infoManager = InfoMessage();
String oldUsername = "Ancien e-mail"; final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userEmail = context.watch<User>().email;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +47,14 @@ class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son e-mail", "Changer son e-mail",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -75,7 +76,7 @@ class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
), ),
), ),
Text( Text(
oldUsername, // Utilisez votre ancien pseudo ici userEmail,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,7 +92,6 @@ class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau e-mail", hitText: "Nouveau e-mail",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
@ -99,9 +99,28 @@ class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
controller: controllerTextEmail, controller: controllerTextEmail,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(
height: media.width * 0.01,
),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await api.modifyUserInfo(
'email',
controllerTextEmail.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false).email =
controllerTextEmail.text;
}
setState(() {});
}),
], ],
), ),
), ),
@ -112,4 +131,4 @@ class _MobileChangeEmailViewState extends State<MobileChangeEmailView> {
), ),
); );
} }
} }

@ -1,25 +1,34 @@
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
import 'package:tuple/tuple.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
class MobileChangePasswordView extends StatefulWidget { class MobileChangePasswordView extends StatefulWidget {
const MobileChangePasswordView({super.key}); const MobileChangePasswordView({super.key});
@override @override
State<MobileChangePasswordView> createState() => _MobileChangePasswordViewState(); State<MobileChangePasswordView> createState() =>
_MobileChangePasswordViewState();
} }
class _MobileChangePasswordViewState extends State<MobileChangePasswordView> { class _MobileChangePasswordViewState extends State<MobileChangePasswordView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerActualPasswd = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final TextEditingController controllerNewPasswd = TextEditingController();
final TextEditingController controllerNewPasswd2 = TextEditingController();
final InfoMessage infoManager = InfoMessage();
final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
User providerUser = Provider.of<User>(context, listen: false);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +53,14 @@ class _MobileChangePasswordViewState extends State<MobileChangePasswordView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son Mot de passe", "Changer son Mot de passe",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -77,29 +84,49 @@ class _MobileChangePasswordViewState extends State<MobileChangePasswordView> {
obscureText: true, obscureText: true,
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerActualPasswd,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
RoundTextField( RoundTextField(
controller: controllerTextPassword, controller: controllerNewPasswd,
hitText: "Nouveau mot de passe", hitText: "Nouveau mot de passe",
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
obscureText: true, obscureText: true,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
RoundTextField( RoundTextField(
controller: controllerTextPassword, controller: controllerNewPasswd2,
hitText: "Confirmer nouveau mot de passe", hitText: "Confirmer nouveau mot de passe",
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
obscureText: true, obscureText: true,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
Tuple2<bool, String> res = await api.login(
controllerActualPasswd.text,
providerUser.email,
infoManager);
if (res.item1) {
if (controllerNewPasswd.text ==
controllerNewPasswd2.text) {
await api.modifyUserInfo(
'password',
sha256
.convert(utf8
.encode(controllerNewPasswd.text))
.toString(),
providerUser.token,
infoManager);
} else {
infoManager.displayMessage(
'Passwords does not match each other! Enter them carefully.',
true);
}
}
setState(() {});
}),
], ],
), ),
), ),
@ -110,4 +137,4 @@ class _MobileChangePasswordViewState extends State<MobileChangePasswordView> {
), ),
); );
} }
} }

@ -1,25 +1,29 @@
import 'package:provider/provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class MobileChangeUsernameView extends StatefulWidget { class MobileChangeUsernameView extends StatefulWidget {
const MobileChangeUsernameView({super.key}); const MobileChangeUsernameView({super.key});
@override @override
State<MobileChangeUsernameView> createState() => _MobileChangeUsernameViewState(); State<MobileChangeUsernameView> createState() =>
_MobileChangeUsernameViewState();
} }
class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> { class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextUsername = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final InfoMessage infoManager = InfoMessage();
String oldUsername = "Ancien pseudo"; final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userUsername = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +48,14 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son pseudo", "Changer son pseudo",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -75,7 +77,7 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
), ),
), ),
Text( Text(
oldUsername, // Utilisez votre ancien pseudo ici userUsername, // Utilisez votre ancien pseudo ici
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,17 +93,33 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau pseudo", hitText: "Nouveau pseudo",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerTextUsername,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.02),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await api.modifyUserInfo(
'username',
controllerTextUsername.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false)
.username = controllerTextUsername.text;
}
setState(() {});
}),
], ],
), ),
), ),
@ -112,4 +130,4 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
), ),
); );
} }
} }

@ -1,5 +1,7 @@
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:animated_toggle_switch/animated_toggle_switch.dart'; import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/setting_row.dart'; import 'package:smartfit_app_mobile/common_widget/setting_row.dart';
@ -48,6 +50,8 @@ class _MobileProfileView extends State<MobileProfileView> {
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String username = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: TColor.white, backgroundColor: TColor.white,
@ -106,7 +110,7 @@ class _MobileProfileView extends State<MobileProfileView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
"Benjelloun Othmane", username,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
@ -214,21 +218,23 @@ class _MobileProfileView extends State<MobileProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeUsernameView(), builder: (context) =>
const ChangeUsernameView(),
), ),
); );
} else if (iObj["tag"] == "2") { } else if (iObj["tag"] == "2") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangePasswordView(), builder: (context) =>
const ChangePasswordView(),
), ),
); );
} else { } else {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeEmailView(), builder: (context) => const ChangeEmailView(),
), ),
); );
} }
@ -388,14 +394,15 @@ class _MobileProfileView extends State<MobileProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => PrivacyPolicyView(), builder: (context) =>
const PrivacyPolicyView(),
), ),
); );
} else if (iObj["tag"] == "5") { } else if (iObj["tag"] == "5") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ContactUsView(), builder: (context) => const ContactUsView(),
), ),
); );
} else { } else {

@ -1,9 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class WebChangeEmailView extends StatefulWidget { class WebChangeEmailView extends StatefulWidget {
const WebChangeEmailView({super.key}); const WebChangeEmailView({super.key});
@ -14,12 +16,13 @@ class WebChangeEmailView extends StatefulWidget {
class _WebChangeEmailViewState extends State<WebChangeEmailView> { class _WebChangeEmailViewState extends State<WebChangeEmailView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextEmail = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final ApiWrapper apiWrapper = ApiWrapper();
String oldUsername = "Ancien e-mail"; final InfoMessage infoManager = InfoMessage();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userEmail = context.watch<User>().email;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +47,14 @@ class _WebChangeEmailViewState extends State<WebChangeEmailView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son e-mail", "Changer son email",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -67,7 +68,7 @@ class _WebChangeEmailViewState extends State<WebChangeEmailView> {
Row( Row(
children: [ children: [
Text( Text(
"Ancien e-mail : ", "Email actuel : ",
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -75,7 +76,7 @@ class _WebChangeEmailViewState extends State<WebChangeEmailView> {
), ),
), ),
Text( Text(
oldUsername, userEmail,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,17 +92,33 @@ class _WebChangeEmailViewState extends State<WebChangeEmailView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau email", hitText: "Nouveau email",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerTextEmail,
), ),
SizedBox(height: media.width * 0.04), SizedBox(height: media.width * 0.01),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.03),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await apiWrapper.modifyUserInfo(
'email',
controllerTextEmail.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false).email =
controllerTextEmail.text;
}
setState(() {});
}),
], ],
), ),
), ),
@ -112,4 +129,4 @@ class _WebChangeEmailViewState extends State<WebChangeEmailView> {
), ),
); );
} }
} }

@ -1,9 +1,14 @@
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:tuple/tuple.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
class WebChangePasswordView extends StatefulWidget { class WebChangePasswordView extends StatefulWidget {
const WebChangePasswordView({super.key}); const WebChangePasswordView({super.key});
@ -13,13 +18,16 @@ class WebChangePasswordView extends StatefulWidget {
} }
class _WebChangePasswordViewState extends State<WebChangePasswordView> { class _WebChangePasswordViewState extends State<WebChangePasswordView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerActualPasswd = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final TextEditingController controllerNewPasswd = TextEditingController();
final TextEditingController controllerNewPasswd2 = TextEditingController();
final InfoMessage infoManager = InfoMessage();
final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
User providerUser = Provider.of<User>(context, listen: false);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +52,14 @@ class _WebChangePasswordViewState extends State<WebChangePasswordView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son Mot de passe", "Changer son Mot de passe",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -76,29 +82,54 @@ class _WebChangePasswordViewState extends State<WebChangePasswordView> {
obscureText: true, obscureText: true,
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerActualPasswd,
), ),
SizedBox(height: media.width * 0.02), SizedBox(height: media.width * 0.02),
RoundTextField( RoundTextField(
controller: controllerTextPassword, controller: controllerNewPasswd,
hitText: "Nouveau mot de passe", hitText: "Nouveau mot de passe",
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
obscureText: true, obscureText: true,
), ),
SizedBox(height: media.width * 0.02), SizedBox(height: media.width * 0.02),
RoundTextField( RoundTextField(
controller: controllerTextPassword, controller: controllerNewPasswd2,
hitText: "Confirmer nouveau mot de passe", hitText: "Confirmer nouveau mot de passe",
icon: "assets/img/lock.svg", icon: "assets/img/lock.svg",
obscureText: true, obscureText: true,
), ),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.04), SizedBox(height: media.width * 0.04),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
Tuple2<bool, String> res = await api.login(
controllerActualPasswd.text,
providerUser.email,
infoManager);
if (res.item1) {
if (controllerNewPasswd.text ==
controllerNewPasswd2.text) {
await api.modifyUserInfo(
'password',
sha256
.convert(utf8
.encode(controllerNewPasswd.text))
.toString(),
providerUser.token,
infoManager);
} else {
infoManager.displayMessage(
'Passwords does not match each other! Enter them carefully.',
true);
}
}
setState(() {});
}),
], ],
), ),
), ),
@ -109,4 +140,4 @@ class _WebChangePasswordViewState extends State<WebChangePasswordView> {
), ),
); );
} }
} }

@ -1,9 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class WebChangeUsernameView extends StatefulWidget { class WebChangeUsernameView extends StatefulWidget {
const WebChangeUsernameView({super.key}); const WebChangeUsernameView({super.key});
@ -13,13 +15,14 @@ class WebChangeUsernameView extends StatefulWidget {
} }
class _WebChangeUsernameViewState extends State<WebChangeUsernameView> { class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextUsername = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final InfoMessage infoManager = InfoMessage();
String oldUsername = "Ancien pseudo"; final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userUsername = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,16 +47,14 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son pseudo", "Changer son pseudo",
style: TextStyle( style: TextStyle(
color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700),
), ),
), ),
backgroundColor: TColor.white, backgroundColor: TColor.white,
body: Column( body: Column(
children: [ children: [
@ -75,7 +76,7 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
), ),
), ),
Text( Text(
oldUsername, // Utilisez votre ancien pseudo ici userUsername,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,17 +92,35 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau pseudo", hitText: "Nouveau pseudo",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerTextUsername,
), ),
SizedBox(
height: media.width * 0.01,
),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.04), SizedBox(height: media.width * 0.04),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await api.modifyUserInfo(
'username',
controllerTextUsername.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false)
.username = controllerTextUsername.text;
}
setState(() {});
}),
], ],
), ),
), ),
@ -112,4 +131,4 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
), ),
); );
} }
} }

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:animated_toggle_switch/animated_toggle_switch.dart'; import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/setting_row.dart'; import 'package:smartfit_app_mobile/common_widget/setting_row.dart';
@ -48,6 +50,8 @@ class _WebProfileView extends State<WebProfileView> {
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String username = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: TColor.white, backgroundColor: TColor.white,
@ -106,7 +110,7 @@ class _WebProfileView extends State<WebProfileView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
"Benjelloun Othmane", username,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
@ -214,21 +218,23 @@ class _WebProfileView extends State<WebProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeUsernameView(), builder: (context) =>
const ChangeUsernameView(),
), ),
); );
} else if (iObj["tag"] == "2") { } else if (iObj["tag"] == "2") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangePasswordView(), builder: (context) =>
const ChangePasswordView(),
), ),
); );
} else { } else {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeEmailView(), builder: (context) => const ChangeEmailView(),
), ),
); );
} }
@ -277,7 +283,7 @@ class _WebProfileView extends State<WebProfileView> {
), ),
Expanded( Expanded(
child: Text( child: Text(
"Pop-up Notification", "Push Notifications",
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 12, fontSize: 12,
@ -286,9 +292,9 @@ class _WebProfileView extends State<WebProfileView> {
), ),
CustomAnimatedToggleSwitch<bool>( CustomAnimatedToggleSwitch<bool>(
current: positive, current: positive,
values: [false, true], values: const [false, true],
spacing: 0.0, spacing: 0.0,
indicatorSize: Size.square(25.0), indicatorSize: const Size.square(25.0),
animationDuration: animationDuration:
const Duration(milliseconds: 200), const Duration(milliseconds: 200),
animationCurve: Curves.linear, animationCurve: Curves.linear,
@ -296,7 +302,7 @@ class _WebProfileView extends State<WebProfileView> {
iconBuilder: (context, local, global) { iconBuilder: (context, local, global) {
return const SizedBox(); return const SizedBox();
}, },
cursors: ToggleCursors( cursors: const ToggleCursors(
defaultCursor: SystemMouseCursors.click), defaultCursor: SystemMouseCursors.click),
onTap: (_) => onTap: (_) =>
setState(() => positive = !positive), setState(() => positive = !positive),
@ -388,14 +394,15 @@ class _WebProfileView extends State<WebProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const PrivacyPolicyView(), builder: (context) =>
const PrivacyPolicyView(),
), ),
); );
} else if (iObj["tag"] == "5") { } else if (iObj["tag"] == "5") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ContactUsView(), builder: (context) => const ContactUsView(),
), ),
); );
} else { } else {

@ -35,6 +35,7 @@ dependencies:
file_picker: ^6.1.1 file_picker: ^6.1.1
csv: ^5.1.1 csv: ^5.1.1
fit_tool: ^1.0.5 fit_tool: ^1.0.5
email_validator: '^2.1.16'
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.

Loading…
Cancel
Save