登录逻辑

This commit is contained in:
2022-10-21 14:03:48 +08:00
parent 30a9279ff1
commit 4bf03d234b
11 changed files with 154 additions and 135 deletions

BIN
assets/images/empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -1,16 +1,12 @@
import 'package:chat/models/user_info_model.dart';
class AuthModel {
String tokenType;
String accessToken;
String userSig;
String userID;
UserInfoModel userInfo;
String get userToken => '$tokenType $accessToken';
AuthModel({
required this.tokenType,
required this.accessToken,
required this.userID,
required this.userSig,
@@ -18,9 +14,8 @@ class AuthModel {
});
factory AuthModel.fromJson(Map<String, dynamic> json) => AuthModel(
tokenType: json['token_type'],
accessToken: json['access_token'],
userID: json['user_id'],
userID: json['user_id'].toString(),
userSig: json['user_sig'],
userInfo: UserInfoModel.fromJson(json['user_info']),
);

View File

@@ -7,14 +7,14 @@ class UserInfoModel {
required this.address,
});
int userId;
String userId;
String username;
String nickname;
String avatar;
String? nickname;
String? avatar;
String? address;
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
userId: json['user_id'],
userId: json['user_id'].toString(),
username: json['username'],
nickname: json['nickname'],
avatar: json['avatar'],
@@ -22,10 +22,18 @@ class UserInfoModel {
);
factory UserInfoModel.empty() => UserInfoModel(
userId: 0,
userId: '',
username: '',
nickname: '',
avatar: '',
address: '',
);
Map<String, dynamic> toJson() => {
"userId": userId,
"username": username,
"nickname": nickname,
"avatar": avatar,
"address": address,
};
}

View File

@@ -14,7 +14,7 @@ class AuthProvider {
return AuthModel.fromJson(result);
} catch (e) {
UiTools.toast('区块链地址获取失败');
UiTools.toast('区块链地址获取失败 ${e.toString()}');
return null;
}
}

View File

@@ -25,6 +25,7 @@ class AuthService extends GetxService {
String get _userId => _box.read('userId') ?? '';
String get _userSig => _box.read('userSig') ?? '';
String get _userToken => _box.read('userToken') ?? '';
Map<String, dynamic> get _userInfo => _box.read('userInfo') ?? {};
Rx<UserInfoModel> userInfo = UserInfoModel.empty().obs;
@@ -37,6 +38,7 @@ class AuthService extends GetxService {
userSig = _userSig;
userId = _userId;
userToken = _userToken;
userInfo.value = UserInfoModel.fromJson(_userInfo);
}
}
@@ -46,11 +48,13 @@ class AuthService extends GetxService {
if (result != null) {
_box.write('userId', result.userID);
_box.write('userSig', result.userSig);
_box.write('userToken', result.userToken);
_box.write('userToken', result.accessToken);
_box.write('userInfo', result.userInfo.toJson());
userId = result.userID;
userSig = result.userSig;
userToken = result.userToken;
userToken = result.accessToken;
userInfo.value = result.userInfo;
isLogin.value = true;

View File

@@ -1,5 +1,5 @@
class HttpOptions {
static const String baseUrl = 'http://api.gl.shangkelian.cn/api/';
static const String baseUrl = 'https://zh-chat.cnskl.com/api/';
static const int connectTimeout = 15000;
static const int receiveTimeout = 15000;
}

View File

@@ -46,7 +46,8 @@ class _AuthCreatePageState extends State<AuthCreatePage>
@override
Widget build(BuildContext context) {
return Scaffold(
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: const Text('备份助记词'),
actions: [
@@ -134,6 +135,7 @@ class _AuthCreatePageState extends State<AuthCreatePage>
),
],
),
),
);
}

View File

@@ -37,13 +37,15 @@ class _AuthImportPageState extends State<AuthImportPage> {
appBar: AppBar(
title: const Text('导入账户'),
),
body: Column(
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _editingController,
maxLines: 4,
maxLines: 5,
decoration: const InputDecoration(
hintText: '请输入您的助记词',
hintText: '请输入您的助记词,以空格分割单词或汉字',
border: OutlineInputBorder(
borderSide: BorderSide(
color: AppColors.border,
@@ -52,7 +54,9 @@ class _AuthImportPageState extends State<AuthImportPage> {
),
),
),
const SizedBox(height: 16),
const Text('支持导入所有遵循BIP标准生成的助记词'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
String? address =
@@ -68,6 +72,7 @@ class _AuthImportPageState extends State<AuthImportPage> {
),
],
),
),
);
}
}

View File

@@ -17,6 +17,9 @@ class _AuthPageState extends State<AuthPage> {
title: const Text('ZH-CHAT'),
),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
@@ -32,6 +35,8 @@ class _AuthPageState extends State<AuthPage> {
),
],
),
],
),
);
}
}

View File

@@ -49,7 +49,7 @@ class _QuickReplyBarState extends State<QuickReplyBar> {
border: QuickReplyBar._border,
focusedBorder: QuickReplyBar._border,
disabledBorder: QuickReplyBar._border,
hintText: widget.comment?.user?.nickname.isNotEmpty ?? false
hintText: widget.comment?.user?.nickname != null
? '回复:${widget.comment?.user?.nickname}'
: '评论',
filled: true,

View File

@@ -27,7 +27,7 @@ class _UserPageState extends State<UserPage> {
),
Column(
children: [
Text(_.userInfo.value.nickname),
Text(_.userInfo.value.nickname ?? ''),
Text('${_.userInfo.value.address}'),
],
),