MultiFactorMenu.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import UIKit
  15. /// Firebase Auth supported identity providers and other methods of authentication
  16. enum MultiFactorMenu: String {
  17. case phoneEnroll
  18. case totpEnroll
  19. case multifactorUnenroll
  20. // More intuitively named getter for `rawValue`.
  21. var id: String { rawValue }
  22. // The UI friendly name of the `AuthMenu`. Used for display.
  23. var name: String {
  24. switch self {
  25. // Multi factor
  26. case .phoneEnroll:
  27. return "Phone Enroll"
  28. case .totpEnroll:
  29. return "TOTP Enroll"
  30. case .multifactorUnenroll:
  31. return "Multifactor unenroll"
  32. }
  33. }
  34. // Failable initializer to create an `AuthMenu` from its corresponding `name` value.
  35. // - Parameter rawValue: String value representing `AuthMenu`'s name or type.
  36. init?(rawValue: String) {
  37. switch rawValue {
  38. case "Phone Enroll":
  39. self = .phoneEnroll
  40. case "TOTP Enroll":
  41. self = .totpEnroll
  42. case "Multifactor unenroll":
  43. self = .multifactorUnenroll
  44. default:
  45. return nil
  46. }
  47. }
  48. }
  49. // MARK: DataSourceProvidable
  50. class MultiFactorMenuData : AuthMenuData {
  51. static var multifactorSection: Section {
  52. let header = "Multi Factor"
  53. let items: [Item] = [
  54. Item(title: MultiFactorMenu.phoneEnroll.name),
  55. Item(title: MultiFactorMenu.totpEnroll.name),
  56. Item(title: MultiFactorMenu.multifactorUnenroll.name),
  57. ]
  58. return Section(headerDescription: header, items: items)
  59. }
  60. }
  61. // static var sections: [Section] =
  62. // [multifactorSection]
  63. // static var authLinkSections: [Section] {
  64. // let allItems = AuthMenuData.sections.flatMap { $0.items }
  65. // let header = "Manage linking between providers"
  66. // let footer =
  67. // "Select an unchecked row to link the currently signed in user to that auth provider. To unlink the user from a linked provider, select its corresponding row marked with a checkmark."
  68. // return [Section(headerDescription: header, footerDescription: footer, items: allItems)]
  69. // }
  70. // var sections: [Section] = AuthMenuData.sections