Revert API

This commit is contained in:
Ali 2021-06-25 14:10:53 +04:00
parent 63a313b1cf
commit e6c5c163e3
9 changed files with 120 additions and 136 deletions

View File

@ -475,7 +475,7 @@ public final class TwoFactorDataInputScreen: ViewController {
} }
private func performRecovery(recovery: TwoFactorDataInputMode.Recovery, password: String, hint: String) { private func performRecovery(recovery: TwoFactorDataInputMode.Recovery, password: String, hint: String) {
let statusController = OverlayStatusController(theme: self.presentationData.theme, type: .loading(cancelled: nil)) /*let statusController = OverlayStatusController(theme: self.presentationData.theme, type: .loading(cancelled: nil))
self.present(statusController, in: .window(.root)) self.present(statusController, in: .window(.root))
let _ = (performPasswordRecovery(accountManager: self.sharedContext.accountManager, account: recovery.account, code: recovery.code, syncContacts: recovery.syncContacts, updatedPassword: password.isEmpty ? .none : .password(password: password, hint: hint, email: nil)) let _ = (performPasswordRecovery(accountManager: self.sharedContext.accountManager, account: recovery.account, code: recovery.code, syncContacts: recovery.syncContacts, updatedPassword: password.isEmpty ? .none : .password(password: password, hint: hint, email: nil))
@ -507,7 +507,7 @@ public final class TwoFactorDataInputScreen: ViewController {
} }
strongSelf.dismiss() strongSelf.dismiss()
}) })*/
} }
} }

View File

