Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login | 优化 #76

Merged
merged 5 commits into from Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ body:
required: true
- label: 我确保这个 BUG 在最新版本可复现
required: true
- label: 我确保我已经熟记[提问的智慧](https://lug.ustc.edu.cn/wiki/doc/smart-questions/)
required: true
- type: textarea
id: what-happened
attributes:
Expand Down
72 changes: 31 additions & 41 deletions lib/ui/views/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class _LoginState extends State<Login> {
_LoginState({required this.title});

final String title;

final userController = TextEditingController();
final passwordController = TextEditingController();

Expand Down Expand Up @@ -76,7 +75,7 @@ class _LoginState extends State<Login> {
Container(
margin: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => {_login()},
onPressed: () => _login(),
child: const Text('登录'),
),
),
Expand All @@ -90,50 +89,41 @@ class _LoginState extends State<Login> {
);
}

_login() async {
if (userController.text == '') {
Get.snackbar(
'无效数据',
'请输入用户名',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
} else if (passwordController.text == '') {
void _showSnackbar(String message) {
Get.snackbar(
'无效数据',
message,
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
}

void _login() async {
if (userController.text.isEmpty || passwordController.text.isEmpty) {
_showSnackbar('请输入用户名或密码');
return;
}

Get.snackbar(
'登录中',
'正在请求...',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
final res = await LoginAuth()
.requestLogin(userController.text, passwordController.text);
if (res is UserInfoModel) {
await UserInfoPrefs.setInfo(res);
UserInfoPrefs.saveToFile();
Get.snackbar(
'无效数据',
'请输入密码',
'登录成功',
'欢迎您,指挥官 ${res.user}',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
Get.toNamed('/panel/home');
} else {
Get.snackbar(
'登录中',
'正在请求...',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
final res = await LoginAuth()
.requestLogin(userController.text, passwordController.text);
if (res is UserInfoModel) {
//UserInfoCache.info = res;
//print(UserInfoCache.info);
await UserInfoPrefs.setInfo(res);
UserInfoPrefs.saveToFile();
Get.snackbar(
'登录成功',
'欢迎您,指挥官 ${res.user}',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
Get.toNamed('/panel/home');
} else {
Get.snackbar(
'登录失败',
res.toString(),
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
}
_showSnackbar(res.toString());
}
}
}