fix for resend, cooldown and a few small fixes
This commit is contained in:
5
frontend/pshared/lib/models/auth/probe_result.dart
Normal file
5
frontend/pshared/lib/models/auth/probe_result.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
enum AuthProbeResult {
|
||||
authorized,
|
||||
notVerified,
|
||||
error,
|
||||
}
|
||||
@@ -7,10 +7,12 @@ import 'package:share_plus/share_plus.dart';
|
||||
import 'package:pshared/api/errors/unauthorized.dart';
|
||||
import 'package:pshared/api/requests/signup.dart';
|
||||
import 'package:pshared/api/requests/login_data.dart';
|
||||
import 'package:pshared/api/responses/error/server.dart';
|
||||
import 'package:pshared/api/responses/verification/response.dart';
|
||||
import 'package:pshared/config/constants.dart';
|
||||
import 'package:pshared/models/account/account.dart';
|
||||
import 'package:pshared/models/auth/login_outcome.dart';
|
||||
import 'package:pshared/models/auth/probe_result.dart';
|
||||
import 'package:pshared/models/auth/pending_login.dart';
|
||||
import 'package:pshared/models/auth/state.dart';
|
||||
import 'package:pshared/models/describable.dart';
|
||||
@@ -309,4 +311,31 @@ class AccountProvider extends ChangeNotifier {
|
||||
}
|
||||
await restore();
|
||||
}
|
||||
|
||||
Future<AuthProbeResult> probeAuthorization({
|
||||
required String email,
|
||||
required String password,
|
||||
required String locale,
|
||||
}) async {
|
||||
try {
|
||||
final outcome = await AccountService.login(LoginData.build(
|
||||
login: email,
|
||||
password: password,
|
||||
locale: locale,
|
||||
));
|
||||
if (outcome.isCompleted) {
|
||||
await AuthorizationService.logout();
|
||||
return AuthProbeResult.authorized;
|
||||
}
|
||||
if (outcome.isPending) {
|
||||
return AuthProbeResult.authorized;
|
||||
}
|
||||
return AuthProbeResult.error;
|
||||
} catch (e) {
|
||||
if (e is ErrorResponse && e.error == 'account_not_verified') {
|
||||
return AuthProbeResult.notVerified;
|
||||
}
|
||||
return AuthProbeResult.error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/account.dart';
|
||||
import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class EmailVerificationProvider extends ChangeNotifier {
|
||||
Resource<bool> _resource = Resource(data: null, isLoading: false);
|
||||
String? _token;
|
||||
@@ -16,6 +17,14 @@ class EmailVerificationProvider extends ChangeNotifier {
|
||||
ErrorResponse? get errorResponse =>
|
||||
_resource.error is ErrorResponse ? _resource.error as ErrorResponse : null;
|
||||
int? get errorCode => errorResponse?.code;
|
||||
bool get isTokenAlreadyUsed {
|
||||
final response = errorResponse;
|
||||
if (response == null) return false;
|
||||
if (response.code != 409 || response.error != 'data_conflict') {
|
||||
return false;
|
||||
}
|
||||
return response.details.contains('verification token has already been used');
|
||||
}
|
||||
bool get canResendVerification =>
|
||||
errorCode == 400 || errorCode == 410 || errorCode == 500;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user