Skip to content

Commit 322ee88

Browse files
authored
add login with phone number on iPad (#556)
* 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
1 parent 79004e9 commit 322ee88

28 files changed

+2812
-349
lines changed

assets/captcha.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
5+
<script type="text/javascript">
6+
7+
var postToken = function (response) {
8+
MixinContextTokenCallback.postMessage(response);
9+
}
10+
11+
var postMessage = function (value) {
12+
MixinContextErrorCallback.postMessage(value);
13+
}
14+
15+
var renderCallback = {
16+
'sitekey': '#apiKey',
17+
'callback': postToken,
18+
'expired-callback': postMessage,
19+
'error-callback': postMessage,
20+
'size': 'invisible'
21+
}
22+
23+
var onGCaptchaLoad = function () {
24+
grecaptcha.render('html_element', window.renderCallback);
25+
grecaptcha.execute();
26+
}
27+
28+
var onHCaptchaLoad = function () {
29+
var widgetID = hcaptcha.render('html_element', window.renderCallback);
30+
hcaptcha.execute(widgetID);
31+
}
32+
33+
</script>
34+
</head>
35+
36+
<body>
37+
<form action="?" method="POST" style="hidden">
38+
<div id="html_element"></div>
39+
</form>
40+
<script src="#src" async defer>
41+
</script>
42+
</body>
43+
44+
</html>

ios/Podfile.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ PODS:
4444
- Flutter
4545
- image_picker (0.0.1):
4646
- Flutter
47+
- libphonenumber (0.0.1):
48+
- Flutter
49+
- libPhoneNumber-iOS
50+
- libPhoneNumber-iOS (0.9.15)
51+
- libphonenumber_plugin (0.0.1):
52+
- Flutter
53+
- libphonenumber
54+
- libPhoneNumber-iOS
4755
- ogg_opus_player (0.0.1):
4856
- Flutter
4957
- open_file (0.0.1):
@@ -80,6 +88,8 @@ PODS:
8088
- Flutter
8189
- url_launcher_ios (0.0.1):
8290
- Flutter
91+
- webview_flutter_wkwebview (0.0.1):
92+
- Flutter
8393

8494
DEPENDENCIES:
8595
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
@@ -89,6 +99,8 @@ DEPENDENCIES:
8999
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
90100
- gallery_saver (from `.symlinks/plugins/gallery_saver/ios`)
91101
- image_picker (from `.symlinks/plugins/image_picker/ios`)
102+
- libphonenumber (from `.symlinks/plugins/libphonenumber/ios`)
103+
- libphonenumber_plugin (from `.symlinks/plugins/libphonenumber_plugin/ios`)
92104
- ogg_opus_player (from `.symlinks/plugins/ogg_opus_player/ios`)
93105
- open_file (from `.symlinks/plugins/open_file/ios`)
94106
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
@@ -97,11 +109,13 @@ DEPENDENCIES:
97109
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)
98110
- system_clock (from `.symlinks/plugins/system_clock/ios`)
99111
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
112+
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)
100113

101114
SPEC REPOS:
102115
trunk:
103116
- DKImagePickerController
104117
- DKPhotoGallery
118+
- libPhoneNumber-iOS
105119
- SDWebImage
106120
- sqlite3
107121
- SwiftyGif
@@ -121,6 +135,10 @@ EXTERNAL SOURCES:
121135
:path: ".symlinks/plugins/gallery_saver/ios"
122136
image_picker:
123137
:path: ".symlinks/plugins/image_picker/ios"
138+
libphonenumber:
139+
:path: ".symlinks/plugins/libphonenumber/ios"
140+
libphonenumber_plugin:
141+
:path: ".symlinks/plugins/libphonenumber_plugin/ios"
124142
ogg_opus_player:
125143
:path: ".symlinks/plugins/ogg_opus_player/ios"
126144
open_file:
@@ -137,6 +155,8 @@ EXTERNAL SOURCES:
137155
:path: ".symlinks/plugins/system_clock/ios"
138156
url_launcher_ios:
139157
:path: ".symlinks/plugins/url_launcher_ios/ios"
158+
webview_flutter_wkwebview:
159+
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"
140160

141161
SPEC CHECKSUMS:
142162
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
@@ -148,6 +168,9 @@ SPEC CHECKSUMS:
148168
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
149169
gallery_saver: 9fc173c9f4fcc48af53b2a9ebea1b643255be542
150170
image_picker: 541dcbb3b9cf32d87eacbd957845d8651d6c62c3
171+
libphonenumber: bd14d5abfc5939ab0b0767234e2d8e2593af258e
172+
libPhoneNumber-iOS: 0a32a9525cf8744fe02c5206eb30d571e38f7d75
173+
libphonenumber_plugin: 7cf755ad1656145935d6c208173a476bd3f12898
151174
ogg_opus_player: 0e883df8c4f70995c3e6b8ac3a8ef088f66a8f41
152175
open_file: 02eb5cb6b21264bd3a696876f5afbfb7ca4f4b7d
153176
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
@@ -159,6 +182,7 @@ SPEC CHECKSUMS:
159182
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780
160183
system_clock: 3efb51d18e565092e2a97bc605c6255f328bd13a
161184
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
185+
webview_flutter_wkwebview: 005fbd90c888a42c5690919a1527ecc6649e1162
162186

