Skip to content

Commit

Permalink
Merge pull request #13 from ecency/nt/delete-account
Browse files Browse the repository at this point in the history
add draft setting item for delete account
  • Loading branch information
feruzm authored Sep 7, 2024
2 parents d832b58 + 803344b commit 9b966ab
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 51 deletions.
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"bookmarks": "Bookmarks",
"dark_mode": "Dark Mode",
"light_mode": "Light Mode",
"delete_account": "Delete Account",
"log_out": "Log out",
"scan_tap_qr_code": "Scan/Tap QR Code",
"authorize_this_request_with_keychain_for_hive_app": "Authorize this request with 'Keychain for Hive' app.",
Expand Down Expand Up @@ -48,5 +49,6 @@
"no_threads_found": "No threads found",
"age_limit": "\u2022 Only accounts older than {} days allowed",
"interpretation_token": "\u2022 User HP based vote interpretation",
"max_choices": "\u2022 You may select upto {} choices"
"max_choices": "\u2022 You may select upto {} choices",
"the_account_doesnt_exist":"The account doesn't exists"
}
6 changes: 4 additions & 2 deletions lib/core/common/widgets/drawer/drawer_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class DrawerTile extends StatelessWidget {
this.onTap,
required this.text,
required this.icon,
this.color,
this.leftPadding, this.trailing});

final VoidCallback? onTap;
final String text;
final IconData icon;
final double? leftPadding;
final Widget? trailing;
final Color? color;

@override
Widget build(BuildContext context) {
Expand All @@ -23,8 +25,8 @@ class DrawerTile extends StatelessWidget {
padding: EdgeInsets.only(left: leftPadding ?? 0.0),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20),
leading: Icon(icon),
title: Text(text),
leading: Icon(icon, color: color,),
title: Text(text, style: TextStyle(color: color),),
trailing: trailing,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class RepositoriesGetIt extends GetItFeature {
getIt.registerFactory<UserRepository>(
() => UserRepository(apiService: getIt.call()));
getIt.registerFactory<SettingsRepository>(
() => SettingsRepository(localService: getIt.call()));
() => SettingsRepository(localService: getIt.call(),apiService: getIt.call()));
}
}
4 changes: 4 additions & 0 deletions lib/core/locales/locale_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LocaleText {
static String get bookmarks => "bookmarks".tr();
static String get darkMode => "dark_mode".tr();
static String get lightMode => "light_mode".tr();
static String get deleteAccount => "delete_account".tr();
static String get logOut => "log_out".tr();
static String get scanTapQRCode => "scan_tap_qr_code".tr();
static String get authorizeThisRequestWithKeyChainForHiveApp =>
Expand Down Expand Up @@ -62,4 +63,7 @@ class LocaleText {
static String get pollVote => "poll_vote".tr();
static String get pollVoted => "poll_voted".tr();
static String get pollRevote => "poll_revote".tr();
static String get theAccountDoesntExist => "the_account_doesnt_exist";


}
26 changes: 26 additions & 0 deletions lib/core/services/data_service/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,30 @@ class ApiService {
status: ResponseStatus.failed, errorMessage: e.toString());
}
}

