From f62ee8d55b304d6ba23be463116859dcb4c52aad Mon Sep 17 00:00:00 2001 From: niuhuan Date: Fri, 25 Feb 2022 14:31:25 +0800 Subject: [PATCH] modify password setting --- go/pikapika/client.go | 7 +- lib/basic/Method.dart | 7 ++ lib/screens/AccountScreen.dart | 1 - lib/screens/ModifyPasswordScreen.dart | 131 ++++++++++++++++++++++++++ lib/screens/SettingsScreen.dart | 14 ++- 5 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 lib/screens/ModifyPasswordScreen.dart diff --git a/go/pikapika/client.go b/go/pikapika/client.go index 71adb8f..1a4e1d3 100644 --- a/go/pikapika/client.go +++ b/go/pikapika/client.go @@ -543,7 +543,12 @@ func updatePassword(params string) (string, error) { if err != nil { return "", err } - return "", client.UpdatePassword(paramsStruct.OldPassword, paramsStruct.NewPassword) + err = client.UpdatePassword(paramsStruct.OldPassword, paramsStruct.NewPassword) + if err != nil { + return "", err + } + setPassword(paramsStruct.NewPassword) + return "", nil } func updateSlogan(slogan string) (string, error) { diff --git a/lib/basic/Method.dart b/lib/basic/Method.dart index 461e2ce..a79e542 100644 --- a/lib/basic/Method.dart +++ b/lib/basic/Method.dart @@ -698,4 +698,11 @@ class Method { return await _flatInvoke("updateAvatar", data); } + /// 修改密码 + Future updatePassword(String oldPassword, String newPassword) { + return _flatInvoke("updatePassword", { + "oldPassword": oldPassword, + "newPassword": newPassword, + }); + } } diff --git a/lib/screens/AccountScreen.dart b/lib/screens/AccountScreen.dart index f3e498d..598b7a3 100644 --- a/lib/screens/AccountScreen.dart +++ b/lib/screens/AccountScreen.dart @@ -54,7 +54,6 @@ class _AccountScreenState extends State { Widget _buildGui() { return Scaffold( appBar: AppBar( - brightness: Brightness.dark, title: Text('配置选项'), actions: [ IconButton( diff --git a/lib/screens/ModifyPasswordScreen.dart b/lib/screens/ModifyPasswordScreen.dart new file mode 100644 index 0000000..336d096 --- /dev/null +++ b/lib/screens/ModifyPasswordScreen.dart @@ -0,0 +1,131 @@ +import 'package:flutter/material.dart'; +import 'package:pikapika/basic/Method.dart'; +import 'package:pikapika/screens/components/ContentLoading.dart'; + +import '../basic/Common.dart'; + +class ModifyPasswordScreen extends StatefulWidget { + @override + State createState() => _ModifyPasswordScreenState(); +} + +class _ModifyPasswordScreenState extends State { + late bool _loading = false; + late String _oldPassword = ""; + late String _newPassword = ""; + late String _newPasswordRep = ""; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("修改密码"), + ), + body: _loading + ? Stack( + children: [ + ContentLoading(label: "请稍后"), + WillPopScope( + child: Container(), + onWillPop: () async { + return false; + }, + ), + ], + ) + : _buildForm(), + ); + } + + Widget _buildForm() { + return ListView( + children: [ + const Divider(), + ListTile( + title: Text("旧密码"), + subtitle: Text(_oldPassword == "" ? "未填写" : '\u2022' * 10), + onTap: () async { + String? input = await displayTextInputDialog( + context, + src: _oldPassword, + title: '旧密码', + hint: '请输入旧密码', + isPasswd: true, + ); + if (input != null) { + setState(() { + _oldPassword = input; + }); + } + }, + ), + const Divider(), + ListTile( + title: Text("新密码"), + subtitle: Text(_newPassword == "" ? "未填写" : '\u2022' * 10), + onTap: () async { + String? input = await displayTextInputDialog( + context, + src: _newPassword, + title: '新密码', + hint: '请输入新密码', + isPasswd: true, + ); + if (input != null) { + setState(() { + _newPassword = input; + }); + } + }, + ), + const Divider(), + ListTile( + title: Text("重复输入新密码"), + subtitle: Text(_newPasswordRep == "" ? "未填写" : '\u2022' * 10), + onTap: () async { + String? input = await displayTextInputDialog( + context, + src: _newPasswordRep, + title: '重复输入新密码', + hint: '请重复输入新密码', + isPasswd: true, + ); + if (input != null) { + setState(() { + _newPasswordRep = input; + }); + } + }, + ), + const Divider(), + Container( + margin: EdgeInsets.all(10), + child: MaterialButton( + textColor: Colors.white, + color: Theme.of(context).appBarTheme.backgroundColor, + onPressed: () async { + if (_newPasswordRep != _newPassword) { + defaultToast(context, "新密码不匹配"); + return; + } + setState(() { + _loading = true; + }); + try { + await method.updatePassword(_oldPassword, _newPassword); + defaultToast(context, "修改成功"); + Navigator.of(context).pop(); + } catch (e) { + defaultToast(context, "失败 : $e"); + setState(() { + _loading = false; + }); + } + }, + child: Text("确认"), + ), + ), + ], + ); + } +} diff --git a/lib/screens/SettingsScreen.dart b/lib/screens/SettingsScreen.dart index 9e0ee21..e8d05db 100644 --- a/lib/screens/SettingsScreen.dart +++ b/lib/screens/SettingsScreen.dart @@ -16,10 +16,10 @@ import 'package:pikapika/basic/config/FullScreenUI.dart'; import 'package:pikapika/basic/config/KeyboardController.dart'; import 'package:pikapika/basic/config/NoAnimation.dart'; import 'package:pikapika/basic/config/PagerAction.dart'; +import 'package:pikapika/basic/config/Quality.dart'; import 'package:pikapika/basic/config/ReaderDirection.dart'; import 'package:pikapika/basic/config/ReaderSliderPosition.dart'; import 'package:pikapika/basic/config/ReaderType.dart'; -import 'package:pikapika/basic/config/Quality.dart'; import 'package:pikapika/basic/config/ShadowCategories.dart'; import 'package:pikapika/basic/config/Themes.dart'; import 'package:pikapika/basic/config/TimeOffsetHour.dart'; @@ -30,6 +30,7 @@ import 'package:pikapika/screens/components/NetworkSetting.dart'; import 'CleanScreen.dart'; import 'MigrateScreen.dart'; +import 'ModifyPasswordScreen.dart'; class SettingsScreen extends StatelessWidget { @override @@ -37,6 +38,17 @@ class SettingsScreen extends StatelessWidget { appBar: AppBar(title: Text('设置')), body: ListView( children: [ + Divider(), + ListTile( + onTap: () async { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ModifyPasswordScreen()), + ); + }, + title: Text('修改密码'), + ), Divider(), NetworkSetting(), Divider(),