선생님 호출 시스템 추가 (Firebase 버전을 앱 계정 체계로 이전)

별도로 돌아가던 Firebase RTDB 기반 호출 페이지(index.html/teacher.html)에서
발견한 XSS, 익명 접근(아무나 아무 선생님 위치 변경 가능), 이름 위조 문제를
우리 앱 로그인 체계로 재구현하면서 구조적으로 없앴다. 학생은 본인 계정으로만
호출하고 본인 호출 기록만 보이며, 교사는 본인 위치만 수정하고 본인이 받은
호출만 본다. TTS 대신 FCM 푸시로 대체. 시간표 데이터의 "김지"→"조신현" 오타도
"조신"으로 수정해서 옮겼다.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 23:34:08 +00:00
co-authored by Claude Sonnet 5
parent 89487a7dfc
commit 4cf759de62
6 changed files with 942 additions and 0 deletions
+124
View File
@@ -0,0 +1,124 @@
// 📍 선생님 호출(학생용) 화면의 기능(서버 통신/상태) 담당 컨트롤러.
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import '../config.dart';
import '../data/teacher_call_schedule.dart';
class TeacherCallController extends ChangeNotifier {
final String studentId;
final String studentName;
TeacherCallController({required this.studentId, required this.studentName});
bool _isLoading = true;
bool _isCalling = false;
List<dynamic> _teachers = [];
List<dynamic> _myCalls = [];
List<dynamic> _ranking = [];
bool _disposed = false;
bool get isLoading => _isLoading;
bool get isCalling => _isCalling;
List<dynamic> get teachers => _teachers;
List<dynamic> get myCalls => _myCalls;
List<dynamic> get ranking => _ranking;
void _safeNotify() {
if (!_disposed) notifyListeners();
}
@override
void dispose() {
_disposed = true;
super.dispose();
}
bool isInClassNow(String teacherName) {
final now = DateTime.now();
final hhmm =
'${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
return teachersInClassNow(now.weekday, hhmm).contains(teacherName);
}
Future<void> init() async {
await Future.wait([_fetchTeachers(), _fetchMyCalls(), _fetchRanking()]);
_isLoading = false;
_safeNotify();
}
Future<void> refresh() => init();
Future<void> _fetchTeachers() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/api/teacher-call/teachers'),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_teachers = data['teachers'] ?? [];
}
} catch (_) {
// 조용히 무시 - 마지막으로 받아온 목록을 유지한다.
}
}
Future<void> _fetchMyCalls() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/api/teacher-call/my-calls?studentId=$studentId'),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_myCalls = data['calls'] ?? [];
}
} catch (_) {
// 조용히 무시
}
}
Future<void> _fetchRanking() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/api/teacher-call/ranking'),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_ranking = data['ranking'] ?? [];
}
} catch (_) {
// 조용히 무시
}
}
Future<(bool success, String message)> callTeacher({
required String teacherId,
required String purpose,
}) async {
_isCalling = true;
_safeNotify();
try {
final response = await http.post(
Uri.parse('$baseUrl/api/teacher-call/call'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({
"studentId": studentId,
"studentName": studentName,
"teacherId": teacherId,
"purpose": purpose,
}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
if (response.statusCode == 200 && result['status'] == 'success') {
await Future.wait([_fetchMyCalls(), _fetchRanking()]);
return (true, '${result['message'] ?? '호출했습니다.'}');
}
return (false, '${result['message'] ?? '호출 실패'}');
} catch (e) {
return (false, '네트워크 에러: $e');
} finally {
_isCalling = false;
_safeNotify();
}
}
}
@@ -0,0 +1,97 @@
// 📍 선생님 위치 등록(교사용) 화면의 기능(서버 통신/상태) 담당 컨트롤러.
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import '../config.dart';
class TeacherLocationController extends ChangeNotifier {
final String teacherId;
TeacherLocationController({required this.teacherId});
bool _isLoading = true;
bool _isSaving = false;
String _currentLocation = "교무실";
List<dynamic> _receivedCalls = [];
bool _disposed = false;
bool get isLoading => _isLoading;
bool get isSaving => _isSaving;
String get currentLocation => _currentLocation;
List<dynamic> get receivedCalls => _receivedCalls;
void _safeNotify() {
if (!_disposed) notifyListeners();
}
@override
void dispose() {
_disposed = true;
super.dispose();
}
Future<void> init() async {
await Future.wait([_fetchMyLocation(), fetchReceivedCalls()]);
_isLoading = false;
_safeNotify();
}
Future<void> _fetchMyLocation() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/api/teacher-call/teachers'),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
final List<dynamic> list = data['teachers'] ?? [];
final mine = list.firstWhere(
(t) => t['teacherId'] == teacherId,
orElse: () => null,
);
if (mine != null) _currentLocation = mine['location'] ?? '교무실';
}
} catch (_) {
// 조용히 무시
}
}
Future<void> fetchReceivedCalls() async {
try {
final response = await http.get(
Uri.parse(
'$baseUrl/api/teacher-call/received-calls?teacherId=$teacherId',
),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_receivedCalls = data['calls'] ?? [];
_safeNotify();
}
} catch (_) {
// 조용히 무시
}
}
Future<(bool success, String message)> updateLocation(String location) async {
_isSaving = true;
_safeNotify();
try {
final response = await http.post(
Uri.parse('$baseUrl/api/teacher-call/location'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"teacherId": teacherId, "location": location}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
if (response.statusCode == 200 && result['status'] == 'success') {
_currentLocation = location;
return (true, '${result['message'] ?? '위치가 업데이트되었습니다.'}');
}
return (false, '${result['message'] ?? '업데이트 실패'}');
} catch (e) {
return (false, '네트워크 에러: $e');
} finally {
_isSaving = false;
_safeNotify();
}
}
}