Skip to content

Commit

Permalink
Merge pull request #76 from the-other-world/dev
Browse files Browse the repository at this point in the history
Login | 优化
  • Loading branch information
Muska-Ami authored Feb 14, 2024
2 parents 2be7f72 + 321f131 commit 24bae5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
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());
}
}
}

0 comments on commit 24bae5c

Please sign in to comment.