Future<ActionSingleDataResponse<ReportResponse>> deleteAccount(
String accountName) async {
try {
var url = Uri.parse("https://ecency.com/private-api/request-delete");

http.Response response = await http.post(url,
body: json.encode({
"type": "content",
"data": {"account":accountName}
}));
if (response.statusCode == 200) {
return ActionSingleDataResponse<ReportResponse>(
data: ReportResponse.fromRawJson(response.body),
status: ResponseStatus.success,
isSuccess: true,
errorMessage: "");
} else {
return ActionSingleDataResponse(
status: ResponseStatus.failed, errorMessage: "Server Error");
}
} catch (e) {
return ActionSingleDataResponse(
status: ResponseStatus.failed, errorMessage: e.toString());
}
}
}
24 changes: 20 additions & 4 deletions lib/core/services/user_local_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:get_storage/get_storage.dart';
import 'package:waves/core/utilities/enum.dart';
Expand All @@ -10,12 +12,16 @@ class UserLocalService {
static const String _currentUserAccountStorageKey = 'currentUserAccount';
static const String _allUserAccountsStorageKey = 'allUserAccounts';
static const String _termsAcceptedFlagKey = 'termsAcceptedFlag';
static const String _deletedAccountsKey = 'deletedAccounts';

final FlutterSecureStorage _secureStorage;
final GetStorage _getStorage;

UserLocalService({required FlutterSecureStorage secureStorage, required final GetStorage getStorage})
: _secureStorage = secureStorage, _getStorage = getStorage;
UserLocalService(
{required FlutterSecureStorage secureStorage,
required final GetStorage getStorage})
: _secureStorage = secureStorage,
_getStorage = getStorage;

Future<void> cleanup() async {
await _secureStorage.delete(key: _currentUserAccountStorageKey);
Expand Down Expand Up @@ -84,15 +90,25 @@ class UserLocalService {
await _secureStorage.delete(key: _currentUserAccountStorageKey);
}


Future<void> writeTermsAcceptedFlag(bool status) async {
await _getStorage.write(_termsAcceptedFlagKey, status);
}

bool readTermsAcceptedFlag() {

bool? data = _getStorage.read(_termsAcceptedFlagKey);
return data ?? false;
}

List<String> readDeletedAccounts() {
String? data = _getStorage.read(_deletedAccountsKey);
if (data != null) {
return List<String>.from(json.decode(data));
}
return [];
}

Future<void> writeDeleteAccount(String accountName) async {
List<String> deletedAccounts = [...readDeletedAccounts(), accountName];
await _getStorage.write(_deletedAccountsKey, json.encode(deletedAccounts));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:async';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:waves/core/dependency_injection/dependency_injection.dart';
import 'package:waves/core/locales/locale_text.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/auth/models/hive_signer_auth_model.dart';
import 'package:waves/features/auth/models/hive_signer_helper_model.dart';
Expand All @@ -12,11 +15,17 @@ class HiveSignerController {
final StreamController<UserAuthModel?> _userStreamController =
getIt<StreamController<UserAuthModel?>>();

void onLogin(String url, {required Function(String) onSuccess}) {
void onLogin(String url,
{required Function(String) onSuccess,
required Function(String) onFailure}) {
HiveSignerHelperModel? data = extractTokenFromUrl(url);
if (data != null) {
_saveToLocal(data.username, data.token)
.then((_) => onSuccess(data.username));
if (!_userLocalRepository.isAccountDeleted(data.username)) {
_saveToLocal(data.username, data.token)
.then((_) => onSuccess(data.username));
} else {
onFailure(LocaleText.theAccountDoesntExist.tr());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class PostingAuthController extends ChangeNotifier {
}
}



bool _isKeyFromResponse(String? data) =>
data != null && data != 'true' && data != 'false' && data.isNotEmpty;

Expand Down
18 changes: 10 additions & 8 deletions lib/features/auth/presentation/view/hive_key_chain_auth_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:auto_size_text/auto_size_text.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:provider/provider.dart';
import 'package:waves/core/common/extensions/platform_navigation.dart';
import 'package:waves/core/common/extensions/ui.dart';
import 'package:waves/core/locales/locale_text.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:waves/core/utilities/constants/ui_constants.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/auth/presentation/widgets/auth_button.dart';
import 'package:waves/features/auth/presentation/widgets/auth_textfield.dart';
import 'package:waves/features/user/view/user_controller.dart';

class HiveKeyChainAuthView extends StatefulWidget {
const HiveKeyChainAuthView({super.key, required this.authType});
Expand Down Expand Up @@ -54,16 +56,14 @@ class _HiveKeyChainAuthViewState extends State<HiveKeyChainAuthView> {
const Gap(20),
if (widget.authType == AuthType.hiveKeyChain)
AuthButton(
authType: AuthType.hiveKeyChain,
onTap: () => onHiveAuthLoginTap(AuthType.hiveKeyChain),
label: "HiveKeychain"
),
authType: AuthType.hiveKeyChain,
onTap: () => onHiveAuthLoginTap(AuthType.hiveKeyChain),
label: "HiveKeychain"),
if (widget.authType == AuthType.hiveAuth)
AuthButton(
authType: AuthType.hiveAuth,
onTap: () => onHiveAuthLoginTap(AuthType.hiveAuth),
label: "HiveAuth"
),
authType: AuthType.hiveAuth,
onTap: () => onHiveAuthLoginTap(AuthType.hiveAuth),
label: "HiveAuth"),
],
),
),
Expand All @@ -76,6 +76,8 @@ class _HiveKeyChainAuthViewState extends State<HiveKeyChainAuthView> {
String accountName = accountNameController.text.trim().toLowerCase();
if (accountName.isEmpty) {
context.showSnackBar(LocaleText.pleaseEnterTheUsername.tr());
} else if (context.read<UserController>().isAccountDeleted(accountName)) {
context.showSnackBar(LocaleText.theAccountDoesntExist.tr());
} else {
if (type == AuthType.hiveKeyChain) {
context.platformPushNamed(Routes.hiveAuthTransactionView,
Expand Down
16 changes: 7 additions & 9 deletions lib/features/auth/presentation/view/hive_signer_auth_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,28 @@ class _HiveSignerAuthViewState extends State<HiveSignerAuthView> {
onProgress: (int progress) {
loadingProgress.value = progress;
},
onPageFinished: (String url) {

},
onPageFinished: (String url) {},
onHttpError: (HttpResponseError error) {},
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('https://example.com/')) {
controller.onLogin(
request.url,
onSuccess: (accountname) {
controller.onLogin(request.url, onSuccess: (accountname) {
context.showSnackBar(
LocaleText.successfullLoginMessage(accountname));
Navigator.pop(context);
Navigator.pop(context);
},
);
}, onFailure: (errorMessage) {
context.showSnackBar(errorMessage);
Navigator.pop(context);
});
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(
'https://hivesigner.com/oauth2/authorize?client_id=ecency.app&redirect_uri=https://example.com/callback/&scope=vote,comment'));
'https://hivesigner.com/oauth2/authorize?client_id=ecency.app&redirect_uri=https://example.com/callback/&scope=vote,comment'));
super.initState();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:provider/provider.dart';
import 'package:waves/core/common/extensions/ui.dart';
import 'package:waves/core/locales/locale_text.dart';
import 'package:waves/core/utilities/constants/ui_constants.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/auth/presentation/controller/posting_auth_controller.dart';
import 'package:waves/features/auth/presentation/widgets/auth_button.dart';
import 'package:waves/features/auth/presentation/widgets/auth_textfield.dart';
import 'package:waves/features/user/view/user_controller.dart';

class PostingKeyAuthView extends StatefulWidget {
const PostingKeyAuthView({super.key});
Expand Down Expand Up @@ -55,7 +57,9 @@ class _PostingKeyAuthViewState extends State<PostingKeyAuthView> {
textEditingController: postingKeyController),
const Gap(20),
AuthButton(
authType: AuthType.postingKey, onTap: onPostingLoginTap, label: "Login"),
authType: AuthType.postingKey,
onTap: onPostingLoginTap,
label: "Login"),
],
),
),
Expand All @@ -68,6 +72,8 @@ class _PostingKeyAuthViewState extends State<PostingKeyAuthView> {
String accountName = accountNameController.text.trim().toLowerCase();
if (accountName.isEmpty) {
context.showSnackBar(LocaleText.pleaseEnterTheUsername.tr());
} else if (context.read<UserController>().isAccountDeleted(accountName)) {
context.showSnackBar(LocaleText.theAccountDoesntExist.tr());
} else if (postingKeyController.text.trim().isEmpty) {
context.showSnackBar(LocaleText.pleaseEnterThePostingKey.tr());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'package:waves/core/dependency_injection/dependency_injection.dart';
import 'package:waves/core/models/action_response.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/settings/repository/settings_repository.dart';
import 'package:waves/features/threads/models/thread_feeds/reported/report_reponse.dart';
import 'package:waves/features/user/repository/user_local_repository.dart';

class SettingsController {
final SettingsRepository _repository = getIt<SettingsRepository>();
final UserLocalRepository _userLocalRepository = getIt<UserLocalRepository>();

ThreadFeedType readThreadType() {
return _repository.readDefaultThread();
Expand All @@ -12,4 +16,14 @@ class SettingsController {
void saveThreadType(ThreadFeedType type) async {
await _repository.writeDefaultThread(type);
}

Future<ActionSingleDataResponse<ReportResponse>> deleteAccount(
String accountName) async {
ActionSingleDataResponse<ReportResponse> response =
await _repository.deleteAccount(accountName);
if (response.isSuccess) {
await _userLocalRepository.writeDeleteAccount(accountName);
}
return response;
}
}
Loading

0 comments on commit 9b966ab

Please sign in to comment.