登录逻辑
This commit is contained in:
BIN
assets/images/empty.png
Normal file
BIN
assets/images/empty.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -1,16 +1,12 @@
|
|||||||
import 'package:chat/models/user_info_model.dart';
|
import 'package:chat/models/user_info_model.dart';
|
||||||
|
|
||||||
class AuthModel {
|
class AuthModel {
|
||||||
String tokenType;
|
|
||||||
String accessToken;
|
String accessToken;
|
||||||
String userSig;
|
String userSig;
|
||||||
String userID;
|
String userID;
|
||||||
UserInfoModel userInfo;
|
UserInfoModel userInfo;
|
||||||
|
|
||||||
String get userToken => '$tokenType $accessToken';
|
|
||||||
|
|
||||||
AuthModel({
|
AuthModel({
|
||||||
required this.tokenType,
|
|
||||||
required this.accessToken,
|
required this.accessToken,
|
||||||
required this.userID,
|
required this.userID,
|
||||||
required this.userSig,
|
required this.userSig,
|
||||||
@@ -18,9 +14,8 @@ class AuthModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory AuthModel.fromJson(Map<String, dynamic> json) => AuthModel(
|
factory AuthModel.fromJson(Map<String, dynamic> json) => AuthModel(
|
||||||
tokenType: json['token_type'],
|
|
||||||
accessToken: json['access_token'],
|
accessToken: json['access_token'],
|
||||||
userID: json['user_id'],
|
userID: json['user_id'].toString(),
|
||||||
userSig: json['user_sig'],
|
userSig: json['user_sig'],
|
||||||
userInfo: UserInfoModel.fromJson(json['user_info']),
|
userInfo: UserInfoModel.fromJson(json['user_info']),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ class UserInfoModel {
|
|||||||
required this.address,
|
required this.address,
|
||||||
});
|
});
|
||||||
|
|
||||||
int userId;
|
String userId;
|
||||||
String username;
|
String username;
|
||||||
String nickname;
|
String? nickname;
|
||||||
String avatar;
|
String? avatar;
|
||||||
String? address;
|
String? address;
|
||||||
|
|
||||||
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
|
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
|
||||||
userId: json['user_id'],
|
userId: json['user_id'].toString(),
|
||||||
username: json['username'],
|
username: json['username'],
|
||||||
nickname: json['nickname'],
|
nickname: json['nickname'],
|
||||||
avatar: json['avatar'],
|
avatar: json['avatar'],
|
||||||
@@ -22,10 +22,18 @@ class UserInfoModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
factory UserInfoModel.empty() => UserInfoModel(
|
factory UserInfoModel.empty() => UserInfoModel(
|
||||||
userId: 0,
|
userId: '',
|
||||||
username: '',
|
username: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
address: '',
|
address: '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"userId": userId,
|
||||||
|
"username": username,
|
||||||
|
"nickname": nickname,
|
||||||
|
"avatar": avatar,
|
||||||
|
"address": address,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class AuthProvider {
|
|||||||
|
|
||||||
return AuthModel.fromJson(result);
|
return AuthModel.fromJson(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
UiTools.toast('区块链地址获取失败');
|
UiTools.toast('区块链地址获取失败 ${e.toString()}');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class AuthService extends GetxService {
|
|||||||
String get _userId => _box.read('userId') ?? '';
|
String get _userId => _box.read('userId') ?? '';
|
||||||
String get _userSig => _box.read('userSig') ?? '';
|
String get _userSig => _box.read('userSig') ?? '';
|
||||||
String get _userToken => _box.read('userToken') ?? '';
|
String get _userToken => _box.read('userToken') ?? '';
|
||||||
|
Map<String, dynamic> get _userInfo => _box.read('userInfo') ?? {};
|
||||||
|
|
||||||
Rx<UserInfoModel> userInfo = UserInfoModel.empty().obs;
|
Rx<UserInfoModel> userInfo = UserInfoModel.empty().obs;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ class AuthService extends GetxService {
|
|||||||
userSig = _userSig;
|
userSig = _userSig;
|
||||||
userId = _userId;
|
userId = _userId;
|
||||||
userToken = _userToken;
|
userToken = _userToken;
|
||||||
|
userInfo.value = UserInfoModel.fromJson(_userInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,11 +48,13 @@ class AuthService extends GetxService {
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
_box.write('userId', result.userID);
|
_box.write('userId', result.userID);
|
||||||
_box.write('userSig', result.userSig);
|
_box.write('userSig', result.userSig);
|
||||||
_box.write('userToken', result.userToken);
|
_box.write('userToken', result.accessToken);
|
||||||
|
_box.write('userInfo', result.userInfo.toJson());
|
||||||
|
|
||||||
userId = result.userID;
|
userId = result.userID;
|
||||||
userSig = result.userSig;
|
userSig = result.userSig;
|
||||||
userToken = result.userToken;
|
userToken = result.accessToken;
|
||||||
|
userInfo.value = result.userInfo;
|
||||||
|
|
||||||
isLogin.value = true;
|
isLogin.value = true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class HttpOptions {
|
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 connectTimeout = 15000;
|
||||||
static const int receiveTimeout = 15000;
|
static const int receiveTimeout = 15000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ class _AuthCreatePageState extends State<AuthCreatePage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('备份助记词'),
|
title: const Text('备份助记词'),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -134,6 +135,7 @@ class _AuthCreatePageState extends State<AuthCreatePage>
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,15 @@ class _AuthImportPageState extends State<AuthImportPage> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('导入账户'),
|
title: const Text('导入账户'),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
TextField(
|
TextField(
|
||||||
controller: _editingController,
|
controller: _editingController,
|
||||||
maxLines: 4,
|
maxLines: 5,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: '请输入您的助记词',
|
hintText: '请输入您的助记词,以空格分割单词或汉字',
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: AppColors.border,
|
color: AppColors.border,
|
||||||
@@ -52,7 +54,9 @@ class _AuthImportPageState extends State<AuthImportPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
const Text('支持导入所有遵循BIP标准生成的助记词'),
|
const Text('支持导入所有遵循BIP标准生成的助记词'),
|
||||||
|
const SizedBox(height: 16),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
String? address =
|
String? address =
|
||||||
@@ -68,6 +72,7 @@ class _AuthImportPageState extends State<AuthImportPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class _AuthPageState extends State<AuthPage> {
|
|||||||
title: const Text('ZH-CHAT'),
|
title: const Text('ZH-CHAT'),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -32,6 +35,8 @@ class _AuthPageState extends State<AuthPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class _QuickReplyBarState extends State<QuickReplyBar> {
|
|||||||
border: QuickReplyBar._border,
|
border: QuickReplyBar._border,
|
||||||
focusedBorder: QuickReplyBar._border,
|
focusedBorder: QuickReplyBar._border,
|
||||||
disabledBorder: QuickReplyBar._border,
|
disabledBorder: QuickReplyBar._border,
|
||||||
hintText: widget.comment?.user?.nickname.isNotEmpty ?? false
|
hintText: widget.comment?.user?.nickname != null
|
||||||
? '回复:${widget.comment?.user?.nickname}'
|
? '回复:${widget.comment?.user?.nickname}'
|
||||||
: '评论',
|
: '评论',
|
||||||
filled: true,
|
filled: true,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class _UserPageState extends State<UserPage> {
|
|||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Text(_.userInfo.value.nickname),
|
Text(_.userInfo.value.nickname ?? ''),
|
||||||
Text('${_.userInfo.value.address}'),
|
Text('${_.userInfo.value.address}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user