@ -26,9 +26,8 @@ private final class TwoStepVerificationUnlockSettingsControllerArguments {
let openResetPendingEmail: () -> Void let openResetPendingEmail: () -> Void
let updateEmailCode: (String) -> Void let updateEmailCode: (String) -> Void
let openConfirmEmail: () -> Void let openConfirmEmail: () -> Void
let declinePasswordReset: () -> Void
init(updatePasswordText: @escaping (String) -> Void, checkPassword: @escaping () -> Void, openForgotPassword: @escaping () -> Void, openSetupPassword: @escaping () -> Void, openDisablePassword: @escaping () -> Void, openSetupEmail: @escaping () -> Void, openResetPendingEmail: @escaping () -> Void, updateEmailCode: @escaping (String) -> Void, openConfirmEmail: @escaping () -> Void, declinePasswordReset: @escaping () -> Void) { init(updatePasswordText: @escaping (String) -> Void, checkPassword: @escaping () -> Void, openForgotPassword: @escaping () -> Void, openSetupPassword: @escaping () -> Void, openDisablePassword: @escaping () -> Void, openSetupEmail: @escaping () -> Void, openResetPendingEmail: @escaping () -> Void, updateEmailCode: @escaping (String) -> Void, openConfirmEmail: @escaping () -> Void) {
self.updatePasswordText = updatePasswordText self.updatePasswordText = updatePasswordText
self.checkPassword = checkPassword self.checkPassword = checkPassword
self.openForgotPassword = openForgotPassword self.openForgotPassword = openForgotPassword
@ -38,7 +37,6 @@ private final class TwoStepVerificationUnlockSettingsControllerArguments {
self.openResetPendingEmail = openResetPendingEmail self.openResetPendingEmail = openResetPendingEmail
self.updateEmailCode = updateEmailCode self.updateEmailCode = updateEmailCode
self.openConfirmEmail = openConfirmEmail self.openConfirmEmail = openConfirmEmail
self.declinePasswordReset = declinePasswordReset
} }
} }
@ -134,51 +132,47 @@ private enum TwoStepVerificationUnlockSettingsEntry: ItemListNodeEntry {
}, action: { }, action: {
arguments.checkPassword() arguments.checkPassword()
}) })
case let .passwordEntryInfo(_, text): case let .passwordEntryInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in
switch action { switch action {
case let .tap(item): case .tap:
if item == "forgot" { arguments.openForgotPassword()
arguments.openForgotPassword()
} else if item == "declineReset" {
arguments.declinePasswordReset()
}
} }
}) })
case let .passwordSetup(_, text): case let .passwordSetup(theme, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.openSetupPassword() arguments.openSetupPassword()
}) })
case let .passwordSetupInfo(_, text): case let .passwordSetupInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section) return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section)
case let .changePassword(_, text): case let .changePassword(theme, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.openSetupPassword() arguments.openSetupPassword()
}) })
case let .turnPasswordOff(_, text): case let .turnPasswordOff(theme, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.openDisablePassword() arguments.openDisablePassword()
}) })
case let .setupRecoveryEmail(_, text): case let .setupRecoveryEmail(theme, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.openSetupEmail() arguments.openSetupEmail()
}) })
case let .passwordInfo(_, text): case let .passwordInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
case let .pendingEmailConfirmInfo(_, text): case let .pendingEmailConfirmInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
case let .pendingEmailConfirmCode(_, _, title, text): case let .pendingEmailConfirmCode(theme, strings, title, text):
return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: ""), text: text, placeholder: title, type: .number, sectionId: self.section, textUpdated: { value in return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: ""), text: text, placeholder: title, type: .number, sectionId: self.section, textUpdated: { value in
arguments.updateEmailCode(value) arguments.updateEmailCode(value)
}, action: {}) }, action: {})
case let .pendingEmailInfo(_, text): case let .pendingEmailInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in
switch action { switch action {
case .tap: case .tap:
arguments.openResetPendingEmail() arguments.openResetPendingEmail()
} }
}) })
case let .pendingEmailOpenConfirm(_, text): case let .pendingEmailOpenConfirm(theme, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.openConfirmEmail() arguments.openConfirmEmail()
}) })
@ -210,27 +204,13 @@ private func twoStepVerificationUnlockSettingsControllerEntries(presentationData
entries.append(.passwordSetup(presentationData.theme, presentationData.strings.TwoStepAuth_SetPassword)) entries.append(.passwordSetup(presentationData.theme, presentationData.strings.TwoStepAuth_SetPassword))
entries.append(.passwordSetupInfo(presentationData.theme, presentationData.strings.TwoStepAuth_SetPasswordHelp)) entries.append(.passwordSetupInfo(presentationData.theme, presentationData.strings.TwoStepAuth_SetPasswordHelp))
} }
case let .set(hint, _, _, pendingResetTimestamp): case let .set(hint, _, _):
entries.append(.passwordEntry(presentationData.theme, presentationData.strings, presentationData.strings.TwoStepAuth_EnterPasswordPassword, state.passwordText)) entries.append(.passwordEntry(presentationData.theme, presentationData.strings, presentationData.strings.TwoStepAuth_EnterPasswordPassword, state.passwordText))
var text: String = presentationData.strings.TwoStepAuth_EnterPasswordHint(escapedPlaintextForMarkdown(hint)).0 + "\n\n" + presentationData.strings.TwoStepAuth_EnterPasswordHelp + "\n\n[" + presentationData.strings.TwoStepAuth_EnterPasswordForgot + "](forgot)" if hint.isEmpty {
if !hint.isEmpty { entries.append(.passwordEntryInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EnterPasswordHelp + "\n\n[" + presentationData.strings.TwoStepAuth_EnterPasswordForgot + "](forgot)"))
text = presentationData.strings.TwoStepAuth_EnterPasswordHint(escapedPlaintextForMarkdown(hint)).0 + "\n\n" + presentationData.strings.TwoStepAuth_EnterPasswordHelp + "\n\n[" + presentationData.strings.TwoStepAuth_EnterPasswordForgot + "](forgot)"
} else { } else {
text = presentationData.strings.TwoStepAuth_EnterPasswordHelp + "\n\n[" + presentationData.strings.TwoStepAuth_EnterPasswordForgot + "](forgot)" entries.append(.passwordEntryInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EnterPasswordHint(escapedPlaintextForMarkdown(hint)).0 + "\n\n" + presentationData.strings.TwoStepAuth_EnterPasswordHelp + "\n\n[" + presentationData.strings.TwoStepAuth_EnterPasswordForgot + "](forgot)"))
} }
if let pendingResetTimestamp = pendingResetTimestamp {
let remainingSeconds = pendingResetTimestamp - Int32(Date().timeIntervalSince1970)
if remainingSeconds <= 0 {
text.append("\nPassword reset is available")
} else {
text.append("\nPassword reset available in \(remainingSeconds) s")
}
text.append("\n[Cancel reset](declineReset)")
}
entries.append(.passwordEntryInfo(presentationData.theme, text))
} }
} }
case let .manage(_, emailSet, pendingEmail, _): case let .manage(_, emailSet, pendingEmail, _):
@ -260,14 +240,14 @@ struct TwoStepVerificationPendingEmailState: Equatable {
enum TwoStepVerificationAccessConfiguration: Equatable { enum TwoStepVerificationAccessConfiguration: Equatable {
case notSet(pendingEmail: TwoStepVerificationPendingEmailState?) case notSet(pendingEmail: TwoStepVerificationPendingEmailState?)
case set(hint: String, hasRecoveryEmail: Bool, hasSecureValues: Bool, pendingResetTimestamp: Int32?) case set(hint: String, hasRecoveryEmail: Bool, hasSecureValues: Bool)
init(configuration: TwoStepVerificationConfiguration, password: String?) { init(configuration: TwoStepVerificationConfiguration, password: String?) {
switch configuration { switch configuration {
case let .notSet(pendingEmail): case let .notSet(pendingEmail):
self = .notSet(pendingEmail: pendingEmail.flatMap({ TwoStepVerificationPendingEmailState(password: password, email: $0) })) self = .notSet(pendingEmail: pendingEmail.flatMap({ TwoStepVerificationPendingEmailState(password: password, email: $0) }))
case let .set(hint, hasRecoveryEmail, _, hasSecureValues, pendingResetTimestamp): case let .set(hint, hasRecoveryEmail, _, hasSecureValues, _):
self = .set(hint: hint, hasRecoveryEmail: hasRecoveryEmail, hasSecureValues: hasSecureValues, pendingResetTimestamp: pendingResetTimestamp) self = .set(hint: hint, hasRecoveryEmail: hasRecoveryEmail, hasSecureValues: hasSecureValues)
} }
} }
} }
@ -440,6 +420,7 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
|> mapToSignal { settings -> Signal<(TwoStepVerificationSettings, TwoStepVerificationPendingEmail?), AuthorizationPasswordVerificationError> in |> mapToSignal { settings -> Signal<(TwoStepVerificationSettings, TwoStepVerificationPendingEmail?), AuthorizationPasswordVerificationError> in
return twoStepVerificationConfiguration(account: context.account) return twoStepVerificationConfiguration(account: context.account)
|> mapError { _ -> AuthorizationPasswordVerificationError in |> mapError { _ -> AuthorizationPasswordVerificationError in
return .generic
} }
|> map { configuration in |> map { configuration in
var pendingEmail: TwoStepVerificationPendingEmail? var pendingEmail: TwoStepVerificationPendingEmail?
@ -488,7 +469,7 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
if let configuration = configuration { if let configuration = configuration {
let presentationData = context.sharedContext.currentPresentationData.with { $0 } let presentationData = context.sharedContext.currentPresentationData.with { $0 }
switch configuration { switch configuration {
case let .set(_, hasRecoveryEmail, _, pendingResetTimestamp): case let .set(_, hasRecoveryEmail, _):
if hasRecoveryEmail { if hasRecoveryEmail {
updateState { state in updateState { state in
var state = state var state = state
@ -525,23 +506,7 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
})) }))
} else { } else {
if true || pendingResetTimestamp == nil { presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.TwoStepAuth_RecoveryUnavailable, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
let _ = (requestTwoStepPasswordReset(network: context.account.network)
|> deliverOnMainQueue).start(next: { result in
switch result {
case .done, .waitingForReset:
dataPromise.set(twoStepVerificationConfiguration(account: context.account)
|> map { TwoStepVerificationUnlockSettingsControllerData.access(configuration: TwoStepVerificationAccessConfiguration(configuration: $0, password: nil))
})
case .declined:
break
case let .error(reason):
break
}
})
} else {
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.TwoStepAuth_RecoveryUnavailable, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
}
} }
case .notSet: case .notSet:
break break
@ -797,13 +762,6 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
} }
}) })
}, declinePasswordReset: {
let _ = (declineTwoStepPasswordReset(network: context.account.network)
|> deliverOnMainQueue).start(completed: {
dataPromise.set(twoStepVerificationConfiguration(account: context.account)
|> map { TwoStepVerificationUnlockSettingsControllerData.access(configuration: TwoStepVerificationAccessConfiguration(configuration: $0, password: nil))
})
})
}) })
var initialFocusImpl: (() -> Void)? var initialFocusImpl: (() -> Void)?

