You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7 KiB

6 years ago
6 years ago
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRSignUpNewUserRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kSignupNewUserEndpoint
  19. @brief The "SingupNewUserEndpoint" endpoint.
  20. */
  21. static NSString *const kSignupNewUserEndpoint = @"signupNewUser";
  22. /** @var kEmailKey
  23. @brief The key for the "email" value in the request.
  24. */
  25. static NSString *const kEmailKey = @"email";
  26. /** @var kPasswordKey
  27. @brief The key for the "password" value in the request.
  28. */
  29. static NSString *const kPasswordKey = @"password";
  30. /** @var kDisplayNameKey
  31. @brief The key for the "kDisplayName" value in the request.
  32. */
  33. static NSString *const kDisplayNameKey = @"displayName";
  34. /** @var kReturnSecureTokenKey
  35. @brief The key for the "returnSecureToken" value in the request.
  36. */
  37. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  38. @implementation FIRSignUpNewUserRequest
  39. - (nullable instancetype)initWithEmail:(nullable NSString *)email
  40. password:(nullable NSString *)password
  41. displayName:(nullable NSString *)displayName
  42. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  43. self = [super initWithEndpoint:kSignupNewUserEndpoint requestConfiguration:requestConfiguration];
  44. if (self) {
  45. _email = [email copy];
  46. _password = [password copy];
  47. _displayName = [displayName copy];
  48. _returnSecureToken = YES;
  49. }
  50. return self;
  51. }
  52. - (nullable instancetype)initWithRequestConfiguration:
  53. (FIRAuthRequestConfiguration *)requestConfiguration {
  54. self = [self initWithEmail:nil
  55. password:nil
  56. displayName:nil
  57. requestConfiguration:requestConfiguration];
  58. return self;
  59. }
  60. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  61. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  62. if (_email) {
  63. postBody[kEmailKey] = _email;
  64. }
  65. if (_password) {
  66. postBody[kPasswordKey] = _password;
  67. }
  68. if (_displayName) {
  69. postBody[kDisplayNameKey] = _displayName;
  70. }
  71. if (_returnSecureToken) {
  72. postBody[kReturnSecureTokenKey] = @YES;
  73. }
  74. return postBody;
  75. }
  76. @end
  77. NS_ASSUME_NONNULL_END