Mudanças em criar conta
This commit is contained in:
@@ -19,6 +19,8 @@ class AuthService {
|
||||
static Future<UserCredential?> signUpWithEmailAndPassword({
|
||||
required String email,
|
||||
required String password,
|
||||
String? displayName,
|
||||
String? role,
|
||||
}) async {
|
||||
try {
|
||||
print('DEBUG: Tentando criar conta para email: $email');
|
||||
@@ -33,6 +35,18 @@ class AuthService {
|
||||
print('DEBUG: User ID: ${result.user?.uid}');
|
||||
print('DEBUG: Email verified: ${result.user?.emailVerified}');
|
||||
|
||||
// Update user profile with display name
|
||||
if (displayName != null && displayName.isNotEmpty) {
|
||||
await result.user?.updateDisplayName(displayName);
|
||||
print('DEBUG: Display name atualizado para: $displayName');
|
||||
}
|
||||
|
||||
// Store user role in custom claims or Firestore (simplified for now)
|
||||
if (role != null) {
|
||||
print('DEBUG: Papel do usuário: $role');
|
||||
// TODO: Store role in Firestore for future use
|
||||
}
|
||||
|
||||
// Verificar se o email foi verificado
|
||||
if (result.user != null && !result.user!.emailVerified) {
|
||||
print('DEBUG: Email não verificado, tentando enviar verificação...');
|
||||
@@ -73,6 +87,12 @@ class AuthService {
|
||||
print('DEBUG: Login realizado com sucesso para: ${result.user?.email}');
|
||||
print('DEBUG: User ID: ${result.user?.uid}');
|
||||
print('DEBUG: Email verified: ${result.user?.emailVerified}');
|
||||
print('DEBUG: Display name: ${result.user?.displayName}');
|
||||
|
||||
// Reload user data to ensure we have the latest information
|
||||
await result.user?.reload();
|
||||
print('DEBUG: User data reloaded');
|
||||
print('DEBUG: Display name after reload: ${result.user?.displayName}');
|
||||
|
||||
return result;
|
||||
} on FirebaseAuthException catch (e) {
|
||||
|
||||
@@ -14,13 +14,16 @@ class SignupPage extends StatefulWidget {
|
||||
|
||||
class _SignupPageState extends State<SignupPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _nameController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _isLoading = false;
|
||||
bool _obscurePassword = true;
|
||||
String _selectedRole = 'student'; // 'student' or 'teacher'
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
@@ -34,16 +37,20 @@ class _SignupPageState extends State<SignupPage> {
|
||||
});
|
||||
|
||||
try {
|
||||
// Get email and password from controllers
|
||||
// Get name, email and password from controllers
|
||||
final name = _nameController.text.trim();
|
||||
final email = _emailController.text.trim();
|
||||
final password = _passwordController.text.trim();
|
||||
|
||||
print('DEBUG: Iniciando processo de signup para: $email');
|
||||
print('DEBUG: Nome: $name, Papel: $_selectedRole');
|
||||
|
||||
// Attempt signup with Firebase
|
||||
await AuthService.signUpWithEmailAndPassword(
|
||||
email: email,
|
||||
password: password,
|
||||
displayName: name,
|
||||
role: _selectedRole,
|
||||
);
|
||||
|
||||
print('DEBUG: Signup Firebase bem-sucedido, navegando para dashboard');
|
||||
@@ -59,8 +66,12 @@ class _SignupPageState extends State<SignupPage> {
|
||||
message: 'Conta criada com sucesso!',
|
||||
);
|
||||
|
||||
// Navigate to student dashboard after successful signup
|
||||
context.go('/student-dashboard');
|
||||
// Navigate to appropriate dashboard based on role
|
||||
if (_selectedRole == 'teacher') {
|
||||
context.go('/teacher-dashboard');
|
||||
} else {
|
||||
context.go('/student-dashboard');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('DEBUG: Erro no signup: $e');
|
||||
@@ -181,6 +192,51 @@ class _SignupPageState extends State<SignupPage> {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Name field
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
keyboardType: TextInputType.name,
|
||||
style: const TextStyle(color: Color(0xFF2D3748)),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Nome Completo',
|
||||
labelStyle: const TextStyle(
|
||||
color: Color(0xFF2D3748),
|
||||
),
|
||||
hintStyle: const TextStyle(
|
||||
color: Color(0xFF718096),
|
||||
),
|
||||
prefixIcon: const Icon(
|
||||
Icons.person,
|
||||
color: Color(0xFF82C9BD),
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: const BorderSide(
|
||||
color: Color(0xFFE2E8F0),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: const BorderSide(
|
||||
color: Color(0xFF82C9BD),
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF8F9FA),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Nome é obrigatório';
|
||||
}
|
||||
if (value.length < 2) {
|
||||
return 'Nome muito curto';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Email field
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
@@ -282,6 +338,61 @@ class _SignupPageState extends State<SignupPage> {
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Role selection
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Eu sou:',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF2D3748),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: RadioListTile<String>(
|
||||
title: const Text(
|
||||
'Aluno',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
value: 'student',
|
||||
groupValue: _selectedRole,
|
||||
onChanged: (String? value) {
|
||||
setState(() {
|
||||
_selectedRole = value!;
|
||||
});
|
||||
},
|
||||
activeColor: const Color(0xFF82C9BD),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RadioListTile<String>(
|
||||
title: const Text(
|
||||
'Professor',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
value: 'teacher',
|
||||
groupValue: _selectedRole,
|
||||
onChanged: (String? value) {
|
||||
setState(() {
|
||||
_selectedRole = value!;
|
||||
});
|
||||
},
|
||||
activeColor: const Color(0xFF82C9BD),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Signup button
|
||||
|
||||
@@ -21,12 +21,53 @@ class _StudentDashboardPageState extends State<StudentDashboardPage> {
|
||||
_loadUserData();
|
||||
}
|
||||
|
||||
void _loadUserData() {
|
||||
final user = AuthService.currentUser;
|
||||
if (user != null) {
|
||||
setState(() {
|
||||
_userName = user.displayName ?? 'Estudante';
|
||||
});
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
// Reload user data when dependencies change (e.g., after navigation)
|
||||
_loadUserData();
|
||||
}
|
||||
|
||||
Future<void> _loadUserData() async {
|
||||
try {
|
||||
final user = AuthService.currentUser;
|
||||
if (user != null) {
|
||||
print('DEBUG: Loading user data for dashboard');
|
||||
print('DEBUG: User email: ${user.email}');
|
||||
print('DEBUG: User displayName before reload: ${user.displayName}');
|
||||
|
||||
// Reload user data to get latest information from Firebase
|
||||
await user.reload();
|
||||
|
||||
// Get the updated user
|
||||
final updatedUser = AuthService.currentUser;
|
||||
if (updatedUser != null) {
|
||||
print(
|
||||
'DEBUG: User displayName after reload: ${updatedUser.displayName}',
|
||||
);
|
||||
|
||||
// Use displayName if available, otherwise use email part before @
|
||||
String displayName = updatedUser.displayName ?? '';
|
||||
print('DEBUG: Initial displayName value: "$displayName"');
|
||||
|
||||
if (displayName.isEmpty && updatedUser.email != null) {
|
||||
// Extract name from email (e.g., "fabioceia0223@gmail.com" -> "fabioceia0223")
|
||||
displayName = updatedUser.email!.split('@')[0];
|
||||
print('DEBUG: Extracted name from email: "$displayName"');
|
||||
}
|
||||
if (displayName.isEmpty) {
|
||||
displayName = 'Estudante';
|
||||
print('DEBUG: Using fallback "Estudante"');
|
||||
}
|
||||
|
||||
print('DEBUG: Final displayName to use: "$displayName"');
|
||||
setState(() {
|
||||
_userName = displayName;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('DEBUG: Error loading user data: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,18 @@ class _SplashPageState extends State<SplashPage> {
|
||||
|
||||
if (currentUser != null) {
|
||||
print('DEBUG: User already authenticated: ${currentUser.email}');
|
||||
print(
|
||||
'DEBUG: User displayName before reload: ${currentUser.displayName}',
|
||||
);
|
||||
|
||||
// Reload user data to get latest information from Firebase
|
||||
await currentUser.reload();
|
||||
|
||||
// Get the updated user
|
||||
final updatedUser = AuthService.currentUser;
|
||||
print(
|
||||
'DEBUG: User displayName after reload: ${updatedUser?.displayName}',
|
||||
);
|
||||
|
||||
// Update session with current user if needed
|
||||
await SessionService.updateSessionWithCurrentUser();
|
||||
|
||||
Reference in New Issue
Block a user