修改登录流程

pull/1/head
张萌 3 years ago
parent b884ee4e16
commit c379abb3b6

File diff suppressed because it is too large Load Diff

@ -1,14 +1,19 @@
import 'package:aku_new_community/utils/hive_store.dart';
import 'package:hive/hive.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:aku_new_community/utils/hive_store.dart';
import 'china_region_model.dart'; import 'china_region_model.dart';
part 'picked_city_model.g.dart'; part 'picked_city_model.g.dart';
@JsonSerializable() @JsonSerializable()
@HiveType(typeId: 6)
class PickedCityModel { class PickedCityModel {
@HiveField(0)
final ChinaRegionModel province; final ChinaRegionModel province;
@HiveField(1)
final ChinaRegionModel city; final ChinaRegionModel city;
@HiveField(2)
final ChinaRegionModel district; final ChinaRegionModel district;
factory PickedCityModel.fromJson(Map<String, dynamic> json) => factory PickedCityModel.fromJson(Map<String, dynamic> json) =>
_$PickedCityModelFromJson(json); _$PickedCityModelFromJson(json);

@ -2,6 +2,50 @@
part of 'picked_city_model.dart'; part of 'picked_city_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class PickedCityModelAdapter extends TypeAdapter<PickedCityModel> {
@override
final int typeId = 6;
@override
PickedCityModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return PickedCityModel(
province: fields[0] as ChinaRegionModel,
city: fields[1] as ChinaRegionModel,
district: fields[2] as ChinaRegionModel,
);
}
@override
void write(BinaryWriter writer, PickedCityModel obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.province)
..writeByte(1)
..write(obj.city)
..writeByte(2)
..write(obj.district);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PickedCityModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// ************************************************************************** // **************************************************************************
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************

@ -1,17 +1,13 @@
import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:aku_new_community/widget/others/user_tool.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sms_autofill/sms_autofill.dart'; import 'package:sms_autofill/sms_autofill.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:aku_new_community/widget/others/user_tool.dart';
import '../../tab_navigator.dart';
class CodeMessagePage extends StatefulWidget { class CodeMessagePage extends StatefulWidget {
final String tel; final String tel;
@ -89,7 +85,6 @@ class _CodeMessagePageState extends State<CodeMessagePage> {
await UserTool.userProvider await UserTool.userProvider
.setLogin(re.data['data'] as int); .setLogin(re.data['data'] as int);
await UserTool.dataProvider.addHistories(); await UserTool.dataProvider.addHistories();
Get.offAll(() => TabNavigator());
} else { } else {
_errorMessage = re.data['msg']; _errorMessage = re.data['msg'];
BotToast.showText(text: re.data['msg']); BotToast.showText(text: re.data['msg']);

@ -1,12 +1,3 @@
import 'package:flutter/material.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:aku_new_community/pages/sign/login/code_message_page.dart'; import 'package:aku_new_community/pages/sign/login/code_message_page.dart';
import 'package:aku_new_community/pages/sign/login/forgot_psd_page.dart'; import 'package:aku_new_community/pages/sign/login/forgot_psd_page.dart';
import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/pages/sign/login/login_page.dart';
@ -17,7 +8,13 @@ import 'package:aku_new_community/pages/sign/widget/tel_text_field.dart';
import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/provider/app_provider.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:aku_new_community/widget/others/user_tool.dart';
import '../../tab_navigator.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class OtherLoginPage extends StatefulWidget { class OtherLoginPage extends StatefulWidget {
const OtherLoginPage({Key? key}) : super(key: key); const OtherLoginPage({Key? key}) : super(key: key);
@ -109,7 +106,6 @@ class _OtherLoginPageState extends State<OtherLoginPage> {
if (response.data['success']) { if (response.data['success']) {
await UserTool.userProvider.setLogin(response.data['data']); await UserTool.userProvider.setLogin(response.data['data']);
await UserTool.dataProvider.addHistories(); await UserTool.dataProvider.addHistories();
Get.offAll(() => TabNavigator());
} else { } else {
BotToast.showText(text: response.data['message']); BotToast.showText(text: response.data['message']);
} }

@ -1,11 +1,9 @@
import 'package:aku_new_community/pages/home/home_page.dart';
import 'package:aku_new_community/pages/sign/sign_func.dart'; import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/pages/sign/widget/login_button_widget.dart'; import 'package:aku_new_community/pages/sign/widget/login_button_widget.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:aku_new_community/widget/others/user_tool.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
class SetNickNamePage extends StatefulWidget { class SetNickNamePage extends StatefulWidget {
@ -85,15 +83,17 @@ class _SetNickNamePageState extends State<SetNickNamePage> {
), ),
), ),
_nickIsRepeat ? _nickRepeat() : 100.w.heightBox, _nickIsRepeat ? _nickRepeat() : 100.w.heightBox,
LoginButtonWidget( Padding(
padding: EdgeInsets.symmetric(horizontal: 24.w),
child: LoginButtonWidget(
onTap: () async { onTap: () async {
var result = await SignFunc.setNickName(_nickController.text); var result = await SignFunc.setNickName(_nickController.text);
if (result) { if (result) {
UserTool.userProvider.updateUserInfo(); await UserTool.userProvider.updateUserInfo();
} }
Get.offAll(HomePage());
}, },
text: '确定'), text: '确定'),
),
], ],
), ),
); );

