ActionCodeInfo.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) open 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. init(withOperation operation: ActionCodeOperation, email: String, newEmail: String?) {
  33. self.operation = operation
  34. if let newEmail {
  35. self.email = newEmail
  36. previousEmail = email
  37. } else {
  38. self.email = email
  39. previousEmail = nil
  40. }
  41. }
  42. /** @fn actionCodeOperationForRequestType:
  43. @brief Returns the corresponding operation type per provided request type string.
  44. @param requestType Request type returned in in the server response.
  45. @return The corresponding ActionCodeOperation for the supplied request type.
  46. */
  47. class func actionCodeOperation(forRequestType requestType: String?) -> ActionCodeOperation {
  48. switch requestType {
  49. case "PASSWORD_RESET": return .passwordReset
  50. case "VERIFY_EMAIL": return .verifyEmail
  51. case "RECOVER_EMAIL": return .recoverEmail
  52. case "EMAIL_SIGNIN": return .emailLink
  53. case "VERIFY_AND_CHANGE_EMAIL": return .verifyAndChangeEmail
  54. case "REVERT_SECOND_FACTOR_ADDITION": return .revertSecondFactorAddition
  55. default: return .unknown
  56. }
  57. }
  58. }