Skip to content

Commit

Permalink
添加注册功能
Browse files Browse the repository at this point in the history
更改找回密码提示信息
  • Loading branch information
deretame committed Oct 13, 2024
1 parent 28410f2 commit 83ec671
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 29 deletions.
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks
/.kotlin/sessions/kotlin-compiler-12647246574294006378.salive
16 changes: 16 additions & 0 deletions lib/mobx/string_select.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:mobx/mobx.dart';

part 'string_select.g.dart';

// ignore: library_private_types_in_public_api
class StringSelectStore = _StringSelectStore with _$StringSelectStore;

abstract class _StringSelectStore with Store {
@observable
String date = ''; //MobX 管理的日期字符串

@action
void setDate(String newDate) {
date = newDate;
}
}
48 changes: 48 additions & 0 deletions lib/mobx/string_select.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions lib/network/http/http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ Future<String> login(String username, String password) async {
}
}

Future<Map<String, dynamic>> register(
String birthday,
String email,
String gender,
String name,
String password,
) async {
final Map<String, dynamic> jsonMap = {
"answer1": "4",
"answer2": "5",
"answer3": "6",
"birthday": birthday,
"email": email,
"gender": gender,
"name": name,
"password": password,
"question1": "1",
"question2": "2",
"question3": "3"
};

final Map<String, dynamic> data = await request(
'https://picaapi.picacomic.com/auth/register',
'POST',
json.encode(jsonMap));
debugPrint(data.toString());

return data;
}

Future<Map<String, dynamic>> search(
{String keyword = '',
String sort = 'dd',
Expand Down
4 changes: 3 additions & 1 deletion lib/network/http/http_request_build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ Map<String, String> _getRequestHeaders(String url, String method,
}
}

if (authorization != null && !url.contains('/auth/sign-in')) {
if (authorization != null &&
!url.contains('/auth/sign-in') &&
!url.contains('/auth/register')) {
headers['authorization'] = authorization;
}

Expand Down
39 changes: 36 additions & 3 deletions lib/page/init_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class _InitPageState extends ConsumerState<InitPage> {
Future<void> getAuthorizationStatus() async {
final colorNotifier = ref.read(defaultColorProvider);
needLogin = false;
if (getAuthorization() == null) {
if (getAuthorization() == null &&
(getAccount() == null || getPassword() == null)) {
CherryToast.warning(
description: Text("没有获取到登录状态哦,请先登录呢~",
style: TextStyle(color: colorNotifier.defaultTextColor)),
Expand All @@ -71,7 +72,8 @@ class _InitPageState extends ConsumerState<InitPage> {
}

Future<void> getLoginStatus() async {
if (getAuthorization() == null) {
if (getAuthorization() == null &&
(getAccount() == null || getPassword() == null)) {
return;
}

Expand Down Expand Up @@ -119,7 +121,38 @@ class _InitPageState extends ConsumerState<InitPage> {
backgroundColor: colorNotifier.defaultBackgroundColor,
).show(context);
navigateToNoReturn(context, "/login");
return;
} else {
final result = await login(getAccount()!, getPassword()!);

if (!mounted) return;

if (result == "true") {
CherryToast.success(
description: Text(
"登录成功!",
style: TextStyle(color: colorNotifier.defaultTextColor),
),
animationType: AnimationType.fromTop,
animationDuration: const Duration(milliseconds: 3000),
toastDuration: const Duration(milliseconds: 1500),
autoDismiss: true,
backgroundColor: colorNotifier.defaultBackgroundColor,
).show(context);
continue;
} else {
CherryToast.warning(
description: Text(
"登录失败,正在重试...",
style: TextStyle(color: colorNotifier.defaultTextColor),
),
animationType: AnimationType.fromTop,
animationDuration: const Duration(milliseconds: 3000),
toastDuration: const Duration(milliseconds: 1500),
autoDismiss: true,
backgroundColor: colorNotifier.defaultBackgroundColor,
).show(context);
continue;
}
}
} else {
continue; // Retry on other errors
Expand Down
31 changes: 15 additions & 16 deletions lib/page/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class LoginPage extends StatefulWidget {
}

class _LoginPageState extends State<LoginPage> {
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _account = TextEditingController();
final TextEditingController _password = TextEditingController();
final ButtonStyle style =
ElevatedButton.styleFrom(minimumSize: const Size(200, 40));

@override
void dispose() {
_usernameController.dispose();
_passwordController.dispose();
_account.dispose();
_password.dispose();
super.dispose();
}

Expand Down Expand Up @@ -80,9 +80,7 @@ class _LoginPageState extends State<LoginPage> {
},
);

// 在这里处理登录逻辑
final result =
await login(_usernameController.text, _passwordController.text);
final result = await login(_account.text, _password.text);

// 当登录逻辑完成后,关闭加载动画
if (!mounted) return;
Expand All @@ -91,8 +89,8 @@ class _LoginPageState extends State<LoginPage> {
debugPrint(result);

if (result == "true") {
setAccount(_usernameController.text);
setPassword(_passwordController.text);
setAccount(_account.text);
setPassword(_password.text);
_showDialog("登录成功", "正在跳转...");
Future.delayed(const Duration(seconds: 2), () {
// 检查State是否仍然挂载
Expand Down Expand Up @@ -121,25 +119,23 @@ class _LoginPageState extends State<LoginPage> {
children: <Widget>[
// 账号输入框
TextField(
controller: _usernameController,
controller: _account,
decoration: const InputDecoration(
labelText: '账号',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 20), // 用于添加空间

// 密码输入框
TextField(
controller: _passwordController,
controller: _password,
decoration: const InputDecoration(
labelText: '密码',
border: OutlineInputBorder(),
),
obscureText: true, // 隐藏输入内容
),
const SizedBox(height: 10), // 用于添加空间

Row(
mainAxisAlignment: MainAxisAlignment.center, // 设置Row中的内容水平居中
children: [
Expand All @@ -151,7 +147,6 @@ class _LoginPageState extends State<LoginPage> {
],
),
const SizedBox(height: 10), // 用于添加空间

Expanded(
child: Container(), // 占据剩余空间
),
Expand All @@ -163,13 +158,17 @@ class _LoginPageState extends State<LoginPage> {
children: [
TextButton(
onPressed: () {
nothingDialog(context);
navigateTo(context, '/register');
},
child: const Text('注册账号'),
),
TextButton(
onPressed: () {
nothingDialog(context);
commonDialog(
context,
"找回密码",
"哔咔实际上已经无法找回密码,所以这个功能实际上不存在。",
);
},
child: const Text('找回密码'),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/page/mainPage/search/widget/comic_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class _ComicListWidgetState extends State<ComicListWidget> {
enter.pageCount = _page;
});
}
while (_docInfos.length <= 10 &&
while (_docInfos.length <= 6 &&
results.comics.page.toInt() < results.comics.pages.toInt()) {
_page++;
enter.pageCount = _page;
Expand Down
Loading

0 comments on commit 83ec671

Please sign in to comment.