@ -1,14 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:aku_new_community/pages/sign/login/psd_verify.dart'; import 'package:aku_new_community/pages/sign/login/psd_verify.dart';
import 'package:aku_new_community/pages/sign/sign_func.dart'; import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/pages/sign/widget/login_button_widget.dart'; import 'package:aku_new_community/pages/sign/widget/login_button_widget.dart';
import 'package:aku_new_community/pages/sign/widget/psd_text_field.dart'; import 'package:aku_new_community/pages/sign/widget/psd_text_field.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:aku_new_community/widget/others/user_tool.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:velocity_x/velocity_x.dart';
class SetPsdPage extends StatefulWidget { class SetPsdPage extends StatefulWidget {
const SetPsdPage({Key? key}) : super(key: key); const SetPsdPage({Key? key}) : super(key: key);
@ -94,7 +92,7 @@ class _SetPsdPageState extends State<SetPsdPage> {
var result = var result =
await SignFunc.settingPsd(_psdController.text); await SignFunc.settingPsd(_psdController.text);
if (result) { if (result) {
UserTool.userProvider.updateUserInfo(); await UserTool.userProvider.updateUserInfo();
} }
} }
: null, : null,

@ -5,6 +5,7 @@ import 'package:aku_new_community/models/user/my_house_model.dart';
import 'package:aku_new_community/models/user/user_info_model.dart'; import 'package:aku_new_community/models/user/user_info_model.dart';
import 'package:aku_new_community/pages/sign/login/set_nick_name_page.dart'; import 'package:aku_new_community/pages/sign/login/set_nick_name_page.dart';
import 'package:aku_new_community/pages/sign/login/set_psd_page.dart'; import 'package:aku_new_community/pages/sign/login/set_psd_page.dart';
import 'package:aku_new_community/pages/tab_navigator.dart';
import 'package:aku_new_community/provider/sign_up_provider.dart'; import 'package:aku_new_community/provider/sign_up_provider.dart';
import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/base_model.dart';
@ -167,6 +168,8 @@ class SignFunc {
await Get.to(() => SetPsdPage()); await Get.to(() => SetPsdPage());
} else if (UserTool.userProvider.userInfoModel!.nickName == null) { } else if (UserTool.userProvider.userInfoModel!.nickName == null) {
await Get.to(() => SetNickNamePage()); await Get.to(() => SetNickNamePage());
} else {
Get.offAll(() => TabNavigator());
} }
} }

