Skip to content

Commit

Permalink
add login with phone number on iPad (MixinNetwork#556)
Browse files Browse the repository at this point in the history
* add landing mobile

* add country selection

* add login

* improve country selection.

* improve text field color.

* add user agent and device id.

* add error handler

* improve login error handle

* expand get code button click area

* support captcha

* format code
  • Loading branch information
boyan01 authored Mar 16, 2022
1 parent 79004e9 commit 322ee88
Show file tree
Hide file tree
Showing 28 changed files with 2,812 additions and 349 deletions.
44 changes: 44 additions & 0 deletions assets/captcha.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript">

var postToken = function (response) {
MixinContextTokenCallback.postMessage(response);
}

var postMessage = function (value) {
MixinContextErrorCallback.postMessage(value);
}

var renderCallback = {
'sitekey': '#apiKey',
'callback': postToken,
'expired-callback': postMessage,
'error-callback': postMessage,
'size': 'invisible'
}

var onGCaptchaLoad = function () {
grecaptcha.render('html_element', window.renderCallback);
grecaptcha.execute();
}

var onHCaptchaLoad = function () {
var widgetID = hcaptcha.render('html_element', window.renderCallback);
hcaptcha.execute(widgetID);
}

</script>
</head>

<body>
<form action="?" method="POST" style="hidden">
<div id="html_element"></div>
</form>
<script src="#src" async defer>
</script>
</body>

</html>
24 changes: 24 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ PODS:
- Flutter
- image_picker (0.0.1):
- Flutter
- libphonenumber (0.0.1):
- Flutter
- libPhoneNumber-iOS
- libPhoneNumber-iOS (0.9.15)
- libphonenumber_plugin (0.0.1):
- Flutter
- libphonenumber
- libPhoneNumber-iOS
- ogg_opus_player (0.0.1):
- Flutter
- open_file (0.0.1):
Expand Down Expand Up @@ -80,6 +88,8 @@ PODS:
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
- webview_flutter_wkwebview (0.0.1):
- Flutter

DEPENDENCIES:
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
Expand All @@ -89,6 +99,8 @@ DEPENDENCIES:
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- gallery_saver (from `.symlinks/plugins/gallery_saver/ios`)
- image_picker (from `.symlinks/plugins/image_picker/ios`)
- libphonenumber (from `.symlinks/plugins/libphonenumber/ios`)
- libphonenumber_plugin (from `.symlinks/plugins/libphonenumber_plugin/ios`)
- ogg_opus_player (from `.symlinks/plugins/ogg_opus_player/ios`)
- open_file (from `.symlinks/plugins/open_file/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand All @@ -97,11 +109,13 @@ DEPENDENCIES:
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)
- system_clock (from `.symlinks/plugins/system_clock/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)

SPEC REPOS:
trunk:
- DKImagePickerController
- DKPhotoGallery
- libPhoneNumber-iOS
- SDWebImage
- sqlite3
- SwiftyGif
Expand All @@ -121,6 +135,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/gallery_saver/ios"
image_picker:
:path: ".symlinks/plugins/image_picker/ios"
libphonenumber:
:path: ".symlinks/plugins/libphonenumber/ios"
libphonenumber_plugin:
:path: ".symlinks/plugins/libphonenumber_plugin/ios"
ogg_opus_player:
:path: ".symlinks/plugins/ogg_opus_player/ios"
open_file:
Expand All @@ -137,6 +155,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/system_clock/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
webview_flutter_wkwebview:
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"

SPEC CHECKSUMS:
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Expand All @@ -148,6 +168,9 @@ SPEC CHECKSUMS:
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
gallery_saver: 9fc173c9f4fcc48af53b2a9ebea1b643255be542
image_picker: 541dcbb3b9cf32d87eacbd957845d8651d6c62c3
libphonenumber: bd14d5abfc5939ab0b0767234e2d8e2593af258e
libPhoneNumber-iOS: 0a32a9525cf8744fe02c5206eb30d571e38f7d75
libphonenumber_plugin: 7cf755ad1656145935d6c208173a476bd3f12898
ogg_opus_player: 0e883df8c4f70995c3e6b8ac3a8ef088f66a8f41
open_file: 02eb5cb6b21264bd3a696876f5afbfb7ca4f4b7d
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
Expand All @@ -159,6 +182,7 @@ SPEC CHECKSUMS:
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780
system_clock: 3efb51d18e565092e2a97bc605c6255f328bd13a
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
webview_flutter_wkwebview: 005fbd90c888a42c5690919a1527ecc6649e1162

PODFILE CHECKSUM: c7cf6cd0af5391000f485bb7f6561b845e054d60

Expand Down
31 changes: 2 additions & 29 deletions lib/blaze/blaze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import '../db/extension/job.dart';
import '../db/mixin_database.dart';
import '../utils/extension/extension.dart';
import '../utils/logger.dart';
import '../utils/system/package_info.dart';
import '../workers/message_worker_isolate.dart';
import 'blaze_message.dart';
import 'blaze_message_param_session.dart';
Expand Down Expand Up @@ -89,7 +90,7 @@ class Blaze {
_token ??= signAuthTokenWithEdDSA(
userId, sessionId, privateKey, scp, 'GET', '/', '');
i('ws _token?.isNotEmpty == true: ${_token?.isNotEmpty == true}');
_userAgent ??= await _getUserAgent();
_userAgent ??= await generateUserAgent(packageInfo);
i('ws _userAgent: $_userAgent');
_connect(_token!);
_checkTimeoutTimer = Timer(const Duration(seconds: 10), () {
Expand Down Expand Up @@ -331,34 +332,6 @@ class Blaze {
}
}

Future<String> _getUserAgent() async {
String? systemAndVersion;
if (Platform.isMacOS) {
try {
final result = await Process.run('sw_vers', []);
if (result.stdout != null) {
final stdout = result.stdout as String;
final map = Map.fromEntries(const LineSplitter()
.convert(stdout)
.map((e) => e.split(':'))
.where((element) => element.length >= 2)
.map((e) => MapEntry(e[0].trim(), e[1].trim())));
// example
// ProductName: macOS
// ProductVersion: 12.0.1
// BuildVersion: 21A559
systemAndVersion =
'${map['ProductName']} ${map['ProductVersion']}(${map['BuildVersion']})';
}
} catch (e) {
w('ws mac get user agent error: $e');
}
}
systemAndVersion ??=
'${Platform.operatingSystem}(${Platform.operatingSystemVersion})';
return 'Mixin/${packageInfo.version} (Flutter $systemAndVersion; ${Platform.localeName})';
}

void dispose() {
_disconnect();
_connectedStateBehaviorSubject.close();
Expand Down
2 changes: 2 additions & 0 deletions lib/constants/resources.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/crypto/signal/identity_key_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import '../crypto_key_value.dart';
import 'signal_database.dart';
import 'signal_vo_extension.dart';

Future<void> generateIdentityKeyPair(
Future<void> generateSignalDatabaseIdentityKeyPair(
SignalDatabase db,
List<int> privateKey,
List<int>? privateKey,
) async {
final registrationId = generateRegistrationId(false);
CryptoKeyValue.instance.localRegistrationId = registrationId;
final identityKeyPair = generateIdentityKeyPairFromPrivate(privateKey);
final identityKeyPair = privateKey == null
? generateIdentityKeyPair()
: generateIdentityKeyPairFromPrivate(privateKey);
final identity = IdentitiesCompanion.insert(
address: '-1',
registrationId: Value(registrationId),
Expand Down
5 changes: 2 additions & 3 deletions lib/crypto/signal/signal_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:convert';
import 'package:drift/drift.dart';
import 'package:libsignal_protocol_dart/libsignal_protocol_dart.dart'
hide generateIdentityKeyPair;

// ignore: implementation_imports
import 'package:libsignal_protocol_dart/src/invalid_message_exception.dart';
import 'package:uuid/uuid.dart';
Expand Down Expand Up @@ -35,8 +34,8 @@ class SignalProtocol {
late MixinSignalProtocolStore mixinSignalProtocolStore;
late MixinSenderKeyStore senderKeyStore;

static Future<void> initSignal(List<int> private) async {
await generateIdentityKeyPair(SignalDatabase.get, private);
static Future<void> initSignal(List<int>? private) async {
await generateSignalDatabaseIdentityKeyPair(SignalDatabase.get, private);
}

Future<void> init() async {
Expand Down
11 changes: 11 additions & 0 deletions lib/crypto/uuid/uuid.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:uuid/uuid.dart';

import '../../utils/extension/extension.dart';

Expand All @@ -17,3 +18,13 @@ String generateConversationId(String senderId, String recipientId) {

return '${digest.substring(0, 8)}-${digest.substring(8, 12)}-${digest.substring(12, 16)}-${digest.substring(16, 20)}-${digest.substring(20, 32)}';
}

/// Static factory to retrieve a type 3(name based) UUID based on the given
/// byte array.
/// The same as java.util.UUID.nameUUIDFromBytes.
UuidValue nameUuidFromBytes(List<int> name) {
final bytes = md5.convert(name).bytes;
bytes[6] = (bytes[6] & 0x0f) | 0x30;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
return UuidValue.fromList(bytes);
}
Loading

0 comments on commit 322ee88

Please sign in to comment.