unified code verification service
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:pshared/api/requests/verification/resend.dart';
|
||||
import 'package:pshared/service/device_id.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
@@ -59,7 +60,7 @@ class AccountService {
|
||||
|
||||
static Future<void> resendVerificationEmail(String email) async {
|
||||
_logger.fine('Resending verification email');
|
||||
await getPUTResponse(_objectType, 'email', {'login': email});
|
||||
await getPUTResponse(_objectType, 'email', ResendVerificationEmailRequest.build(login: email).toJson());
|
||||
}
|
||||
|
||||
static Future<void> verifyEmail(String token) async {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class Services {
|
||||
static const String account = 'accounts';
|
||||
static const String authorization = 'authorization';
|
||||
static const String confirmations = 'confirmations';
|
||||
static const String device = 'device';
|
||||
static const String invitations = 'invitations';
|
||||
static const String organization = 'organizations';
|
||||
@@ -9,6 +8,7 @@ class Services {
|
||||
static const String storage = 'storage';
|
||||
static const String chainWallets = 'chain_wallets';
|
||||
static const String ledger = 'ledger_accounts';
|
||||
static const String verification = 'verification';
|
||||
|
||||
static const String recipients = 'recipients';
|
||||
static const String paymentMethods = 'payment_methods';
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:pshared/api/requests/confirmations/login_confirmation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'package:pshared/api/requests/verification/login.dart';
|
||||
import 'package:pshared/api/responses/login.dart';
|
||||
import 'package:pshared/api/responses/verification/response.dart';
|
||||
import 'package:pshared/data/mapper/account/account.dart';
|
||||
import 'package:pshared/data/mapper/session_identifier.dart';
|
||||
import 'package:pshared/models/account/account.dart';
|
||||
import 'package:pshared/data/mapper/account/account.dart';
|
||||
import 'package:pshared/api/responses/confirmation.dart';
|
||||
import 'package:pshared/models/auth/pending_login.dart';
|
||||
import 'package:pshared/service/authorization/storage.dart';
|
||||
import 'package:pshared/service/services.dart';
|
||||
@@ -14,43 +16,50 @@ import 'package:pshared/utils/http/requests.dart';
|
||||
|
||||
class VerificationService {
|
||||
static final _logger = Logger('service.verification');
|
||||
static const String _objectType = Services.confirmations;
|
||||
static const String _objectType = Services.verification;
|
||||
|
||||
static Future<ConfirmationResponse> requestLoginCode(PendingLogin pending, {String? destination}) async {
|
||||
static Future<VerificationResponse> requestLoginCode(PendingLogin pending, {String? target}) async {
|
||||
_logger.fine('Requesting login confirmation code');
|
||||
final response = await getPOSTResponse(
|
||||
_objectType,
|
||||
'',
|
||||
LoginConfirmationRequest(destination: destination).toJson(),
|
||||
LoginVerificationRequest(
|
||||
target: target,
|
||||
idempotencyKey: Uuid().v4(),
|
||||
).toJson(),
|
||||
authToken: pending.pendingToken.token,
|
||||
);
|
||||
return ConfirmationResponse.fromJson(response);
|
||||
return VerificationResponse.fromJson(response);
|
||||
}
|
||||
|
||||
static Future<ConfirmationResponse> resendLoginCode(PendingLogin pending, {String? destination}) async {
|
||||
static Future<VerificationResponse> resendLoginCode(PendingLogin pending, {String? destination}) async {
|
||||
_logger.fine('Resending login confirmation code');
|
||||
final response = await getPOSTResponse(
|
||||
_objectType,
|
||||
'/resend',
|
||||
LoginConfirmationRequest(destination: destination).toJson(),
|
||||
LoginVerificationRequest(
|
||||
target: destination,
|
||||
idempotencyKey: pending.idempotencyKey ?? Uuid().v4(),
|
||||
).toJson(),
|
||||
authToken: pending.pendingToken.token,
|
||||
);
|
||||
return ConfirmationResponse.fromJson(response);
|
||||
return VerificationResponse.fromJson(response);
|
||||
}
|
||||
|
||||
static Future<Account> confirmLoginCode({
|
||||
required PendingLogin pending,
|
||||
required String code,
|
||||
String? destination,
|
||||
String? target,
|
||||
}) async {
|
||||
_logger.fine('Confirming login code');
|
||||
final response = await getPOSTResponse(
|
||||
_objectType,
|
||||
'/verify',
|
||||
LoginConfirmationVerifyRequest(
|
||||
LoginCodeVerifyicationRequest(
|
||||
code: code,
|
||||
destination: destination,
|
||||
target: target,
|
||||
sessionIdentifier: pending.session.toDTO(),
|
||||
idempotencyKey: pending.idempotencyKey ?? Uuid().v4(),
|
||||
).toJson(),
|
||||
authToken: pending.pendingToken.token,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user