mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Add recaptcha
This commit is contained in:
parent
4d1cfa678f
commit
2da0f6fcc4
34 changed files with 2093 additions and 8 deletions
|
|
@ -42,6 +42,7 @@ import MediaEditor
|
|||
import TelegramUIDeclareEncodables
|
||||
import ContextMenuScreen
|
||||
import MetalEngine
|
||||
import RecaptchaEnterprise
|
||||
|
||||
#if canImport(AppCenter)
|
||||
import AppCenter
|
||||
|
|
@ -322,6 +323,8 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||
|
||||
private let voipDeviceToken = Promise<Data?>(nil)
|
||||
private let regularDeviceToken = Promise<Data?>(nil)
|
||||
|
||||
private var recaptchaClientsBySiteKey: [String: Promise<RecaptchaClient>] = [:]
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
precondition(!testIsLaunched)
|
||||
|
|
@ -511,7 +514,63 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||
Logger.shared.log("data", "can't deserialize")
|
||||
}
|
||||
return data
|
||||
}, externalRequestVerificationStream: self.firebaseRequestVerificationSecretStream.get(), autolockDeadine: autolockDeadine, encryptionProvider: OpenSSLEncryptionProvider(), deviceModelName: nil, useBetaFeatures: !buildConfig.isAppStoreBuild, isICloudEnabled: buildConfig.isICloudEnabled)
|
||||
}, externalRequestVerificationStream: self.firebaseRequestVerificationSecretStream.get(), externalRecaptchaRequestVerification: { method, siteKey in
|
||||
return Signal { subscriber in
|
||||
let recaptchaClient: Promise<RecaptchaClient>
|
||||
if let current = self.recaptchaClientsBySiteKey[siteKey] {
|
||||
recaptchaClient = current
|
||||
} else {
|
||||
recaptchaClient = Promise<RecaptchaClient>()
|
||||
self.recaptchaClientsBySiteKey[siteKey] = recaptchaClient
|
||||
|
||||
Recaptcha.fetchClient(withSiteKey: siteKey) { client, error in
|
||||
Queue.mainQueue().async {
|
||||
guard let client else {
|
||||
Logger.shared.log("App \(self.episodeId)", "RecaptchaClient creation error: \(String(describing: error)).")
|
||||
return
|
||||
}
|
||||
recaptchaClient.set(.single(client))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (recaptchaClient.get()
|
||||
|> take(1)
|
||||
|> mapToSignal { recaptchaClient -> Signal<String?, NoError> in
|
||||
return Signal { subscriber in
|
||||
var recaptchaAction: RecaptchaAction?
|
||||
switch method {
|
||||
case "signup":
|
||||
recaptchaAction = RecaptchaAction.signup
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
guard let recaptchaAction else {
|
||||
subscriber.putNext(nil)
|
||||
subscriber.putCompletion()
|
||||
|
||||
return EmptyDisposable
|
||||
}
|
||||
recaptchaClient.execute(withAction: recaptchaAction) { token, error in
|
||||
if let token {
|
||||
subscriber.putNext(token)
|
||||
Logger.shared.log("App \(self.episodeId)", "RecaptchaClient executed successfully")
|
||||
} else {
|
||||
subscriber.putNext(nil)
|
||||
Logger.shared.log("App \(self.episodeId)", "RecaptchaClient execute error: \(String(describing: error))")
|
||||
}
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
|
||||
return ActionDisposable {
|
||||
}
|
||||
}
|
||||
|> runOn(Queue.mainQueue())
|
||||
}).startStandalone(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||
}
|
||||
|> runOn(Queue.mainQueue())
|
||||
}, autolockDeadine: autolockDeadine, encryptionProvider: OpenSSLEncryptionProvider(), deviceModelName: nil, useBetaFeatures: !buildConfig.isAppStoreBuild, isICloudEnabled: buildConfig.isICloudEnabled)
|
||||
|
||||
guard let appGroupUrl = maybeAppGroupUrl else {
|
||||
self.mainWindow?.presentNative(UIAlertController(title: nil, message: "Error 2", preferredStyle: .alert))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue