Skip to content

Commit

Permalink
feat: deleting academia account now works!
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Sep 19, 2024
1 parent c993784 commit fbb8ee7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ class UserController extends GetxController {
debugPrint("Error during logout: ${e.toString()}");
}
}

Future<Either<String, bool>> deleteUser() async {
final result = await service.deleteStudent(authHeaders, user.value!.id!);
return result;
}
}
24 changes: 24 additions & 0 deletions lib/models/services/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ class UserService with VerisafeService {
}
}

Future<Either<String, bool>> deleteStudent(
Map<String, String> authheaders, String userID) async {
try {
final response = await http.delete(
Uri.parse("${VerisafeService.urlPrefix}/students/delete/$userID"),
headers: authheaders,
);

if (response.statusCode == 200) {
return right(true);
}

return const Left(
"We ran into an error please retry again later!",
);
} catch (e) {
if (e is http.ClientException) {
return const Left(
"Error communicating to server please check your network and try again later");
}
return Left(e.toString());
}
}

/// Register
/// Registers a user to verisafe
Future<Either<String, User>> register(Map<String, dynamic> data) async {
Expand Down
36 changes: 35 additions & 1 deletion lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,41 @@ class _SettingsPageState extends State<SettingsPage> {
ListTile(
leading: const Icon(Ionicons.trash),
title: const Text("Delete my account"),
onTap: () {},
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Confirmation"),
content: const Text(
"Are you sure you want to delete this acount? Doing this will result to data loss and cannot be restored!",
),
actions: [
OutlinedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("Cancel"),
),
FilledButton(
onPressed: () async {
await HapticFeedback.heavyImpact();
await settingsController.logout();
await userController.deleteUser();
if (context.mounted) {
Navigator.pop(context);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const Academia(),
),
);
}
},
child: const Text("Yes delete it"),
)
],
),
);
},
),
Padding(
padding: const EdgeInsets.all(12),
Expand Down

0 comments on commit fbb8ee7

Please sign in to comment.