- 프로필 꾸미기: 미리보기 중인 큰 타일의 테두리도 테마 색으로 바뀌게 수정, 미구매 템플릿에 "체험하기" 버튼을 따로 둬서 사기 전에도 눌러볼 수 있게 함 - 앱 전반의 확인/삭제/저장 같은 다이얼로그 기본 액션 버튼에 autofocus를 줘서 엔터 키로도 눌리게 함 (텍스트 입력이 있는 다이얼로그는 입력창 쪽에 autofocus + onSubmitted를 달아 입력 중 바로 엔터로 제출되게 처리) - HoldToRevealPasswordField 위젯 추가 - 눈 아이콘을 누르고 있는 동안만 비밀번호가 평문으로 보임. 로그인/간편인증/초기 비밀번호 변경 화면에 적용
107 lines
3.8 KiB
Dart
107 lines
3.8 KiB
Dart
// 🔑 비밀번호 변경 화면. (참고: 현재 앱 어디서도 이 화면으로 이동하는 곳이 없는 미사용 화면)
|
|
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../config.dart';
|
|
import '../theme/app_palette.dart';
|
|
import '../ui/app_notice.dart';
|
|
import '../ui/hold_to_reveal_password_field.dart';
|
|
import '../ui/login_screen.dart';
|
|
|
|
// 💡 main.dart 파일의 최하단(다른 클래스 중괄호 밖)에 붙여넣으세요.
|
|
class ChangePasswordScreen extends StatefulWidget {
|
|
final String studentId;
|
|
const ChangePasswordScreen({super.key, required this.studentId});
|
|
|
|
@override
|
|
State<ChangePasswordScreen> createState() => _ChangePasswordScreenState();
|
|
}
|
|
|
|
class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
|
final _pwController = TextEditingController();
|
|
bool _isLoading = false;
|
|
|
|
Future<void> _updatePassword() async {
|
|
String newPw = _pwController.text.trim();
|
|
if (newPw.isEmpty || newPw == "1234") {
|
|
AppNotice.show(context, '초기 비밀번호와 다른 안전한 비밀번호를 입력하세요.');
|
|
return;
|
|
}
|
|
|
|
setState(() => _isLoading = true);
|
|
try {
|
|
final response = await http.post(
|
|
Uri.parse('$baseUrl/api/users/change-password'),
|
|
headers: {"Content-Type": "application/json"},
|
|
body: jsonEncode({"studentId": widget.studentId, "newPassword": newPw}),
|
|
);
|
|
|
|
final res = jsonDecode(response.body);
|
|
if (response.statusCode == 200 && res['status'] == 'success') {
|
|
AppNotice.show(context, '비밀번호 변경 완료! 다시 로그인해 주세요.');
|
|
// 비밀번호를 바꿨으니 다시 로그인 화면으로 강제 이동
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
AppNotice.show(context, '통신 실패');
|
|
} finally {
|
|
setState(() => _isLoading = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppPalette.mist,
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(32.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'보안을 위해\n비밀번호를 변경해 주세요',
|
|
style: TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'처음 로그인 시 초기 비밀번호(1234)를 반드시 변경해야 이용이 가능합니다.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 32),
|
|
HoldToRevealPasswordField(
|
|
controller: _pwController,
|
|
autofocus: true,
|
|
labelText: '새로운 비밀번호 입력',
|
|
textInputAction: TextInputAction.done,
|
|
onSubmitted: (_) => _updatePassword(),
|
|
),
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
onPressed: _isLoading ? null : _updatePassword,
|
|
child: _isLoading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Text('변경 및 적용하기'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|