Nueva contraseña
This commit is contained in:
+3
-1
@@ -6,6 +6,7 @@ import 'package:prosappco/src/screens/login.dart';
|
|||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:prosappco/src/screens/login_email.dart';
|
import 'package:prosappco/src/screens/login_email.dart';
|
||||||
import 'package:prosappco/src/screens/new_number.dart';
|
import 'package:prosappco/src/screens/new_number.dart';
|
||||||
|
import 'package:prosappco/src/screens/new_password.dart';
|
||||||
import 'package:prosappco/src/screens/profession.dart';
|
import 'package:prosappco/src/screens/profession.dart';
|
||||||
import 'package:prosappco/src/screens/professional_profile.dart';
|
import 'package:prosappco/src/screens/professional_profile.dart';
|
||||||
import 'package:prosappco/src/screens/professional_revision.dart';
|
import 'package:prosappco/src/screens/professional_revision.dart';
|
||||||
@@ -44,7 +45,8 @@ class MyApp extends StatelessWidget {
|
|||||||
'/newNumber': (context) => NewNumberScreen(),
|
'/newNumber': (context) => NewNumberScreen(),
|
||||||
'/profesionalRevision': (context) => ProfessionalRevisionScreen(),
|
'/profesionalRevision': (context) => ProfessionalRevisionScreen(),
|
||||||
'/profesionalProfile': (context) => ProfessionalProfileScreen(),
|
'/profesionalProfile': (context) => ProfessionalProfileScreen(),
|
||||||
'/solicitudEnviada': (context) => RequestSentScreen()
|
'/solicitudEnviada': (context) => RequestSentScreen(),
|
||||||
|
'/nuevaPassword': (context) => NewPasswordScreen()
|
||||||
},
|
},
|
||||||
onGenerateRoute: (settings) {
|
onGenerateRoute: (settings) {
|
||||||
throw Exception('Ruta desconocida: ${settings.name}');
|
throw Exception('Ruta desconocida: ${settings.name}');
|
||||||
|
|||||||
@@ -202,8 +202,8 @@ class _LoginEmailScreenState extends State<LoginEmailScreen> {
|
|||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_obscureText
|
_obscureText
|
||||||
? Icons.visibility_off
|
? Icons.visibility
|
||||||
: Icons.visibility,
|
: Icons.visibility_off,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:prosappco/src/components/primary_btn.dart';
|
||||||
|
|
||||||
|
class NewPasswordScreen extends StatefulWidget {
|
||||||
|
NewPasswordScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<NewPasswordScreen> createState() => _NewPasswordScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewPasswordScreenState extends State<NewPasswordScreen> {
|
||||||
|
final _currentPasswordController = TextEditingController();
|
||||||
|
final _newPasswordController = TextEditingController();
|
||||||
|
bool _obscureText = true;
|
||||||
|
bool _obscureText2 = true;
|
||||||
|
|
||||||
|
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||||
|
|
||||||
|
Future<void> updatePassword(
|
||||||
|
String currentPassword, String newPassword) async {
|
||||||
|
final User user = _auth.currentUser!;
|
||||||
|
|
||||||
|
final credential = EmailAuthProvider.credential(
|
||||||
|
email: user.email!,
|
||||||
|
password: currentPassword,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (newPassword == currentPassword) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Misma contraseña',
|
||||||
|
'La nueva contraseña debe ser diferente a la contraseña actual.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (newPassword.isEmpty) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Ingrese una contraseña valida',
|
||||||
|
'La nueva contraseña no puede estar vacia.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
await user.reauthenticateWithCredential(credential);
|
||||||
|
try {
|
||||||
|
await user.updatePassword(newPassword);
|
||||||
|
// Muestra un mensaje de éxito
|
||||||
|
Get.snackbar(
|
||||||
|
'Contraseña actualizada',
|
||||||
|
'La contraseña ha sido actualizada correctamente.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print("Error al verificar la contraseña actual: $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Contraseña incorrecta',
|
||||||
|
'Error al actualizar la contraseña asegurese de ingresar bien la contraseña actual.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
iconTheme: const IconThemeData(
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'Cambie su contraseña',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 300,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 100),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _currentPasswordController,
|
||||||
|
obscureText: _obscureText,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.lock_outline),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureText
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureText = !_obscureText;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
hintText: 'Contraseña (Actual)'),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 40.0),
|
||||||
|
TextFormField(
|
||||||
|
controller: _newPasswordController,
|
||||||
|
obscureText: _obscureText2,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.lock_outline),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureText2
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureText2 = !_obscureText2;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
hintText: 'Contraseña (Nueva)'),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 80.0),
|
||||||
|
PrimaryButtom(
|
||||||
|
onPressed: () {
|
||||||
|
updatePassword(_currentPasswordController.text.trim(),
|
||||||
|
_newPasswordController.text.trim());
|
||||||
|
},
|
||||||
|
label: 'Actualizar contraseña'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -404,6 +404,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
20.0), // Agrega espacio vertical entre los TextFormFields
|
20.0), // Agrega espacio vertical entre los TextFormFields
|
||||||
_email != null
|
_email != null
|
||||||
? TextFormField(
|
? TextFormField(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context, '/nuevaPassword');
|
||||||
|
},
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
@@ -427,8 +431,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_obscureText
|
_obscureText
|
||||||
? Icons.visibility_off
|
? Icons.visibility
|
||||||
: Icons.visibility,
|
: Icons.visibility_off,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
@@ -207,8 +207,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_obscureText
|
_obscureText
|
||||||
? Icons.visibility_off
|
? Icons.visibility
|
||||||
: Icons.visibility,
|
: Icons.visibility_off,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
Reference in New Issue
Block a user