iOS crypto target

This commit is contained in:
Ivan Murashov
2018-03-11 01:40:57 +03:00
parent cae46b60f9
commit c229ea8c9e
41 changed files with 811 additions and 192 deletions

View File

@@ -135,11 +135,7 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
}
}
// onWillPop() {
// if(returnToScanner) {
// return startScanner(context, app, helper);
// } else {
// return true;
// }
// }
@override bool isAutomaticallyImplyLeading() {
return true;
}
}

View File

@@ -59,28 +59,25 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
// Если токен активирован, то открывается экран со сканером,
// Если нет, то отправляется запрос на проверку статуса токена.
handleTap() async {
handleTap() {
print('tokenActive: $_tokenActive');
if (_tokenActive) {
new Future.delayed(const Duration(milliseconds: 200), () {
Navigator.of(context).pop();
});
Navigator.of(context).pop(true);
} else {
if (await platform.invokeMethod('isOnline')) {
String token = await helper.getToken();
getCheckTokenStatusRequest(token).then((response) {
Map parsedMap = JSON.decode(response.body);
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
setState(() {
_tokenActive = parsedMap['active'];
platform.invokeMethod('isOnline').then((isOnline) {
if (isOnline ) {
helper.getToken().then((token) {
getCheckTokenStatusRequest(token).then((response) {
setState(() {
_tokenActive = JSON.decode(response.body)['active'];
});
}).catchError((error) {
print(error.toString());
return false;
});
});
}).catchError((error) {
print(error.toString());
return false;
});
}
}
});
}
}

View File

@@ -114,7 +114,7 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).pushReplacement(route).then((b) {
Navigator.of(context).push(route).then((b) {
print('finish registration closed: $b');
});
});

View File

@@ -1,10 +1,14 @@
import 'dart:async';
import 'package:checker/base/base_screen.dart';
import 'package:checker/base/base_state.dart';
import 'package:checker/common.dart';
import 'package:checker/consts.dart';
import 'package:checker/db.dart';
import 'package:checker/network.dart';
import 'package:checker/screens/currencies.dart';
import 'package:checker/screens/languages.dart';
import 'package:checker/screens/splash.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
@@ -42,12 +46,18 @@ class SettingsState extends BaseState<SettingsScreen> {
this.returnToScanner = returnToScanner;
}
@override
void initState() {
print('init state!');
super.initState();
}
@override Widget build(BuildContext ctx) {
helper.getSettings(true).then((info) {
setState(() {
print('currency: ${info['currency']}');
print('locale: ${info['locale']}');
print('token: ${info['token']}');
// print('currency: ${info['currency']}');
// print('locale: ${info['locale']}');
// print('token: ${info['token']}');
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[2].title = StringsLocalization.logout();
@@ -152,6 +162,55 @@ class SettingsState extends BaseState<SettingsScreen> {
}
}
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
logout(BuildContext context, SqliteHelper helper) async {
String token = await helper.getToken();
VoidCallback positiveCallback = () {
if (token != null) {
getDeleteTokenRequest(token).then((response) {
helper.clear().then((result) {
while (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new SplashScreen(helper, app));
new Future.delayed(const Duration(milliseconds: 200), () {
Navigator.of(context).pushReplacement(route);
});
});
}).catchError((error) {
print(error.toString());
});
} else {
while (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
};
showYesNoDialog(context, StringsLocalization.confirmation(),
StringsLocalization.askChangeStore(), positiveCallback);
}
// Запуск диалога с двумя кнопками
showYesNoDialog(BuildContext context, String title, String content,
VoidCallback positiveCallback) {
showDialog(
context: context,
child: new AlertDialog(
title: new Text(title),
content: new Text(content),
actions: <Widget>[
new FlatButton(
child: new Text(StringsLocalization.no()),
onPressed: () {
Navigator.of(context).pop();
}),
new FlatButton(
child: new Text(StringsLocalization.yes()),
onPressed: positiveCallback)
]));
}
Widget getArrow() {
return new Container(margin: new EdgeInsets.only(left: 8.0),
child: new Image.asset(settings_arrow_png, height: 42.0));
@@ -161,12 +220,4 @@ class SettingsState extends BaseState<SettingsScreen> {
String getTitle() {
return StringsLocalization.settings();
}
// onWillPop() {
// if (returnToScanner) {
// return startScanner(context, app, helper);
// } else {
// return true;
// }
// }
}

View File

@@ -78,24 +78,23 @@ class _SplashScreenState extends BaseState<SplashScreen> {
]));
}
startRegistration(Widget screen) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(
builder: (BuildContext context) => screen, fullscreenDialog: true);
Navigator.of(context).push(route).then((token) {
_initAndStartScanner(context, app, token, helper);
});
});
}
/// Запуск следующего экрана приложения.
showNextScreen() async {
String token = await helper.getToken();
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
if (token == null) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(
builder: (BuildContext context) => new RegistrationScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
_initAndStartScanner(context, app, token, helper);
});
});
// pushRoute(context, new RegistrationScreen(helper, app));
startRegistration(new RegistrationScreen(helper, app));
} else {
if (await platform.invokeMethod('isOnline')) {
getCheckTokenStatusRequest(token).then((statusResponse) {
@@ -114,7 +113,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
int code = statusResponse.statusCode;
if (code == 404) {
helper.clear().then((result) {
pushRouteReplacement(context, new RegistrationScreen(helper, app));
startRegistration(new RegistrationScreen(helper, app));
});
} else {
Map status = JSON.decode(statusResponse.body);
@@ -146,8 +145,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
.then((response) {
if (response.statusCode == 409) {
pushRouteReplacement(
context, new FinishRegistrationScreen(helper, app));
startRegistration(new FinishRegistrationScreen(helper, app));
} else if (response.statusCode == 201) {
clearToken(response, helper);
}
@@ -161,8 +159,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
helper.clear().then((_) {
Map parsedMap = JSON.decode(response.body);
getDeleteTokenRequest(parsedMap['token']).then((_) {
Navigator.of(context).pop();
pushRouteReplacement(context, new RegistrationScreen(helper, app));
startRegistration(new RegistrationScreen(helper, app));
}).catchError((error) {
print(error.toString());
});
@@ -186,6 +183,8 @@ class _SplashScreenState extends BaseState<SplashScreen> {
userResponse.then((response) {
List<Map> users;
try {
users = JSON.decode(response.body);
} catch (error) {
@@ -203,10 +202,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
faq(helper, app, context, true);
} else if (call.method == 'settings') {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(
var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) => new SettingsScreen(helper, app, true), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
print('purchase closed: $b');
Navigator.of(context).push(route).then((_) {
_initAndStartScanner(context, app, token, helper);
});
});
@@ -246,10 +244,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
startScanner(String token, String userString, String card) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(
var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
print('purchase closed: $b');
Navigator.of(context).push(route).then((_) {
_initAndStartScanner(context, app, token, helper);
});
});
@@ -272,4 +269,4 @@ class _SplashScreenState extends BaseState<SplashScreen> {
return null;
}
}
}
}