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.

86 lines
2.7 KiB

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. /** @var kSignupNewUserEndpoint
  18. @brief The "SingupNewUserEndpoint" endpoint.
  19. */
  20. static NSString *const kSignupNewUserEndpoint = @"signupNewUser";
  21. /** @var kEmailKey
  22. @brief The key for the "email" value in the request.
  23. */
  24. static NSString *const kEmailKey = @"email";
  25. /** @var kPasswordKey
  26. @brief The key for the "password" value in the request.
  27. */
  28. static NSString *const kPasswordKey = @"password";
  29. /** @var kDisplayNameKey
  30. @brief The key for the "kDisplayName" value in the request.
  31. */
  32. static NSString *const kDisplayNameKey = @"displayName";
  33. /** @var kReturnSecureTokenKey
  34. @brief The key for the "returnSecureToken" value in the request.
  35. */
  36. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  37. @implementation FIRSignUpNewUserRequest
  38. - (nullable instancetype)initWithEmail:(nullable NSString *)email
  39. password:(nullable NSString *)password
  40. displayName:(nullable NSString *)displayName
  41. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  42. self = [super initWithEndpoint:kSignupNewUserEndpoint requestConfiguration:requestConfiguration];
  43. if (self) {
  44. _email = [email copy];
  45. _password = [password copy];
  46. _displayName = [displayName copy];
  47. _returnSecureToken = YES;
  48. }
  49. return self;
  50. }
  51. - (nullable instancetype)initWithRequestConfiguration:
  52. (FIRAuthRequestConfiguration *)requestConfiguration {
  53. self = [self initWithEmail:nil
  54. password:nil
  55. displayName:nil
  56. requestConfiguration:requestConfiguration];
  57. return self;
  58. }
  59. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  60. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  61. if (_email) {
  62. postBody[kEmailKey] = _email;
  63. }
  64. if (_password) {
  65. postBody[kPasswordKey] = _password;
  66. }
  67. if (_displayName) {
  68. postBody[kDisplayNameKey] = _displayName;
  69. }
  70. if (_returnSecureToken) {
  71. postBody[kReturnSecureTokenKey] = @YES;
  72. }
  73. return postBody;
  74. }
  75. @end