View File

@ -795,7 +795,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1908627474] = { return Api.SecureValueType.parse_secureValueTypeEmail($0) } dict[-1908627474] = { return Api.SecureValueType.parse_secureValueTypeEmail($0) }
dict[-732254058] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoUnknown($0) } dict[-732254058] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoUnknown($0) }
dict[982592842] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow($0) } dict[982592842] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow($0) }
dict[408623183] = { return Api.account.Password.parse_password($0) } dict[-1390001672] = { return Api.account.Password.parse_password($0) }
dict[-2000710887] = { return Api.InputBotInlineResult.parse_inputBotInlineResult($0) } dict[-2000710887] = { return Api.InputBotInlineResult.parse_inputBotInlineResult($0) }
dict[-1462213465] = { return Api.InputBotInlineResult.parse_inputBotInlineResultPhoto($0) } dict[-1462213465] = { return Api.InputBotInlineResult.parse_inputBotInlineResultPhoto($0) }
dict[-459324] = { return Api.InputBotInlineResult.parse_inputBotInlineResultDocument($0) } dict[-459324] = { return Api.InputBotInlineResult.parse_inputBotInlineResultDocument($0) }

View File

@ -1325,13 +1325,13 @@ public struct account {
} }
public enum Password: TypeConstructorDescription { public enum Password: TypeConstructorDescription {
case password(flags: Int32, currentAlgo: Api.PasswordKdfAlgo?, srpB: Buffer?, srpId: Int64?, hint: String?, emailUnconfirmedPattern: String?, newAlgo: Api.PasswordKdfAlgo, newSecureAlgo: Api.SecurePasswordKdfAlgo, secureRandom: Buffer, pendingResetDate: Int32?) case password(flags: Int32, currentAlgo: Api.PasswordKdfAlgo?, srpB: Buffer?, srpId: Int64?, hint: String?, emailUnconfirmedPattern: String?, newAlgo: Api.PasswordKdfAlgo, newSecureAlgo: Api.SecurePasswordKdfAlgo, secureRandom: Buffer)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self { switch self {
case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom, let pendingResetDate): case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom):
if boxed { if boxed {
buffer.appendInt32(408623183) buffer.appendInt32(-1390001672)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 2) != 0 {currentAlgo!.serialize(buffer, true)} if Int(flags) & Int(1 << 2) != 0 {currentAlgo!.serialize(buffer, true)}
@ -1342,15 +1342,14 @@ public struct account {
newAlgo.serialize(buffer, true) newAlgo.serialize(buffer, true)
newSecureAlgo.serialize(buffer, true) newSecureAlgo.serialize(buffer, true)
serializeBytes(secureRandom, buffer: buffer, boxed: false) serializeBytes(secureRandom, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 5) != 0 {serializeInt32(pendingResetDate!, buffer: buffer, boxed: false)}
break break
} }
} }
public func descriptionFields() -> (String, [(String, Any)]) { public func descriptionFields() -> (String, [(String, Any)]) {
switch self { switch self {
case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom, let pendingResetDate): case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom):
return ("password", [("flags", flags), ("currentAlgo", currentAlgo), ("srpB", srpB), ("srpId", srpId), ("hint", hint), ("emailUnconfirmedPattern", emailUnconfirmedPattern), ("newAlgo", newAlgo), ("newSecureAlgo", newSecureAlgo), ("secureRandom", secureRandom), ("pendingResetDate", pendingResetDate)]) return ("password", [("flags", flags), ("currentAlgo", currentAlgo), ("srpB", srpB), ("srpId", srpId), ("hint", hint), ("emailUnconfirmedPattern", emailUnconfirmedPattern), ("newAlgo", newAlgo), ("newSecureAlgo", newSecureAlgo), ("secureRandom", secureRandom)])
} }
} }
@ -1379,8 +1378,6 @@ public struct account {
} }
var _9: Buffer? var _9: Buffer?
_9 = parseBytes(reader) _9 = parseBytes(reader)
var _10: Int32?
if Int(_1!) & Int(1 << 5) != 0 {_10 = reader.readInt32() }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = (Int(_1!) & Int(1 << 2) == 0) || _2 != nil let _c2 = (Int(_1!) & Int(1 << 2) == 0) || _2 != nil
let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil
@ -1390,9 +1387,8 @@ public struct account {
let _c7 = _7 != nil let _c7 = _7 != nil
let _c8 = _8 != nil let _c8 = _8 != nil
let _c9 = _9 != nil let _c9 = _9 != nil
let _c10 = (Int(_1!) & Int(1 << 5) == 0) || _10 != nil if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 {
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 { return Api.account.Password.password(flags: _1!, currentAlgo: _2, srpB: _3, srpId: _4, hint: _5, emailUnconfirmedPattern: _6, newAlgo: _7!, newSecureAlgo: _8!, secureRandom: _9!)
return Api.account.Password.password(flags: _1!, currentAlgo: _2, srpB: _3, srpId: _4, hint: _5, emailUnconfirmedPattern: _6, newAlgo: _7!, newSecureAlgo: _8!, secureRandom: _9!, pendingResetDate: _10)
} }
else { else {
return nil return nil
@ -5254,13 +5250,11 @@ public extension Api {
}) })
} }
public static func recoverPassword(flags: Int32, code: String, newSettings: Api.account.PasswordInputSettings?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.auth.Authorization>) { public static func recoverPassword(code: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.auth.Authorization>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(923364464) buffer.appendInt32(1319464594)
serializeInt32(flags, buffer: buffer, boxed: false)
serializeString(code, buffer: buffer, boxed: false) serializeString(code, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {newSettings!.serialize(buffer, true)} return (FunctionDescription(name: "auth.recoverPassword", parameters: [("code", code)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.auth.Authorization? in
return (FunctionDescription(name: "auth.recoverPassword", parameters: [("flags", flags), ("code", code), ("newSettings", newSettings)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.auth.Authorization? in
let reader = BufferReader(buffer) let reader = BufferReader(buffer)
var result: Api.auth.Authorization? var result: Api.auth.Authorization?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {
@ -5365,20 +5359,6 @@ public extension Api {
return result return result
}) })
} }
public static func checkRecoveryPassword(code: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(221691769)
serializeString(code, buffer: buffer, boxed: false)
return (FunctionDescription(name: "auth.checkRecoveryPassword", parameters: [("code", code)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.Bool
}
return result
})
}
} }
public struct bots { public struct bots {
public static func sendCustomRequest(customMethod: String, params: Api.DataJSON) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.DataJSON>) { public static func sendCustomRequest(customMethod: String, params: Api.DataJSON) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.DataJSON>) {
@ -5431,6 +5411,21 @@ public extension Api {
}) })
} }
public static func resetBotCommands(scope: Api.BotCommandScope, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(1032708345)
scope.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
return (FunctionDescription(name: "bots.resetBotCommands", parameters: [("scope", scope), ("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.Bool
}
return result
})
}
public static func getBotCommands(scope: Api.BotCommandScope, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.BotCommand]>) { public static func getBotCommands(scope: Api.BotCommandScope, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.BotCommand]>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(-481554986) buffer.appendInt32(-481554986)
@ -7507,34 +7502,6 @@ public extension Api {
return result return result
}) })
} }
public static func resetPassword() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(1517436040)
return (FunctionDescription(name: "account.resetPassword", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.Bool
}
return result
})
}
public static func declinePasswordReset() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(1284770294)
return (FunctionDescription(name: "account.declinePasswordReset", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.Bool
}
return result
})
}
} }
public struct langpack { public struct langpack {
public static func getLangPack(langPack: String, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) { public static func getLangPack(langPack: String, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) {

View File

@ -377,7 +377,8 @@ public func twoStepAuthData(_ network: Network) -> Signal<TwoStepAuthData, MTRpc
return network.request(Api.functions.account.getPassword()) return network.request(Api.functions.account.getPassword())
|> map { config -> TwoStepAuthData in |> map { config -> TwoStepAuthData in
switch config { switch config {
case let .password(flags, currentAlgo, srpB, srpId, hint, emailUnconfirmedPattern, newAlgo, newSecureAlgo, secureRandom, pendingResetDate): case let .password(flags, currentAlgo, srpB, srpId, hint, emailUnconfirmedPattern, newAlgo, newSecureAlgo, secureRandom/*, pendingResetDate*/):
let pendingResetDate: Int32? = nil
let hasRecovery = (flags & (1 << 0)) != 0 let hasRecovery = (flags & (1 << 0)) != 0
let hasSecureValues = (flags & (1 << 1)) != 0 let hasSecureValues = (flags & (1 << 1)) != 0

View File

@ -373,7 +373,41 @@ public enum PasswordRecoveryError {
case generic case generic
} }
public func checkPasswordRecoveryCode(network: Network, code: String) -> Signal<Never, PasswordRecoveryError> { public func performPasswordRecovery(accountManager: AccountManager, account: UnauthorizedAccount, code: String, syncContacts: Bool) -> Signal<Void, PasswordRecoveryError> {
return account.network.request(Api.functions.auth.recoverPassword(code: code))
|> mapError { error -> PasswordRecoveryError in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .limitExceeded
} else if error.errorDescription.hasPrefix("PASSWORD_RECOVERY_EXPIRED") {
return .expired
} else {
return .invalidCode
}
}
|> mapToSignal { result -> Signal<Void, PasswordRecoveryError> in
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
switch result {
case let .authorization(_, _, user):
let user = TelegramUser(user: user)
let state = AuthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, peerId: user.id, state: nil)
/*transaction.updatePeersInternal([user], update: { current, peer -> Peer? in
return peer
})*/
initializedAppSettingsAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion, syncContacts: syncContacts)
transaction.setState(state)
return accountManager.transaction { transaction -> Void in
switchToAuthorizedAccount(transaction: transaction, account: account)
}
case .authorizationSignUpRequired:
return .complete()
}
}
|> switchToLatest
|> mapError { _ -> PasswordRecoveryError in }
}
}
/*public func checkPasswordRecoveryCode(network: Network, code: String) -> Signal<Never, PasswordRecoveryError> {
return network.request(Api.functions.auth.checkRecoveryPassword(code: code), automaticFloodWait: false) return network.request(Api.functions.auth.checkRecoveryPassword(code: code), automaticFloodWait: false)
|> mapError { error -> PasswordRecoveryError in |> mapError { error -> PasswordRecoveryError in
if error.errorDescription.hasPrefix("FLOOD_WAIT") { if error.errorDescription.hasPrefix("FLOOD_WAIT") {
@ -446,7 +480,7 @@ public func performPasswordRecovery(accountManager: AccountManager, account: Una
|> mapError { _ -> PasswordRecoveryError in } |> mapError { _ -> PasswordRecoveryError in }
} }
} }
} }*/
public enum AccountResetError { public enum AccountResetError {
case generic case generic

View File

@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
public class Serialization: NSObject, MTSerialization { public class Serialization: NSObject, MTSerialization {
public func currentLayer() -> UInt { public func currentLayer() -> UInt {
return 131 return 130
} }
public func parseMessage(_ data: Data!) -> Any! { public func parseMessage(_ data: Data!) -> Any! {

View File

@ -18,7 +18,7 @@ public func twoStepVerificationConfiguration(account: Account) -> Signal<TwoStep
switch result { switch result {
case let .password(password): case let .password(password):
if password.currentAlgo != nil { if password.currentAlgo != nil {
return .set(hint: password.hint ?? "", hasRecoveryEmail: (password.flags & (1 << 0)) != 0, pendingEmail: password.emailUnconfirmedPattern.flatMap({ TwoStepVerificationPendingEmail(pattern: $0, codeLength: nil) }), hasSecureValues: (password.flags & (1 << 1)) != 0, pendingResetTimestamp: password.pendingResetDate) return .set(hint: password.hint ?? "", hasRecoveryEmail: (password.flags & (1 << 0)) != 0, pendingEmail: password.emailUnconfirmedPattern.flatMap({ TwoStepVerificationPendingEmail(pattern: $0, codeLength: nil) }), hasSecureValues: (password.flags & (1 << 1)) != 0, pendingResetTimestamp: nil/*password.pendingResetDate*/)
} else { } else {
return .notSet(pendingEmail: password.emailUnconfirmedPattern.flatMap({ TwoStepVerificationPendingEmail(pattern: $0, codeLength: nil) })) return .notSet(pendingEmail: password.emailUnconfirmedPattern.flatMap({ TwoStepVerificationPendingEmail(pattern: $0, codeLength: nil) }))
} }
@ -345,7 +345,7 @@ public func recoverTwoStepVerificationPassword(network: Network, code: String) -
flags |= (1 << 0) flags |= (1 << 0)
} }
return network.request(Api.functions.auth.recoverPassword(flags: 0, code: code, newSettings: nil), automaticFloodWait: false) return network.request(Api.functions.auth.recoverPassword(code: code), automaticFloodWait: false)
|> mapError { error -> RecoverTwoStepVerificationPasswordError in |> mapError { error -> RecoverTwoStepVerificationPasswordError in
if error.errorDescription.hasPrefix("FLOOD_WAIT_") { if error.errorDescription.hasPrefix("FLOOD_WAIT_") {
return .limitExceeded return .limitExceeded
@ -426,7 +426,7 @@ public enum RequestTwoStepPasswordResetResult {
case error(reason: ErrorReason) case error(reason: ErrorReason)
} }
public func requestTwoStepPasswordReset(network: Network) -> Signal<RequestTwoStepPasswordResetResult, NoError> { /*public func requestTwoStepPasswordReset(network: Network) -> Signal<RequestTwoStepPasswordResetResult, NoError> {
return network.request(Api.functions.account.resetPassword(), automaticFloodWait: false) return network.request(Api.functions.account.resetPassword(), automaticFloodWait: false)
|> map { _ -> RequestTwoStepPasswordResetResult in |> map { _ -> RequestTwoStepPasswordResetResult in
return .done return .done
@ -462,4 +462,4 @@ public func declineTwoStepPasswordReset(network: Network) -> Signal<Never, NoErr
return .single(.boolFalse) return .single(.boolFalse)
} }
|> ignoreValues |> ignoreValues
} }*/

View File

@ -571,6 +571,30 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
controller?.inProgress = true controller?.inProgress = true
strongSelf.actionDisposable.set((performPasswordRecovery(accountManager: strongSelf.sharedContext.accountManager, account: strongSelf.account, code: code, syncContacts: syncContacts) |> deliverOnMainQueue).start(error: { error in
Queue.mainQueue().async {
if let strongSelf = self, let controller = controller {
controller.inProgress = false
let text: String
switch error {
case .limitExceeded:
text = strongSelf.presentationData.strings.LoginPassword_FloodError
case .invalidCode:
text = strongSelf.presentationData.strings.Login_InvalidCodeError
case .expired:
text = strongSelf.presentationData.strings.Login_CodeExpiredError
case .generic:
text = strongSelf.presentationData.strings.Login_UnknownError
}
controller.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: strongSelf.presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
}
}
}))
/*controller?.inProgress = true
strongSelf.actionDisposable.set((checkPasswordRecoveryCode(network: strongSelf.account.network, code: code) strongSelf.actionDisposable.set((checkPasswordRecoveryCode(network: strongSelf.account.network, code: code)
|> deliverOnMainQueue).start(error: { error in |> deliverOnMainQueue).start(error: { error in
guard let strongSelf = self, let controller = controller else { guard let strongSelf = self, let controller = controller else {
@ -603,7 +627,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
} }
}) })
strongSelf.setViewControllers(strongSelf.viewControllers + [setupController], animated: true) strongSelf.setViewControllers(strongSelf.viewControllers + [setupController], animated: true)
})) }))*/
} }
controller.noAccess = { [weak self, weak controller] in controller.noAccess = { [weak self, weak controller] in
if let strongSelf = self, let controller = controller { if let strongSelf = self, let controller = controller {