선생님 호출 시스템 추가 (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
+31
View File
@@ -23,6 +23,8 @@ import 'nfc_poccket_checkin_screen.dart';
import 'nfc_tag_writer_screen.dart';
import 'study_timer_screen.dart';
import 'teacher_attendance_page.dart';
import 'teacher_call_screen.dart';
import 'teacher_location_screen.dart';
import 'teacher_student_management_page.dart';
class MainDashboard extends StatefulWidget {
@@ -347,6 +349,22 @@ class _MainDashboardState extends State<MainDashboard> {
),
),
));
tiles.add((
id: 'teacher_call',
child: _buildModernCard(
icon: Icons.campaign_rounded,
title: '선생님 호출',
subtitle: '교무실 위치 확인 및 호출',
color: AppPalette.ink,
onTap: () => pushLaunchpad(
context,
(context) => TeacherCallScreen(
studentId: _displayId,
studentName: _displayName,
),
),
),
));
}
if (_isTeacherOrAbove) {
@@ -405,6 +423,19 @@ class _MainDashboardState extends State<MainDashboard> {
),
),
));
tiles.add((
id: 'teacher_location',
child: _buildModernCard(
icon: Icons.my_location_rounded,
title: '내 위치 알리기',
subtitle: '학생 호출 확인 및 위치 등록',
color: AppPalette.ink,
onTap: () => pushLaunchpad(
context,
(context) => TeacherLocationScreen(teacherId: _displayId),
),
),
));
}
if (_isAdmin) {
+360
View File
@@ -0,0 +1,360 @@
// 📍 선생님 호출 화면(학생용) (UI 전용). 선생님을 골라 방문 목적과 함께 호출한다.
// 서버 통신/상태는 lib/function/teacher_call_controller.dart가 담당한다.
import 'package:flutter/material.dart';
import '../data/teacher_call_schedule.dart';
import '../function/teacher_call_controller.dart';
import '../theme/app_palette.dart';
import 'app_notice.dart';
import 'title_pill.dart';
class TeacherCallScreen extends StatefulWidget {
final String studentId;
final String studentName;
const TeacherCallScreen({
super.key,
required this.studentId,
required this.studentName,
});
@override
State<TeacherCallScreen> createState() => _TeacherCallScreenState();
}
class _TeacherCallScreenState extends State<TeacherCallScreen> {
late final TeacherCallController _controller;
String? _selectedTeacherId;
String? _selectedTeacherName;
String _selectedPurpose = kCallPurposes.first;
final _customPurposeController = TextEditingController();
bool _useCustomPurpose = false;
@override
void initState() {
super.initState();
_controller = TeacherCallController(
studentId: widget.studentId,
studentName: widget.studentName,
);
_controller.init();
}
@override
void dispose() {
_controller.dispose();
_customPurposeController.dispose();
super.dispose();
}
Future<void> _call() async {
if (_selectedTeacherId == null) {
AppNotice.show(context, '선생님을 선택해 주세요.');
return;
}
final purpose = _useCustomPurpose
? _customPurposeController.text.trim()
: _selectedPurpose;
if (purpose.isEmpty) {
AppNotice.show(context, '방문 목적을 입력해 주세요.');
return;
}
final (success, message) = await _controller.callTeacher(
teacherId: _selectedTeacherId!,
purpose: purpose,
);
if (!mounted) return;
AppNotice.show(
context,
message,
icon: success ? Icons.check_circle_rounded : Icons.error_outline_rounded,
);
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _controller,
builder: (context, _) {
return Scaffold(
backgroundColor: AppPalette.mist,
appBar: AppBar(
backgroundColor: Colors.transparent,
foregroundColor: AppPalette.ink,
elevation: 0,
centerTitle: true,
title: const TitlePill('선생님 호출'),
),
body: _controller.isLoading
? const Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: _controller.refresh,
child: ListView(
padding: const EdgeInsets.all(16),
children: [
if (_controller.ranking.isNotEmpty) _buildRanking(),
const SizedBox(height: 16),
const Text(
'방문 목적',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildPurposeChips(),
if (_useCustomPurpose) ...[
const SizedBox(height: 8),
TextField(
controller: _customPurposeController,
maxLength: 40,
decoration: InputDecoration(
hintText: '용무를 입력하세요',
filled: true,
fillColor: AppPalette.paper,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: AppPalette.sage),
),
),
),
],
const SizedBox(height: 16),
const Text(
'선생님 선택',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildTeacherGrid(),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: _selectedTeacherId == null
? Colors.grey
: AppPalette.ink,
foregroundColor: AppPalette.paper,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
),
onPressed: _controller.isCalling ? null : _call,
child: _controller.isCalling
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: Text(
_selectedTeacherName == null
? '선생님을 선택해 주세요'
: '$_selectedTeacherName 선생님 호출하기',
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(height: 24),
const Text(
'내 호출 기록',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildMyCalls(),
],
),
),
);
},
);
}
Widget _buildRanking() {
final medals = ['🥇', '🥈', '🥉'];
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: AppPalette.paper,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppPalette.sage),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'오늘 인기 선생님',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
for (var i = 0; i < _controller.ranking.length; i++)
Column(
children: [
Text(medals[i], style: const TextStyle(fontSize: 22)),
Text(
_controller.ranking[i]['teacherName'] ?? '',
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(
'${_controller.ranking[i]['count']}회',
style: const TextStyle(color: Colors.grey, fontSize: 12),
),
],
),
],
),
],
),
);
}
Widget _buildPurposeChips() {
return Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final p in kCallPurposes)
ChoiceChip(
label: Text(p),
selected: !_useCustomPurpose && _selectedPurpose == p,
onSelected: (_) => setState(() {
_useCustomPurpose = false;
_selectedPurpose = p;
}),
selectedColor: AppPalette.ink,
labelStyle: TextStyle(
color: !_useCustomPurpose && _selectedPurpose == p
? Colors.white
: AppPalette.ink,
),
),
ChoiceChip(
label: const Text('직접 입력'),
selected: _useCustomPurpose,
onSelected: (_) => setState(() => _useCustomPurpose = true),
selectedColor: AppPalette.ink,
labelStyle: TextStyle(
color: _useCustomPurpose ? Colors.white : AppPalette.ink,
),
),
],
);
}
Widget _buildTeacherGrid() {
return GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: _controller.teachers.length,
itemBuilder: (context, index) {
final t = _controller.teachers[index];
final name = t['name'] ?? '';
final location = t['location'] ?? '교무실';
final isSelected = _selectedTeacherId == t['teacherId'];
final inClass = _controller.isInClassNow(name);
return GestureDetector(
onTap: () => setState(() {
_selectedTeacherId = t['teacherId'];
_selectedTeacherName = name;
}),
child: Container(
decoration: BoxDecoration(
color: isSelected ? const Color(0xFFEFF6FF) : AppPalette.paper,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected ? AppPalette.ink : AppPalette.sage,
width: isSelected ? 2 : 1,
),
),
child: Stack(
children: [
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
name,
style: const TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
'${kLocationIcons[location] ?? '📍'} $location',
style: const TextStyle(
fontSize: 11,
color: Colors.grey,
),
),
],
),
),
if (inClass)
Positioned(
top: 4,
right: 4,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 1,
),
decoration: BoxDecoration(
color: Colors.orange[100],
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.orange),
),
child: const Text(
'수업중',
style: TextStyle(fontSize: 9, color: Colors.orange),
),
),
),
],
),
),
);
},
);
}
Widget _buildMyCalls() {
if (_controller.myCalls.isEmpty) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Text('아직 호출 기록이 없어요.', style: TextStyle(color: Colors.grey)),
);
}
return Column(
children: [
for (final c in _controller.myCalls)
Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: AppPalette.paper,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: Text('${c['teacherName']} 선생님 · ${c['purpose']}'),
),
Text(
'${c['createdAt'] ?? ''}'.split(' ').last,
style: const TextStyle(color: Colors.grey, fontSize: 12),
),
],
),
),
],
);
}
}
+198
View File
@@ -0,0 +1,198 @@
// 📍 선생님 위치 등록 화면(교사용) (UI 전용). 본인 위치를 바꾸고, 받은 호출을 확인한다.
// 서버 통신/상태는 lib/function/teacher_location_controller.dart가 담당한다.
import 'package:flutter/material.dart';
import '../data/teacher_call_schedule.dart';
import '../function/teacher_location_controller.dart';
import '../theme/app_palette.dart';
import 'app_notice.dart';
import 'title_pill.dart';
class TeacherLocationScreen extends StatefulWidget {
final String teacherId;
const TeacherLocationScreen({super.key, required this.teacherId});
@override
State<TeacherLocationScreen> createState() => _TeacherLocationScreenState();
}
class _TeacherLocationScreenState extends State<TeacherLocationScreen> {
late final TeacherLocationController _controller;
@override
void initState() {
super.initState();
_controller = TeacherLocationController(teacherId: widget.teacherId);
_controller.init();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
Future<void> _selectLocation(String location) async {
final (success, message) = await _controller.updateLocation(location);
if (!mounted) return;
AppNotice.show(
context,
message,
icon: success ? Icons.check_circle_rounded : Icons.error_outline_rounded,
);
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _controller,
builder: (context, _) {
return Scaffold(
backgroundColor: AppPalette.mist,
appBar: AppBar(
backgroundColor: Colors.transparent,
foregroundColor: AppPalette.ink,
elevation: 0,
centerTitle: true,
title: const TitlePill('내 위치 알리기'),
),
body: _controller.isLoading
? const Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: _controller.fetchReceivedCalls,
child: ListView(
padding: const EdgeInsets.all(16),
children: [
Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFFEFF6FF),
borderRadius: BorderRadius.circular(14),
),
child: Row(
children: [
const Text(
'현재 위치',
style: TextStyle(fontWeight: FontWeight.bold),
),
const Spacer(),
Text(
'${kLocationIcons[_controller.currentLocation] ?? '📍'} ${_controller.currentLocation}',
style: const TextStyle(
fontWeight: FontWeight.bold,
color: AppPalette.ink,
),
),
],
),
),
const SizedBox(height: 20),
const Text(
'위치 선택',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1.3,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: kLocationOptions.length,
itemBuilder: (context, index) {
final loc = kLocationOptions[index];
final isSelected = _controller.currentLocation == loc;
return GestureDetector(
onTap: _controller.isSaving
? null
: () => _selectLocation(loc),
child: Container(
decoration: BoxDecoration(
color: isSelected
? AppPalette.ink
: AppPalette.paper,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected
? AppPalette.ink
: AppPalette.sage,
),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
kLocationIcons[loc] ?? '📍',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 4),
Text(
loc,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: isSelected
? Colors.white
: AppPalette.ink,
),
),
],
),
),
),
);
},
),
const SizedBox(height: 24),
const Text(
'나를 찾은 학생 기록',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildReceivedCalls(),
],
),
),
);
},
);
}
Widget _buildReceivedCalls() {
if (_controller.receivedCalls.isEmpty) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Text('아직 호출 기록이 없어요.', style: TextStyle(color: Colors.grey)),
);
}
return Column(
children: [
for (final c in _controller.receivedCalls)
Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: AppPalette.paper,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: Text('${c['studentName']} 학생 · ${c['purpose']}'),
),
Text(
'${c['createdAt'] ?? ''}',
style: const TextStyle(color: Colors.grey, fontSize: 11),
),
],
),
),
],
);
}
}