diff --git a/lib/pages/drawer/drawer_page.dart b/lib/pages/drawer/drawer_page.dart index 1291e41..f0f2922 100644 --- a/lib/pages/drawer/drawer_page.dart +++ b/lib/pages/drawer/drawer_page.dart @@ -4,6 +4,7 @@ import 'package:get/get.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; +import 'package:rogapp/services/auth_service.dart'; import 'package:url_launcher/url_launcher.dart'; class DrawerPage extends StatelessWidget { @@ -76,7 +77,22 @@ class DrawerPage extends StatelessWidget { }, ) : Container(width: 0, height: 0,), - + indexController.currentUser.length > 0 ? + ListTile( + leading: const Icon(Icons.delete_forever), + title: Text("delete_account".tr), + onTap: (){ + String _token = indexController.currentUser[0]['token']; + AuthService.deleteUser(_token).then((value){ + if(value.isNotEmpty){ + indexController.logout(); + Get.toNamed(AppPages.TRAVEL); + Get.snackbar("accounted_deleted".tr, "account_deleted_message".tr); + } + }); + }, + ) : + Container(width: 0, height: 0,), // ListTile( // leading: const Icon(Icons.person), // title: Text("profile".tr), diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index 4f851c6..96d04db 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -77,6 +77,25 @@ class AuthService{ return cats; } + static Future> deleteUser(String token) async { + Map cats = {}; + String server_url = ConstValues.currentServer(); + String url = '${server_url}/api/delete-account/'; + //String url = 'http://localhost:8100/api/register/'; + final http.Response response = await http.get( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Token ${token}' + } + ); + + if (response.statusCode == 200) { + cats = json.decode(utf8.decode(response.bodyBytes)); + } + return cats; + } + static Future?> UserDetails(int userid) async { List cats = []; diff --git a/lib/utils/string_values.dart b/lib/utils/string_values.dart index 85fbe57..d2acdca 100644 --- a/lib/utils/string_values.dart +++ b/lib/utils/string_values.dart @@ -67,7 +67,10 @@ class StringValues extends Translations{ "Not started yet":"Not started yet", "You have not started rogaining yet.":"You have not started rogaining yet.", "Not reached the goal yet": "Not reached the goal yet", - "You have not reached the goal yet.":"You have not reached the goal yet." + "You have not reached the goal yet.":"You have not reached the goal yet.", + "delete_account": "Delete account", + "accounted_deleted": "Account deleted", + "account_deleted_message": "your account has beed successfully deleted" }, 'ja_JP': { 'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます', @@ -135,7 +138,10 @@ class StringValues extends Translations{ "Not started yet":"まだ開始されていません", "You have not started rogaining yet.":"あなたはまだロゲイニングを始めていません。", "Not reached the goal yet": "まだ目標に達していない", - "You have not reached the goal yet.":"あなたはまだゴールに達していません。" + "You have not reached the goal yet.":"あなたはまだゴールに達していません。", + "delete_account": "アカウントを削除する", + "accounted_deleted": "アカウントが削除されました", + "account_deleted_message": "あなたのアカウントは正常に削除されました" }, }; } \ No newline at end of file