@ -3,8 +3,7 @@ import 'dart:io';
import 'package:aku_new_community/main_initialize.dart'; import 'package:aku_new_community/main_initialize.dart';
import 'package:aku_new_community/pages/setting_page/agreement_page/agreement_page.dart'; import 'package:aku_new_community/pages/setting_page/agreement_page/agreement_page.dart';
import 'package:aku_new_community/pages/setting_page/agreement_page/privacy_page.dart'; import 'package:aku_new_community/pages/setting_page/agreement_page/privacy_page.dart';
import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/pages/sign/login/login_page.dart';
import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/developer_util.dart';
import 'package:aku_new_community/utils/headers.dart'; import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/hive_store.dart'; import 'package:aku_new_community/utils/hive_store.dart';
@ -19,9 +18,6 @@ import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
import 'package:provider/provider.dart';
import '../tab_navigator.dart';
class SplashPage extends StatefulWidget { class SplashPage extends StatefulWidget {
SplashPage({Key? key}) : super(key: key); SplashPage({Key? key}) : super(key: key);
@ -34,30 +30,6 @@ class _SplashPageState extends State<SplashPage> {
TapGestureRecognizer _agreementRecognizer = TapGestureRecognizer(); TapGestureRecognizer _agreementRecognizer = TapGestureRecognizer();
TapGestureRecognizer _privacyRecognizer = TapGestureRecognizer(); TapGestureRecognizer _privacyRecognizer = TapGestureRecognizer();
///
Future _originOp() async {
//HiveStore
await Hive.initFlutter();
await HiveStore.init();
}
Future _initOp() async {
//ensure call _originOp first.
try {
final userProvider = Provider.of<UserProvider>(context, listen: false);
final appProvider = Provider.of<AppProvider>(context, listen: false);
appProvider.initApplications();
appProvider.startLocation();
// await AmapCore.init('84041703f7ecb242685325796897eff4');
if (HiveStore.appBox!.get('login') ?? false) {
////
await userProvider.setLogin(HiveStore.appBox!.get('token'));
}
} catch (e) {
LoggerData.addData(e);
}
}
Future<bool?> _showLoginVerify() async { Future<bool?> _showLoginVerify() async {
return await showCupertinoDialog( return await showCupertinoDialog(
barrierDismissible: false, barrierDismissible: false,
@ -117,7 +89,9 @@ class _SplashPageState extends State<SplashPage> {
); );
Future.delayed(Duration(milliseconds: 0), () async { Future.delayed(Duration(milliseconds: 0), () async {
await _originOp(); //
await Hive.initFlutter();
await HiveStore.init();
var agreement = await HiveStore.appBox?.get('agreement') ?? false; var agreement = await HiveStore.appBox?.get('agreement') ?? false;
if (!agreement) { if (!agreement) {
var result = await _showLoginVerify(); var result = await _showLoginVerify();
@ -133,14 +107,28 @@ class _SplashPageState extends State<SplashPage> {
if (Platform.isAndroid || Platform.isIOS) { if (Platform.isAndroid || Platform.isIOS) {
await Permission.locationWhenInUse.request(); await Permission.locationWhenInUse.request();
} }
await _initOp(); //
UserTool.dataProvider.init();
AMapFlutterLocation.updatePrivacyShow(true, true); AMapFlutterLocation.updatePrivacyShow(true, true);
AMapFlutterLocation.updatePrivacyAgree(true); AMapFlutterLocation.updatePrivacyAgree(true);
MainInitialize.initTheme(); MainInitialize.initTheme();
MainInitialize.initWechat(); MainInitialize.initWechat();
MainInitialize.initWebSocket(); MainInitialize.initWebSocket();
Get.offAll(() => TabNavigator()); UserTool.appProveider.startLocation();
UserTool.appProveider.initApplications();
//
await UserTool.dataProvider.init();
//
try {
// await AmapCore.init('84041703f7ecb242685325796897eff4');
if (HiveStore.appBox!.get('login') ?? false) {
////
UserTool.userProvider.setLogin(HiveStore.appBox!.get('token'));
} else {
await Get.offAll(() => LoginPage());
}
} catch (e) {
LoggerData.addData(e);
}
}); });
} }

@ -200,8 +200,8 @@ class AppProvider extends ChangeNotifier {
_messageCenterModel ?? MessageCenterModel.zero(); _messageCenterModel ?? MessageCenterModel.zero();
getMessageCenter() async { getMessageCenter() async {
Response response = await NetUtil().dio!.get(API.message.center); // Response response = await NetUtil().dio!.get(API.message.center);
_messageCenterModel = MessageCenterModel.fromJson(response.data); // _messageCenterModel = MessageCenterModel.fromJson(response.data);
notifyListeners(); notifyListeners();
} }
@ -311,7 +311,7 @@ class AppProvider extends ChangeNotifier {
/// ///
Future getMyAddress() async { Future getMyAddress() async {
BaseModel model = await NetUtil().get(SARSAPI.market.address.myAddress); BaseModel model = await NetUtil().get(SARSAPI.market.address.myAddress);
if (model.data!.length == 0) if (model.data?.length == 0)
return []; return [];
else { else {
_addressModels = _addressModels =

@ -7,7 +7,6 @@ import 'package:aku_new_community/models/user/user_config_model.dart';
import 'package:aku_new_community/models/user/user_info_model.dart'; import 'package:aku_new_community/models/user/user_info_model.dart';
import 'package:aku_new_community/pages/sign/sign_func.dart'; import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/provider/app_provider.dart';
import 'package:aku_new_community/ui/profile/house/house_func.dart';
import 'package:aku_new_community/utils/hive_store.dart'; import 'package:aku_new_community/utils/hive_store.dart';
import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/utils/network/net_util.dart';
@ -26,13 +25,11 @@ class UserProvider extends ChangeNotifier {
bool get isNotLogin => !_isLogin; bool get isNotLogin => !_isLogin;
Future setLogin(int token) async { Future init() async {
final appProvider = Provider.of<AppProvider>(Get.context!, listen: false); if (isLogin) {
_isLogin = true;
NetUtil().dio!.options.headers['app-login-token'] = token;
HiveStore.appBox!.put('token', token);
HiveStore.appBox!.put('login', true);
await updateUserInfo(); await updateUserInfo();
WebSocketUtil().setUser(userInfoModel!.id.toString());
WebSocketUtil().startWebSocket();
/// ///
_userConfig = await HiveStore.userBox!.get('${_userInfoModel!.id}') ?? _userConfig = await HiveStore.userBox!.get('${_userInfoModel!.id}') ??
@ -40,11 +37,16 @@ class UserProvider extends ChangeNotifier {
userId: _userInfoModel!.id, userId: _userInfoModel!.id,
clockRemind: false, clockRemind: false,
todayClocked: false); todayClocked: false);
await appProvider.updateHouses(await HouseFunc.passedHouses);
if (isLogin) {
WebSocketUtil().setUser(userInfoModel!.id.toString());
WebSocketUtil().startWebSocket();
} }
}
Future setLogin(int token) async {
final appProvider = Provider.of<AppProvider>(Get.context!, listen: false);
_isLogin = true;
NetUtil().dio!.options.headers['app-login-token'] = token;
HiveStore.appBox!.put('token', token);
HiveStore.appBox!.put('login', true);
await init();
notifyListeners(); notifyListeners();
} }
@ -64,18 +66,15 @@ class UserProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<bool> updateUserInfo() async { ///
Future updateUserInfo() async {
_userInfoModel = await SignFunc.getUserInfo(); _userInfoModel = await SignFunc.getUserInfo();
if (_userInfoModel == null) { if (_userInfoModel == null) {
BotToast.showText(text: '获取用户信息失败'); BotToast.showText(text: '获取用户信息失败');
return false;
} }
if (_userInfoModel != null && !kIsWeb && !Platform.isMacOS) {} if (_userInfoModel != null && !kIsWeb && !Platform.isMacOS) {}
SignFunc.checkNameAndAccount();
await SignFunc.checkNameAndAccount();
notifyListeners(); notifyListeners();
return true;
} }
Future updateMyHouseInfo() async { Future updateMyHouseInfo() async {

@ -24,12 +24,12 @@ class HiveStore {
if (!kIsWeb) { if (!kIsWeb) {
var dir = await getApplicationDocumentsDirectory(); var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path); Hive.init(dir.path);
Hive.registerAdapter(ProvinceModelAdapter()); Hive.registerAdapter(ProvinceModelAdapter()); //HiveTypeId:0
Hive.registerAdapter(CityAdapter()); Hive.registerAdapter(CityAdapter()); //HiveTypeId:1
Hive.registerAdapter(DistrictAdapter()); Hive.registerAdapter(DistrictAdapter()); //HiveTypeId:2
Hive.registerAdapter(ChinaRegionModelAdapter()); Hive.registerAdapter(ChinaRegionModelAdapter()); //HiveTypeId:3
Hive.registerAdapter(HistoryLoginModelAdapter()); Hive.registerAdapter(HistoryLoginModelAdapter()); //HiveTypeId:4
Hive.registerAdapter(UserConfigModelAdapter()); Hive.registerAdapter(UserConfigModelAdapter()); //HiveTypeId:5
_appBox = await Hive.openBox('app'); _appBox = await Hive.openBox('app');
_userBox = await Hive.openBox('userBox'); _userBox = await Hive.openBox('userBox');
_dataBox = await Hive.openBox('dataBox'); _dataBox = await Hive.openBox('dataBox');

@ -1,20 +1,18 @@
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response, FormData, MultipartFile;
import 'package:power_logger/power_logger.dart';
import 'package:provider/provider.dart';
import 'package:aku_new_community/constants/api.dart';
import 'package:aku_new_community/constants/sars_api.dart'; import 'package:aku_new_community/constants/sars_api.dart';
import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/pages/sign/login/login_page.dart';
import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/developer_util.dart';
import 'package:aku_new_community/utils/network/base_list_model.dart'; import 'package:aku_new_community/utils/network/base_list_model.dart';
import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response, FormData, MultipartFile;
import 'package:power_logger/power_logger.dart';
import 'package:provider/provider.dart';
class NetUtil { class NetUtil {
Dio? _dio; Dio? _dio;
@ -204,14 +202,12 @@ class NetUtil {
_parseRequestError(BaseModel model, {bool showMessage = false}) { _parseRequestError(BaseModel model, {bool showMessage = false}) {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false); final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
if (!model.success && if (!model.success && (model.code == 10010 || model.msg == '登录失效,请重新登录')) {
(model.code == 10010 || model.msg == '登录失效,请重新登录') &&
userProvider.isLogin) {
userProvider.logout(); userProvider.logout();
Get.offAll(() => LoginPage()); Get.offAll(() => LoginPage());
} if (userProvider.isLogin) {
if (!model.success && showMessage) {
BotToast.showText(text: model.msg); BotToast.showText(text: model.msg);
} }
} }
}
} }

Loading…
Cancel
Save