correção de bugs, creação propria para turmas, e preparação para criar quizzes
This commit is contained in:
@@ -31,6 +31,27 @@ class _JoinClassPageState extends State<JoinClassPage> {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final currentUser = AuthService.currentUser;
|
||||
|
||||
if (currentUser == null) {
|
||||
setState(() => _isLoading = false);
|
||||
_showError('Erro: Utilizador não autenticado');
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar role — apenas alunos podem entrar por código
|
||||
final userRole = await AuthService.getUserRole(currentUser.uid);
|
||||
if (userRole != 'student') {
|
||||
setState(() => _isLoading = false);
|
||||
_showError('Apenas alunos podem entrar em turmas por código.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Ler classId autorizado do aluno (definido no registo)
|
||||
final authorizedClassId = await AuthService.getStudentClassId(
|
||||
currentUser.uid,
|
||||
);
|
||||
|
||||
// Procurar turma pelo código
|
||||
final classQuery = await FirebaseFirestore.instance
|
||||
.collection('classes')
|
||||
@@ -46,11 +67,14 @@ class _JoinClassPageState extends State<JoinClassPage> {
|
||||
|
||||
final classDoc = classQuery.docs.first;
|
||||
final classId = classDoc.id;
|
||||
final currentUser = AuthService.currentUser;
|
||||
|
||||
if (currentUser == null) {
|
||||
// Verificar se o aluno está autorizado a entrar nesta turma
|
||||
if (authorizedClassId == null || authorizedClassId != classId) {
|
||||
setState(() => _isLoading = false);
|
||||
_showError('Erro: Utilizador não autenticado');
|
||||
_showError(
|
||||
'Não tens permissão para entrar nesta turma.\n'
|
||||
'O teu professor ainda não te adicionou a esta disciplina.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,7 +96,10 @@ class _JoinClassPageState extends State<JoinClassPage> {
|
||||
await FirebaseFirestore.instance.collection('enrollments').add({
|
||||
'classId': classId,
|
||||
'studentId': currentUser.uid,
|
||||
'studentName': currentUser.displayName ?? currentUser.email?.split('@')[0] ?? 'Aluno',
|
||||
'studentName':
|
||||
currentUser.displayName ??
|
||||
currentUser.email?.split('@')[0] ??
|
||||
'Aluno',
|
||||
'joinedAt': FieldValue.serverTimestamp(),
|
||||
});
|
||||
|
||||
@@ -163,10 +190,7 @@ class _JoinClassPageState extends State<JoinClassPage> {
|
||||
Center(
|
||||
child: Text(
|
||||
'O professor partilhou contigo um código de 6 caracteres.',
|
||||
style: TextStyle(
|
||||
color: Colors.grey[600],
|
||||
fontSize: 14,
|
||||
),
|
||||
style: TextStyle(color: Colors.grey[600], fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -219,7 +243,9 @@ class _JoinClassPageState extends State<JoinClassPage> {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
disabledBackgroundColor: const Color(0xFF82C9BD).withOpacity(0.5),
|
||||
disabledBackgroundColor: const Color(
|
||||
0xFF82C9BD,
|
||||
).withOpacity(0.5),
|
||||
),
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
|
||||
Reference in New Issue
Block a user