ログインをメアドに変更

This commit is contained in:
2024-07-15 06:54:02 +09:00
parent ae05a8bbcd
commit 616f87c0c5
11 changed files with 140 additions and 102 deletions

View File

@ -15,6 +15,7 @@ import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/auth_service.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/widgets/debug_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../main.dart';
@ -52,6 +53,8 @@ class IndexController extends GetxController with WidgetsBindingObserver {
MapController mapController = MapController();
MapController rogMapController = MapController();
LogManager logManager = LogManager();
String? userToken;
// mode = 0 is map mode, mode = 1 list mode
@ -155,14 +158,15 @@ class IndexController extends GetxController with WidgetsBindingObserver {
return WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
title: Text('位置情報の許可が必要です'),
content: Text('設定>プライバシーとセキュリティ>位置情報サービス を開いて、岐阜ナビを探し、「位置情報の許可」を「常に」にして下さい。'),
title: Text('location_permission_needed_title'.tr),
content: Text('location_permission_needed_main'.tr),
actions: [
TextButton(
onPressed: () {
logManager.addOperationLog("User tapped confirm button for location permission required.");
Navigator.of(context).pop();
},
child: Text('OK'),
child: Text('confirm'.tr),
),
],
),
@ -230,6 +234,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
void _startLocationService() async {
const platform = MethodChannel('location');
try {
logManager.addOperationLog("Called start location service.");
await platform.invokeMethod('startLocationService');
} on PlatformException catch (e) {
print("Failed to start location service: '${e.message}'.");
@ -239,6 +244,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
void _stopLocationService() async {
const platform = MethodChannel('location');
try {
logManager.addOperationLog("Called stop location service.");
await platform.invokeMethod('stopLocationService');
} on PlatformException catch (e) {
print("Failed to stop location service: '${e.message}'.");
@ -301,24 +307,29 @@ class IndexController extends GetxController with WidgetsBindingObserver {
}
}
logManager.addOperationLog("Called boundsFromLatLngList (${x1!},${y1!})-(${x0!},${y0!}).");
return LatLngBounds(LatLng(x1!, y1!), LatLng(x0!, y0!));
}
// 要検討:エラーハンドリングが行われていますが、エラーメッセージをローカライズすることを検討してください。
//
void login(String email, String password, BuildContext context) {
AuthService.login(email, password).then((value) {
print("------- logged in user details ######## $value ###### --------");
if (value.isNotEmpty) {
logManager.addOperationLog("User logged in : ${value}.");
// Navigator.pop(context);
print("--------- user details login ----- $value");
//await Future.delayed(const Duration(milliseconds: 500)); // Added Akira:2024-4-6, #2800
changeUser(value);
} else {
logManager.addOperationLog("User failed login : ${email} , ${password}.");
isLoading.value = false;
Get.snackbar(
"ログイン失敗",
"ログインIDかパスワードを確認して下さい。",
"login_failed".tr,
"check_login_id_or_password".tr,
backgroundColor: Colors.red,
colorText: Colors.white,
icon: const Icon(Icons.error, size: 40.0, color: Colors.blue),
@ -340,6 +351,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
AuthService.changePassword(oldpassword, newpassword, token).then((value) {
////print("------- change password ######## $value ###### --------");
if (value.isNotEmpty) {
logManager.addOperationLog("User successed to change password : ${oldpassword} , ${newpassword}.");
isLoading.value = false;
Navigator.pop(context);
if (rogMode.value == 1) {
@ -348,6 +360,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
switchPage(AppPages.INDEX);
}
} else {
logManager.addOperationLog("User failed to change password : ${oldpassword} , ${newpassword}.");
Get.snackbar(
'failed'.tr,
'password_change_failed_please_try_again'.tr,
@ -383,6 +396,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
*/
void logout() async {
logManager.addOperationLog("User logout : ${currentUser} .");
saveGameState();
locations.clear();
DatabaseHelper db = DatabaseHelper.instance;
@ -403,12 +417,15 @@ class IndexController extends GetxController with WidgetsBindingObserver {
void register(String email, String password, BuildContext context) {
AuthService.register(email, password).then((value) {
if (value.isNotEmpty) {
logManager.addOperationLog("User tried to register new account : ${email} , ${password} .");
currentUser.clear();
currentUser.add(value);
isLoading.value = false;
Navigator.pop(context);
Get.toNamed(AppPages.INDEX);
} else {
logManager.addOperationLog("User failed to register new account : ${email} , ${password} .");
isLoading.value = false;
Get.snackbar(
'failed'.tr,