ActionCodeInfo.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2023 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 Foundation
  15. /** @class ActionCodeInfo
  16. @brief Manages information regarding action codes.
  17. */
  18. @objc(FIRActionCodeInfo) public class ActionCodeInfo: NSObject {
  19. /**
  20. @brief The operation being performed.
  21. */
  22. @objc public let operation: ActionCodeOperation
  23. /** @property email
  24. @brief The email address to which the code was sent. The new email address in the case of
  25. `ActionCodeOperationRecoverEmail`.
  26. */
  27. @objc public let email: String
  28. /** @property previousEmail
  29. @brief The email that is being recovered in the case of `ActionCodeOperationRecoverEmail`.
  30. */
  31. @objc public let previousEmail: String?
  32. // TODO: Below here change to internal.
  33. @objc public init(withOperation operation: ActionCodeOperation, email: String,
  34. newEmail: String?) {
  35. self.operation = operation
  36. if let newEmail {
  37. self.email = newEmail
  38. previousEmail = email
  39. } else {
  40. self.email = email
  41. previousEmail = nil
  42. }
  43. }
  44. /** @fn actionCodeOperationForRequestType:
  45. @brief Returns the corresponding operation type per provided request type string.
  46. @param requestType Request type returned in in the server response.
  47. @return The corresponding ActionCodeOperation for the supplied request type.
  48. */
  49. @objc public
  50. class func actionCodeOperation(forRequestType requestType: String?) -> ActionCodeOperation {
  51. switch requestType {
  52. case "PASSWORD_RESET": return .passwordReset
  53. case "VERIFY_EMAIL": return .verifyEmail
  54. case "RECOVER_EMAIL": return .recoverEmail
  55. case "EMAIL_SIGNIN": return .emailLink
  56. case "VERIFY_AND_CHANGE_EMAIL": return .verifyAndChangeEmail
  57. case "REVERT_SECOND_FACTOR_ADDITION": return .revertSecondFactorAddition
  58. default: return .unknown
  59. }
  60. }
  61. }