163187
PODFILE CHECKSUM: c7cf6cd0af5391000f485bb7f6561b845e054d60
164188

lib/blaze/blaze.dart

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import '../db/extension/job.dart';
1616
import '../db/mixin_database.dart';
1717
import '../utils/extension/extension.dart';
1818
import '../utils/logger.dart';
19+
import '../utils/system/package_info.dart';
1920
import '../workers/message_worker_isolate.dart';
2021
import 'blaze_message.dart';
2122
import 'blaze_message_param_session.dart';
@@ -89,7 +90,7 @@ class Blaze {
8990
_token ??= signAuthTokenWithEdDSA(
9091
userId, sessionId, privateKey, scp, 'GET', '/', '');
9192
i('ws _token?.isNotEmpty == true: ${_token?.isNotEmpty == true}');
92-
_userAgent ??= await _getUserAgent();
93+
_userAgent ??= await generateUserAgent(packageInfo);
9394
i('ws _userAgent: $_userAgent');
9495
_connect(_token!);
9596
_checkTimeoutTimer = Timer(const Duration(seconds: 10), () {
@@ -331,34 +332,6 @@ class Blaze {
331332
}
332333
}
333334

334-
Future<String> _getUserAgent() async {
335-
String? systemAndVersion;
336-
if (Platform.isMacOS) {
337-
try {
338-
final result = await Process.run('sw_vers', []);
339-
if (result.stdout != null) {
340-
final stdout = result.stdout as String;
341-
final map = Map.fromEntries(const LineSplitter()
342-
.convert(stdout)
343-
.map((e) => e.split(':'))
344-
.where((element) => element.length >= 2)
345-
.map((e) => MapEntry(e[0].trim(), e[1].trim())));
346-
// example
347-
// ProductName: macOS
348-
// ProductVersion: 12.0.1
349-
// BuildVersion: 21A559
350-
systemAndVersion =
351-
'${map['ProductName']} ${map['ProductVersion']}(${map['BuildVersion']})';
352-
}
353-
} catch (e) {
354-
w('ws mac get user agent error: $e');
355-
}
356-
}
357-
systemAndVersion ??=
358-
'${Platform.operatingSystem}(${Platform.operatingSystemVersion})';
359-
return 'Mixin/${packageInfo.version} (Flutter $systemAndVersion; ${Platform.localeName})';
360-
}
361-
362335
void dispose() {
363336
_disconnect();
364337
_connectedStateBehaviorSubject.close();

lib/constants/resources.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/crypto/signal/identity_key_util.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import '../crypto_key_value.dart';
55
import 'signal_database.dart';
66
import 'signal_vo_extension.dart';
77

8-
Future<void> generateIdentityKeyPair(
8+
Future<void> generateSignalDatabaseIdentityKeyPair(
99
SignalDatabase db,
10-
List<int> privateKey,
10+
List<int>? privateKey,
1111
) async {
1212
final registrationId = generateRegistrationId(false);
1313
CryptoKeyValue.instance.localRegistrationId = registrationId;
14-
final identityKeyPair = generateIdentityKeyPairFromPrivate(privateKey);
14+
final identityKeyPair = privateKey == null
15+
? generateIdentityKeyPair()
16+
: generateIdentityKeyPairFromPrivate(privateKey);
1517
final identity = IdentitiesCompanion.insert(
1618
address: '-1',
1719
registrationId: Value(registrationId),

lib/crypto/signal/signal_protocol.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:convert';
33
import 'package:drift/drift.dart';
44
import 'package:libsignal_protocol_dart/libsignal_protocol_dart.dart'
55
hide generateIdentityKeyPair;
6-
76
// ignore: implementation_imports
87
import 'package:libsignal_protocol_dart/src/invalid_message_exception.dart';
98
import 'package:uuid/uuid.dart';
@@ -35,8 +34,8 @@ class SignalProtocol {
3534
late MixinSignalProtocolStore mixinSignalProtocolStore;
3635
late MixinSenderKeyStore senderKeyStore;
3736

38-
static Future<void> initSignal(List<int> private) async {
39-
await generateIdentityKeyPair(SignalDatabase.get, private);
37+
static Future<void> initSignal(List<int>? private) async {
38+
await generateSignalDatabaseIdentityKeyPair(SignalDatabase.get, private);
4039
}
4140

4241
Future<void> init() async {

lib/crypto/uuid/uuid.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22

33
import 'package:crypto/crypto.dart';
4+
import 'package:uuid/uuid.dart';
45

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

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

1819
return '${digest.substring(0, 8)}-${digest.substring(8, 12)}-${digest.substring(12, 16)}-${digest.substring(16, 20)}-${digest.substring(20, 32)}';
1920
}
21+
22+
/// Static factory to retrieve a type 3(name based) UUID based on the given
23+
/// byte array.
24+
/// The same as java.util.UUID.nameUUIDFromBytes.
25+
UuidValue nameUuidFromBytes(List<int> name) {
26+
final bytes = md5.convert(name).bytes;
27+
bytes[6] = (bytes[6] & 0x0f) | 0x30;
28+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
29+
return UuidValue.fromList(bytes);
30+
}

0 commit comments

Comments
 (0)