validação entre professor e aluno, criação de placeholder para a tela de professores e mudanças na firebase
This commit is contained in:
@@ -7,7 +7,9 @@ import '../../../../core/services/session_service.dart';
|
||||
import '../../../../shared/presentation/widgets/custom_notification.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
final String? selectedRole;
|
||||
|
||||
const LoginPage({super.key, this.selectedRole});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
@@ -62,12 +64,41 @@ class _LoginPageState extends State<LoginPage> {
|
||||
print('DEBUG: Iniciando processo de login para: $email');
|
||||
|
||||
// Attempt login with Firebase
|
||||
await AuthService.signInWithEmailAndPassword(
|
||||
final result = await AuthService.signInWithEmailAndPassword(
|
||||
email: email,
|
||||
password: password,
|
||||
);
|
||||
|
||||
print('DEBUG: Login Firebase bem-sucedido, salvando sessão');
|
||||
print('DEBUG: Login Firebase bem-sucedido');
|
||||
print('DEBUG: Role selecionado na tela anterior: ${widget.selectedRole}');
|
||||
|
||||
// Ler role na Firestore
|
||||
final uid = result?.user?.uid;
|
||||
if (uid == null) throw Exception('Erro ao obter UID');
|
||||
|
||||
final actualRole = await AuthService.getUserRole(uid);
|
||||
print('DEBUG: Role real do usuário na Firestore: $actualRole');
|
||||
|
||||
// Validar se o role selecionado corresponde ao role real
|
||||
final selectedRole = widget.selectedRole;
|
||||
if (selectedRole != null && actualRole != null && selectedRole != actualRole) {
|
||||
// Role não corresponde - mostrar erro
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
|
||||
String errorMessage;
|
||||
if (selectedRole == 'teacher' && actualRole == 'student') {
|
||||
errorMessage = 'Este email está registado como Aluno. Não pode aceder à área de Professores.';
|
||||
} else if (selectedRole == 'student' && actualRole == 'teacher') {
|
||||
errorMessage = 'Este email está registado como Professor. Não pode aceder à área de Alunos.';
|
||||
} else {
|
||||
errorMessage = 'O tipo de utilizador selecionado não corresponde ao perfil registado.';
|
||||
}
|
||||
|
||||
_showRoleErrorDialog('Acesso Negado', errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save session based on remember me preference
|
||||
await SessionService.saveSession(
|
||||
@@ -76,9 +107,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||
displayName: AuthService.currentUser?.displayName,
|
||||
);
|
||||
|
||||
print('DEBUG: Sessão salva, navegando para dashboard');
|
||||
|
||||
// Navigate to student dashboard after successful login
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -90,7 +118,12 @@ class _LoginPageState extends State<LoginPage> {
|
||||
message: 'Login realizado com sucesso!',
|
||||
);
|
||||
|
||||
context.go('/student-dashboard');
|
||||
// Redirecionar baseado no role real
|
||||
if (actualRole == 'teacher') {
|
||||
context.go('/teacher-dashboard');
|
||||
} else {
|
||||
context.go('/student-dashboard');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('DEBUG: Erro no login: $e');
|
||||
@@ -110,6 +143,41 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _showRoleErrorDialog(String title, String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF2D3748),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
message,
|
||||
style: const TextStyle(color: Color(0xFF2D3748)),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
// Fazer logout para limpar a sessão
|
||||
AuthService.signOut();
|
||||
},
|
||||
child: const Text(
|
||||
'Voltar',
|
||||
style: TextStyle(color: Color(0xFF82C9BD)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
||||
@@ -278,6 +278,28 @@ class _RoleSelectionPageState extends State<RoleSelectionPage> {
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// Login link
|
||||
GestureDetector(
|
||||
onTap: _selectedRole != null ? _handleGoToLogin : null,
|
||||
child: Text(
|
||||
'Já tenho conta',
|
||||
style: TextStyle(
|
||||
color: _selectedRole != null
|
||||
? AppColors.primaryBlue
|
||||
: Colors.grey,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
)
|
||||
.animate()
|
||||
.fadeIn(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
delay: const Duration(milliseconds: 1400),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -288,6 +310,12 @@ class _RoleSelectionPageState extends State<RoleSelectionPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleGoToLogin() {
|
||||
if (_selectedRole != null) {
|
||||
context.go('/login?role=$_selectedRole');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildRoleCard(
|
||||
BuildContext context,
|
||||
String title,
|
||||
|
||||
@@ -6,7 +6,9 @@ import '../../../../core/services/auth_service.dart';
|
||||
import '../../../../shared/presentation/widgets/custom_notification.dart';
|
||||
|
||||
class SignupPage extends StatefulWidget {
|
||||
const SignupPage({super.key});
|
||||
final String? selectedRole;
|
||||
|
||||
const SignupPage({super.key, this.selectedRole});
|
||||
|
||||
@override
|
||||
State<SignupPage> createState() => _SignupPageState();
|
||||
@@ -19,7 +21,14 @@ class _SignupPageState extends State<SignupPage> {
|
||||
final _passwordController = TextEditingController();
|
||||
bool _isLoading = false;
|
||||
bool _obscurePassword = true;
|
||||
String _selectedRole = 'student'; // 'student' or 'teacher'
|
||||
late String _selectedRole;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Usar role passado da tela anterior ou default 'student'
|
||||
_selectedRole = widget.selectedRole ?? 'student';
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -338,61 +347,6 @@ 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
|
||||
@@ -434,7 +388,7 @@ class _SignupPageState extends State<SignupPage> {
|
||||
// Login link
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.go('/login');
|
||||
context.go('/login?role=$_selectedRole');
|
||||
},
|
||||
child: Text(
|
||||
'Já tem conta? Entrar aqui',
|
||||
|
||||
Reference in New Issue
Block a user