1
0
forked from baron/baron-sso

Merge commit 'e345570210aa0fc8acdb9cf042561f35f00812f0'

This commit is contained in:
2026-02-02 17:12:45 +09:00
31 changed files with 1239 additions and 160 deletions

View File

@@ -102,6 +102,37 @@ class ProfileRepository {
}
}
Future<void> changePassword({
required String currentPassword,
required String newPassword,
}) async {
final token = await _getToken();
final useCookie = AuthTokenStore.usesCookie();
if (token == null && !useCookie) throw Exception('No active session');
final url = Uri.parse('$_baseUrl/api/v1/user/me/password');
final client = createHttpClient(withCredentials: useCookie);
final headers = <String, String>{
'Content-Type': 'application/json',
};
if (!useCookie && token != null) {
headers['Authorization'] = 'Bearer $token';
}
final response = await client.post(
url,
headers: headers,
body: jsonEncode({
'currentPassword': currentPassword,
'newPassword': newPassword,
}),
);
client.close();
if (response.statusCode != 200) {
throw Exception('Failed to change password: ${response.body}');
}
}
Future<void> verifyUpdateCode(String phone, String code) async {
final token = await _getToken();
final useCookie = AuthTokenStore.usesCookie();

View File

@@ -26,6 +26,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
TextEditingController? _phoneController;
TextEditingController? _departmentController;
TextEditingController? _codeController;
TextEditingController? _currentPasswordController;
TextEditingController? _newPasswordController;
TextEditingController? _confirmPasswordController;
final FocusNode _nameFocus = FocusNode();
final FocusNode _departmentFocus = FocusNode();
final FocusNode _phoneFocus = FocusNode();
@@ -42,6 +45,13 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
bool _isCodeSent = false;
bool _isVerifying = false;
bool _isPasswordSaving = false;
String? _passwordError;
String? _passwordSuccess;
bool _showCurrentPassword = false;
bool _showNewPassword = false;
bool _showConfirmPassword = false;
@override
void initState() {
super.initState();
@@ -97,6 +107,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
_phoneController?.dispose();
_departmentController?.dispose();
_codeController?.dispose();
_currentPasswordController?.dispose();
_newPasswordController?.dispose();
_confirmPasswordController?.dispose();
_nameFocus.dispose();
_departmentFocus.dispose();
_phoneFocus.dispose();
@@ -113,6 +126,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
_nameController ??= TextEditingController(text: profile.name);
_departmentController ??= TextEditingController(text: profile.department);
_codeController ??= TextEditingController();
_currentPasswordController ??= TextEditingController();
_newPasswordController ??= TextEditingController();
_confirmPasswordController ??= TextEditingController();
if (_phoneController == null) {
_phoneController = TextEditingController(text: profile.phone);
@@ -256,6 +272,54 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
}
}
Future<void> _changePassword() async {
if (_isPasswordSaving) return;
final currentPassword = _currentPasswordController?.text.trim() ?? '';
final newPassword = _newPasswordController?.text.trim() ?? '';
final confirmPassword = _confirmPasswordController?.text.trim() ?? '';
if (currentPassword.isEmpty) {
setState(() => _passwordError = '현재 비밀번호를 입력해 주세요.');
return;
}
if (newPassword.isEmpty) {
setState(() => _passwordError = '새 비밀번호를 입력해 주세요.');
return;
}
if (newPassword != confirmPassword) {
setState(() => _passwordError = '새 비밀번호가 일치하지 않습니다.');
return;
}
setState(() {
_passwordError = null;
_passwordSuccess = null;
_isPasswordSaving = true;
});
try {
await ref.read(profileRepositoryProvider).changePassword(
currentPassword: currentPassword,
newPassword: newPassword,
);
_currentPasswordController?.clear();
_newPasswordController?.clear();
_confirmPasswordController?.clear();
setState(() {
_passwordSuccess = '비밀번호가 변경되었습니다.';
});
} catch (e) {
final message = e.toString().replaceFirst('Exception: ', '');
setState(() {
_passwordError = '비밀번호 변경 실패: $message';
});
} finally {
if (mounted) {
setState(() => _isPasswordSaving = false);
}
}
}
void _autoSaveIfEditing(UserProfile profile, String field) {
if (_editingField != field) return;
if (_isVerifying) return;
@@ -693,6 +757,104 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
);
}
Widget _buildPasswordSection() {
return _buildCard(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'비밀번호 변경',
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
),
const SizedBox(height: 8),
const Text(
'현재 비밀번호 확인 후 새 비밀번호로 변경합니다.',
style: TextStyle(color: Color(0xFF6B7280)),
),
const SizedBox(height: 16),
TextField(
controller: _currentPasswordController,
obscureText: !_showCurrentPassword,
decoration: InputDecoration(
labelText: '현재 비밀번호',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(_showCurrentPassword ? Icons.visibility_off : Icons.visibility),
onPressed: () => setState(() {
_showCurrentPassword = !_showCurrentPassword;
}),
),
),
),
const SizedBox(height: 12),
TextField(
controller: _newPasswordController,
obscureText: !_showNewPassword,
decoration: InputDecoration(
labelText: '새 비밀번호',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(_showNewPassword ? Icons.visibility_off : Icons.visibility),
onPressed: () => setState(() {
_showNewPassword = !_showNewPassword;
}),
),
),
),
const SizedBox(height: 12),
TextField(
controller: _confirmPasswordController,
obscureText: !_showConfirmPassword,
decoration: InputDecoration(
labelText: '새 비밀번호 확인',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(_showConfirmPassword ? Icons.visibility_off : Icons.visibility),
onPressed: () => setState(() {
_showConfirmPassword = !_showConfirmPassword;
}),
),
),
),
if (_passwordError != null) ...[
const SizedBox(height: 12),
Text(
_passwordError!,
style: const TextStyle(color: Colors.red),
),
],
if (_passwordSuccess != null) ...[
const SizedBox(height: 12),
Text(
_passwordSuccess!,
style: const TextStyle(color: Colors.green),
),
],
const SizedBox(height: 16),
Row(
children: [
ElevatedButton(
onPressed: _isPasswordSaving ? null : _changePassword,
child: _isPasswordSaving
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('비밀번호 변경'),
),
const SizedBox(width: 12),
TextButton(
onPressed: () => context.go('/recovery'),
child: const Text('비밀번호를 잊으셨나요?'),
),
],
),
],
),
);
}
Widget _buildContent(UserProfile profile, bool isUpdating) {
return RefreshIndicator(
onRefresh: () => ref.read(profileProvider.notifier).loadProfile(),
@@ -754,6 +916,10 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
],
),
),
const SizedBox(height: 28),
_buildSectionTitle('보안', '비밀번호를 안전하게 관리합니다.'),
const SizedBox(height: 12),
_buildPasswordSection(),
if (isUpdating || _isVerifying) ...[
const SizedBox(height: 24),
const Center(child: CircularProgressIndicator()),