Browse Source

fix when PIN is empty

pull/18/head
Sun 4 years ago
parent
commit
2a2faf0ac4
  1. 4
      lib/pages/account_generate.dart
  2. 4
      lib/pages/account_quick.dart
  3. 4
      lib/pages/account_restore.dart
  4. 18
      lib/security.dart
  5. 1
      lib/utils/device_info.dart
  6. 4
      lib/widgets/shadow_dialog.dart
  7. 4
      lib/widgets/show_pin.dart
  8. 2
      macos/Flutter/GeneratedPluginRegistrant.swift
  9. 44
      pubspec.lock
  10. 1
      pubspec.yaml
  11. 7
      src/group.rs
  12. 27
      src/rpc.rs
  13. 8
      src/utils/device_status.rs

4
lib/pages/account_generate.dart

@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; @@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:esse/l10n/localizations.dart';
import 'package:esse/utils/device_info.dart';
import 'package:esse/widgets/button_text.dart';
import 'package:esse/widgets/shadow_dialog.dart';
import 'package:esse/widgets/show_pin.dart';
@ -83,7 +82,6 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> { @@ -83,7 +82,6 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> {
final mnemonic = _mnemoicWords;
final name = _nameController.text;
final avatar = _imageBytes != null ? base64.encode(_imageBytes!) : "";
final info = await deviceInfo();
if (!_registerChecked) {
return;
@ -99,7 +97,7 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> { @@ -99,7 +97,7 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> {
// send to core node service by rpc.
final res = await httpPost(Global.httpRpc,
'account-create', [
_selectedLang.toInt(), mnemonic, "", name, lock, avatar, info[0], info[1]
_selectedLang.toInt(), mnemonic, "", name, lock, avatar
]);
if (res.isOk) {

4
lib/pages/account_quick.dart

@ -7,7 +7,6 @@ import 'package:flutter/material.dart'; @@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:esse/l10n/localizations.dart';
import 'package:esse/utils/device_info.dart';
import 'package:esse/widgets/button_text.dart';
import 'package:esse/widgets/shadow_dialog.dart';
import 'package:esse/widgets/show_pin.dart';
@ -132,7 +131,6 @@ class _AccountQuickPageState extends State<AccountQuickPage> { @@ -132,7 +131,6 @@ class _AccountQuickPageState extends State<AccountQuickPage> {
final String mnemonic = lang_mnemonic[1];
final name = _nameController.text;
final avatar = _imageBytes != null ? base64.encode(_imageBytes!) : "";
final info = await deviceInfo();
final lock = '';
if (!_registerChecked) {
@ -141,7 +139,7 @@ class _AccountQuickPageState extends State<AccountQuickPage> { @@ -141,7 +139,7 @@ class _AccountQuickPageState extends State<AccountQuickPage> {
// send to core node service by rpc.
final res = await httpPost(Global.httpRpc, 'account-create', [
language.toInt(), mnemonic, "", name, lock, avatar, info[0], info[1]
language.toInt(), mnemonic, "", name, lock, avatar
]);
if (res.isOk) {

4
lib/pages/account_restore.dart

@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:esse/l10n/localizations.dart';
import 'package:esse/utils/device_info.dart';
import 'package:esse/utils/better_print.dart';
import 'package:esse/widgets/button_text.dart';
import 'package:esse/widgets/shadow_dialog.dart';
@ -394,7 +393,6 @@ class _AccountRestorePageState extends State<AccountRestorePage> { @@ -394,7 +393,6 @@ class _AccountRestorePageState extends State<AccountRestorePage> {
if (addr.length < 2) {
return;
}
final info = await deviceInfo();
showShadowDialog(
context,
@ -405,7 +403,7 @@ class _AccountRestorePageState extends State<AccountRestorePage> { @@ -405,7 +403,7 @@ class _AccountRestorePageState extends State<AccountRestorePage> {
Navigator.of(context).pop();
// send to core node service by rpc.
final res = await httpPost(Global.httpRpc, 'account-restore', [
_selectedLang.toInt(), mnemonic, "", this._name, lock, addr, info[0], info[1]
_selectedLang.toInt(), mnemonic, "", this._name, lock, addr
]);
if (res.isOk) {

18
lib/security.dart

@ -12,6 +12,7 @@ import 'package:esse/pages/account_restore.dart'; @@ -12,6 +12,7 @@ import 'package:esse/pages/account_restore.dart';
import 'package:esse/pages/account_quick.dart';
import 'package:esse/utils/logined_cache.dart';
import 'package:esse/utils/better_print.dart';
import 'package:esse/utils/toast.dart';
import 'package:esse/account.dart';
import 'package:esse/global.dart';
import 'package:esse/rpc.dart';
@ -109,7 +110,7 @@ class _SecurityPageState extends State<SecurityPage> { @@ -109,7 +110,7 @@ class _SecurityPageState extends State<SecurityPage> {
loginForm(color, lang),
const SizedBox(height: 20.0),
ButtonText(text: lang.ok, enable: _accountsLoaded,
action: () => loginAction(lang.verifyPin)),
action: () => loginAction(lang.verifyPin, color, lang)),
const SizedBox(height: 20.0),
InkWell(
child: Container(width: 600.0, height: 50.0,
@ -241,11 +242,11 @@ class _SecurityPageState extends State<SecurityPage> { @@ -241,11 +242,11 @@ class _SecurityPageState extends State<SecurityPage> {
Navigator.of(context).pushNamedAndRemoveUntil("/", (Route<dynamic> route) => false);
} else {
// TODO tostor error
print(res.error);
toast(context, res.error);
}
}
void loginAction(String title) {
void loginAction(String title, color, lang) {
if (this._selectedUserLock.length == 0) {
_verifyAfter('');
} else {
@ -258,7 +259,16 @@ class _SecurityPageState extends State<SecurityPage> { @@ -258,7 +259,16 @@ class _SecurityPageState extends State<SecurityPage> {
callback: (pinWords) async {
Navigator.of(context).pop();
_verifyAfter(pinWords);
}));
}),
40.0,
InkWell(
onTap: () => _verifyAfter(''),
child: Container(
child: Icon(
Icons.arrow_forward,
color: color.primary,
)))
);
}
}

1
lib/utils/device_info.dart

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
// device_info_plus: any no-need.
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/services.dart' show PlatformException;

4
lib/widgets/shadow_dialog.dart

@ -21,7 +21,7 @@ Widget _buildMaterialDialogTransitions( @@ -21,7 +21,7 @@ Widget _buildMaterialDialogTransitions(
);
}
showShadowDialog(BuildContext context, IconData icon, String text, Widget content, [double height=40.0]) {
showShadowDialog(BuildContext context, IconData icon, String text, Widget content, [double height=40.0, Widget? right=null]) {
showGeneralDialog(
context: context,
barrierDismissible: true,
@ -51,6 +51,8 @@ showShadowDialog(BuildContext context, IconData icon, String text, Widget conten @@ -51,6 +51,8 @@ showShadowDialog(BuildContext context, IconData icon, String text, Widget conten
),
),
),
if (right != null)
Positioned(right: 0.0, child: right),
Container(
child: Row(
mainAxisSize: MainAxisSize.min,

4
lib/widgets/show_pin.dart

@ -129,7 +129,7 @@ class _PinWordsState extends State<PinWords> { @@ -129,7 +129,7 @@ class _PinWordsState extends State<PinWords> {
@override
Widget build(BuildContext context) {
final color = Theme.of(context).colorScheme;
//final lang = AppLocalizations.of(context);
final lang = AppLocalizations.of(context);
return Column(children: [
this._waiting ? CupertinoActivityIndicator(radius: 10.0, animating: true) : const SizedBox(),
@ -189,7 +189,7 @@ class _PinWordsState extends State<PinWords> { @@ -189,7 +189,7 @@ class _PinWordsState extends State<PinWords> {
size: 20.0, color: Colors.white)),
),
),
])
]),
]);
}
}

2
macos/Flutter/GeneratedPluginRegistrant.swift

@ -6,7 +6,6 @@ import FlutterMacOS @@ -6,7 +6,6 @@ import FlutterMacOS
import Foundation
import audio_session
import device_info_plus_macos
import esse_core
import file_selector_macos
import just_audio
@ -16,7 +15,6 @@ import url_launcher_macos @@ -16,7 +15,6 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
EsseCorePlugin.register(with: registry.registrar(forPlugin: "EsseCorePlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))

44
pubspec.lock

@ -121,7 +121,7 @@ packages: @@ -121,7 +121,7 @@ packages:
source: hosted
version: "0.3.2"
crypto:
dependency: "direct main"
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
@ -134,48 +134,6 @@ packages: @@ -134,48 +134,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.1"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
device_info_plus_linux:
dependency: transitive
description:
name: device_info_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
device_info_plus_macos:
dependency: transitive
description:
name: device_info_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
device_info_plus_web:
dependency: transitive
description:
name: device_info_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
device_info_plus_windows:
dependency: transitive
description:
name: device_info_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
diff_match_patch:
dependency: transitive
description:

1
pubspec.yaml

@ -47,7 +47,6 @@ dependencies: @@ -47,7 +47,6 @@ dependencies:
web_socket_channel: any
record: any
just_audio: any
device_info_plus: any
percent_indicator: any
bottom_navy_bar: any
flutter_quill: any

7
src/group.rs

@ -18,7 +18,7 @@ use crate::event::{InnerEvent, StatusEvent, SyncEvent}; @@ -18,7 +18,7 @@ use crate::event::{InnerEvent, StatusEvent, SyncEvent};
use crate::layer::Layer;
use crate::rpc;
use crate::storage::{account_db, account_init, consensus_db, write_avatar};
use crate::utils::device_status::device_status as local_device_status;
use crate::utils::device_status::{device_info, device_status as local_device_status};
pub(crate) mod running;
@ -441,8 +441,6 @@ impl Group { @@ -441,8 +441,6 @@ impl Group {
name: &str,
lock: &str,
avatar_bytes: Vec<u8>,
device_name: &str,
device_info: &str,
) -> Result<(i64, GroupId)> {
let account_index = self.accounts.len() as u32;
let (mut account, sk) = Account::generate(
@ -472,7 +470,8 @@ impl Group { @@ -472,7 +470,8 @@ impl Group {
let _ = write_avatar(&self.base, &account_id, &account_id, &account.avatar).await;
self.accounts.insert(account.gid, account);
let mut device = Device::new(device_name.to_owned(), device_info.to_owned(), self.addr);
let (device_name, device_info) = device_info();
let mut device = Device::new(device_name, device_info, self.addr);
let db = consensus_db(&self.base, &account_id)?;
device.insert(&db)?;
db.close()?;

27
src/rpc.rs

@ -266,24 +266,12 @@ fn new_rpc_handler( @@ -266,24 +266,12 @@ fn new_rpc_handler(
let lock = params[4].as_str().ok_or(RpcError::ParseError)?;
let avatar = params[5].as_str().ok_or(RpcError::ParseError)?;
let device_name = params[6].as_str().ok_or(RpcError::ParseError)?;
let device_info = params[7].as_str().ok_or(RpcError::ParseError)?;
let avatar_bytes = base64::decode(avatar).unwrap_or(vec![]);
let (id, gid) = state
.group
.write()
.await
.add_account(
lang,
seed,
pass,
name,
lock,
avatar_bytes,
device_name,
device_info,
)
.add_account(lang, seed, pass, name, lock, avatar_bytes)
.await?;
state.layer.write().await.add_running(&gid, gid, id, 0)?;
@ -308,23 +296,12 @@ fn new_rpc_handler( @@ -308,23 +296,12 @@ fn new_rpc_handler(
let some_addr =
PeerAddr::from_hex(params[5].as_str().ok_or(RpcError::ParseError)?).ok();
let device_name = params[6].as_str().ok_or(RpcError::ParseError)?;
let device_info = params[7].as_str().ok_or(RpcError::ParseError)?;
let (id, gid) = state
.group
.write()
.await
.add_account(
lang,
seed,
pass,
name,
lock,
vec![],
device_name,
device_info,
)
.add_account(lang, seed, pass, name, lock, vec![])
.await?;
state.layer.write().await.add_running(&gid, gid, id, 0)?;

8
src/utils/device_status.rs

@ -33,3 +33,11 @@ pub(crate) fn device_status() -> (u32, u32, u32, u32, u16, u16, u16, u16) { @@ -33,3 +33,11 @@ pub(crate) fn device_status() -> (u32, u32, u32, u32, u16, u16, u16, u16) {
cpu_n, memory_t, swap_t, disk_t_n, cpu_p, memory_p, swap_p, disk_p,
)
}
pub(crate) fn device_info() -> (String, String) {
let sys = System::new_all();
(
sys.name().unwrap_or("Unknown".to_owned()),
sys.host_name().unwrap_or("Unknown".to_owned()),
)
}

Loading…
Cancel
Save