Verify phone number

This commit is contained in:
Hillel Coren 2022-07-27 12:22:43 +03:00
parent b246ca2d48
commit c82871838a
2 changed files with 18 additions and 8 deletions

View File

@ -9,7 +9,6 @@ import 'package:flutter/material.dart';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:flutter_styled_toast/flutter_styled_toast.dart';
import 'package:invoiceninja_flutter/main_app.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -745,6 +744,7 @@ class __SmsVerificationState extends State<_SmsVerification> {
final state = widget.state; final state = widget.state;
final credentials = widget.state.credentials; final credentials = widget.state.credentials;
final url = '${credentials.url}/verify'; final url = '${credentials.url}/verify';
final navigator = Navigator.of(context);
setState(() { setState(() {
_isLoading = true; _isLoading = true;
@ -754,9 +754,6 @@ class __SmsVerificationState extends State<_SmsVerification> {
.post(url, credentials.token, .post(url, credentials.token,
data: json.encode({'phone': state.user.phone})) data: json.encode({'phone': state.user.phone}))
.then((dynamic data) { .then((dynamic data) {
print('## VERIFY Response: $data');
showMessageDialog(
context: navigatorKey.currentContext, message: 'Response: $data');
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
@ -764,7 +761,9 @@ class __SmsVerificationState extends State<_SmsVerification> {
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
Navigator.of(context).pop(); if (navigator.canPop()) {
navigator.pop();
}
showErrorDialog(context: context, message: error); showErrorDialog(context: context, message: error);
}); });
} }
@ -780,8 +779,11 @@ class __SmsVerificationState extends State<_SmsVerification> {
return; return;
} }
final store = StoreProvider.of<AppState>(context);
final localization = AppLocalization.of(context);
final credentials = widget.state.credentials; final credentials = widget.state.credentials;
final url = '${credentials.url}/verify/confirm'; final url = '${credentials.url}/verify/confirm';
final navigator = Navigator.of(context);
setState(() { setState(() {
_isLoading = true; _isLoading = true;
@ -790,12 +792,14 @@ class __SmsVerificationState extends State<_SmsVerification> {
_webClient _webClient
.post(url, credentials.token, data: json.encode({'code': _code})) .post(url, credentials.token, data: json.encode({'code': _code}))
.then((dynamic data) { .then((dynamic data) {
print('## CONFIRM Response: $data');
showMessageDialog(
context: navigatorKey.currentContext, message: 'Response: $data');
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
if (navigator.canPop()) {
navigator.pop();
}
showToast(localization.verifiedPhoneNumber);
store.dispatch(RefreshData());
}).catchError((dynamic error) { }).catchError((dynamic error) {
setState(() { setState(() {
_isLoading = false; _isLoading = false;
@ -831,6 +835,7 @@ class __SmsVerificationState extends State<_SmsVerification> {
label: localization.code, label: localization.code,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
autovalidate: _autoValidate, autovalidate: _autoValidate,
onChanged: (value) => _code = value,
validator: (value) => validator: (value) =>
value.isEmpty ? localization.pleaseEnterACode : null, value.isEmpty ? localization.pleaseEnterACode : null,
), ),

View File

@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = { static final Map<String, Map<String, String>> _localizedValues = {
'en': { 'en': {
// STARTER: lang key - do not remove comment // STARTER: lang key - do not remove comment
'verified_phone_number': 'Successfully verified phone number',
'code_was_sent': 'A code has been sent via SMS', 'code_was_sent': 'A code has been sent via SMS',
'resend': 'Resend', 'resend': 'Resend',
'verify': 'Verify', 'verify': 'Verify',
@ -85246,6 +85247,10 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['bulk_email_purchase_orders'] ?? _localizedValues[localeCode]['bulk_email_purchase_orders'] ??
_localizedValues['en']['bulk_email_purchase_orders']; _localizedValues['en']['bulk_email_purchase_orders'];
String get verifiedPhoneNumber =>
_localizedValues[localeCode]['verified_phone_number'] ??
_localizedValues['en']['verified_phone_number'];
// STARTER: lang field - do not remove comment // STARTER: lang field - do not remove comment
String lookup(String key) { String lookup(String key) {