fix: a new server could not be given its password
The form only rendered the password field when editing a saved server
(!_editNew). Adding a password-protected instance therefore failed with
"需要密码或已保存的凭据" and offered nowhere to type it. The field is now
always shown ("密码(如果需要)", empty for a passwordless server); a failed
connect that asks for a password focuses it, and a rejected password reads
as "密码错误,请重试".
Adds test/servers_form_test.dart. 0.3.18 (318).
This commit is contained in:
1 parent
e646130d1f
commit
d9d5424318
6 files changed
+64
-7
No files matched your search
@@ -5,6 +5,15 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.3.18 需要密码的服务器无法输入密码(分支 `flutter`)
|
||||||
|
|
||||||
|
| 项 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 问题 | 「添加服务器」表单的密码框只在编辑已保存服务器时显示(`!_editNew`)。新服务器首次连接被 401 拒绝后只提示「需要密码或已保存的凭据」,却没有输入密码的地方 |
|
||||||
|
| 修复 | 密码框始终显示,文案为「密码(如果需要)」,提示服务器未设置可留空;连接失败且错误提示需要密码时自动聚焦密码框;服务端返回 `Invalid credentials` 时显示为「密码错误,请重试」。新增 `test/servers_form_test.dart` 覆盖新服务器表单含密码框 |
|
||||||
|
| 版本 | **0.3.18(code 318)** |
|
||||||
|
---
|
||||||
|
|
||||||
## 0.3.17 设置页、侧栏底部服务器栏与追问处理行为(分支 `flutter`)
|
## 0.3.17 设置页、侧栏底部服务器栏与追问处理行为(分支 `flutter`)
|
||||||
|
|
||||||
| 项 | 结果 |
|
| 项 | 结果 |
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
|
|||||||
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
||||||
Flutter to compare mobile UI maturity.
|
Flutter to compare mobile UI maturity.
|
||||||
|
|
||||||
Status: 0.3.17 — servers (passwordless / password login, HTTP/HTTPS and
|
Status: 0.3.18 — servers (passwordless / password login, HTTP/HTTPS and
|
||||||
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
||||||
events, chat with streaming Markdown and full history paging, tool steps
|
events, chat with streaming Markdown and full history paging, tool steps
|
||||||
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
String _password = '';
|
String _password = '';
|
||||||
bool _connecting = false;
|
bool _connecting = false;
|
||||||
String? _formError;
|
String? _formError;
|
||||||
|
// A server may ask for a password only after the first attempt; the field
|
||||||
|
// is always there, but this one takes the focus when it is what is missing.
|
||||||
|
final FocusNode _passwordFocus = FocusNode();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -35,6 +38,12 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
if (widget.startEditing) _editing = true;
|
if (widget.startEditing) _editing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_passwordFocus.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListenableBuilder(
|
return ListenableBuilder(
|
||||||
@@ -159,6 +168,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
_password = '';
|
_password = '';
|
||||||
_formError = widget.app.lastError;
|
_formError = widget.app.lastError;
|
||||||
});
|
});
|
||||||
|
_focusPasswordIfNeeded(_formError);
|
||||||
widget.app.clearLastError();
|
widget.app.clearLastError();
|
||||||
} else if (mounted) {
|
} else if (mounted) {
|
||||||
setState(() => _connecting = false);
|
setState(() => _connecting = false);
|
||||||
@@ -236,16 +246,18 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
value: _insecure,
|
value: _insecure,
|
||||||
onChanged: (v) => setState(() => _insecure = v),
|
onChanged: (v) => setState(() => _insecure = v),
|
||||||
),
|
),
|
||||||
if (!_editNew) ...[
|
// Shown for new servers too: a password-protected instance rejects
|
||||||
_labelText('密码'),
|
// the first attempt, and this is where the password goes.
|
||||||
|
_labelText('密码(如果需要)'),
|
||||||
TextField(
|
TextField(
|
||||||
controller: TextEditingController(text: _password),
|
controller: TextEditingController(text: _password),
|
||||||
|
focusNode: _passwordFocus,
|
||||||
onChanged: (v) => _password = v,
|
onChanged: (v) => _password = v,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: '服务器密码', border: OutlineInputBorder()),
|
hintText: '服务器密码;服务器未设置可留空',
|
||||||
|
border: OutlineInputBorder()),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
if (_formError != null)
|
if (_formError != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 8),
|
padding: const EdgeInsets.only(top: 8),
|
||||||
@@ -296,11 +308,20 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
_connecting = false;
|
_connecting = false;
|
||||||
_formError = widget.app.lastError;
|
_formError = widget.app.lastError;
|
||||||
});
|
});
|
||||||
|
_focusPasswordIfNeeded(_formError);
|
||||||
widget.app.clearLastError();
|
widget.app.clearLastError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The server asked for a password: put the caret where it is typed.
|
||||||
|
void _focusPasswordIfNeeded(String? message) {
|
||||||
|
if (message == null || !message.contains('需要密码')) return;
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) _passwordFocus.requestFocus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _confirmDelete(Connection c) {
|
void _confirmDelete(Connection c) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
+7
-1
@@ -239,7 +239,13 @@ class AppState extends ChangeNotifier {
|
|||||||
|
|
||||||
/// A short, actionable message for a failed connect.
|
/// A short, actionable message for a failed connect.
|
||||||
String friendlyConnectError(Object e) {
|
String friendlyConnectError(Object e) {
|
||||||
if (e is ApiError) return e.message;
|
if (e is ApiError) {
|
||||||
|
if (e.status == 401 &&
|
||||||
|
e.message.toLowerCase().contains('invalid credentials')) {
|
||||||
|
return '密码错误,请重试';
|
||||||
|
}
|
||||||
|
return e.message;
|
||||||
|
}
|
||||||
if (e is ArgumentError) return e.message?.toString() ?? e.toString();
|
if (e is ArgumentError) return e.message?.toString() ?? e.toString();
|
||||||
if (e is TimeoutException) return '连接超时:检查服务器与代理地址';
|
if (e is TimeoutException) return '连接超时:检查服务器与代理地址';
|
||||||
final s = e.toString();
|
final s = e.toString();
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
|||||||
description: "A lightweight OpenChamber client for phones."
|
description: "A lightweight OpenChamber client for phones."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.3.17+317
|
version: 0.3.18+318
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.14.0
|
sdk: ^3.14.0
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:openchamber/screens/servers_screen.dart';
|
||||||
|
import 'package:openchamber/state.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('a new server form offers the password field', (tester) async {
|
||||||
|
final app = AppState();
|
||||||
|
addTearDown(app.dispose);
|
||||||
|
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
home: ServersScreen(app: app, startEditing: true),
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(find.text('添加服务器'), findsOneWidget);
|
||||||
|
// New servers need it too: a password-protected instance rejects the
|
||||||
|
// first attempt, and there must be somewhere to type the password.
|
||||||
|
expect(find.text('密码(如果需要)'), findsOneWidget);
|
||||||
|
expect(find.text('服务器密码;服务器未设置可留空'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user