RLMEmailPasswordAuth.mm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2020 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import "RLMEmailPasswordAuth.h"
  19. #import "RLMApp_Private.hpp"
  20. #import "RLMBSON_Private.hpp"
  21. #import "RLMProviderClient_Private.hpp"
  22. #import <realm/object-store/sync/app.hpp>
  23. @implementation RLMEmailPasswordAuth
  24. - (realm::app::App::UsernamePasswordProviderClient)client {
  25. return self.app._realmApp->provider_client<realm::app::App::UsernamePasswordProviderClient>();
  26. }
  27. - (void)registerUserWithEmail:(NSString *)email
  28. password:(NSString *)password
  29. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  30. self.client.register_email(email.UTF8String, password.UTF8String, ^(realm::util::Optional<realm::app::AppError> error) {
  31. [self handleResponse:error completion:completion];
  32. });
  33. }
  34. - (void)confirmUser:(NSString *)token
  35. tokenId:(NSString *)tokenId
  36. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  37. self.client.confirm_user(token.UTF8String, tokenId.UTF8String, ^(realm::util::Optional<realm::app::AppError> error) {
  38. [self handleResponse:error completion:completion];
  39. });
  40. }
  41. - (void)resendConfirmationEmail:(NSString *)email
  42. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  43. self.client.resend_confirmation_email(email.UTF8String, ^(realm::util::Optional<realm::app::AppError> error) {
  44. [self handleResponse:error completion:completion];
  45. });
  46. }
  47. - (void)sendResetPasswordEmail:(NSString *)email
  48. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  49. self.client.send_reset_password_email(email.UTF8String, ^(realm::util::Optional<realm::app::AppError> error) {
  50. [self handleResponse:error completion:completion];
  51. });
  52. }
  53. - (void)resetPasswordTo:(NSString *)password
  54. token:(NSString *)token
  55. tokenId:(NSString *)tokenId
  56. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  57. self.client.reset_password(password.UTF8String, token.UTF8String, tokenId.UTF8String, ^(realm::util::Optional<realm::app::AppError> error) {
  58. [self handleResponse:error completion:completion];
  59. });
  60. }
  61. - (void)callResetPasswordFunction:(NSString *)email
  62. password:(NSString *)password
  63. args:(NSArray<id<RLMBSON>> *)args
  64. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  65. self.client.call_reset_password_function(email.UTF8String,
  66. password.UTF8String,
  67. static_cast<realm::bson::BsonArray>(RLMConvertRLMBSONToBson(args)),
  68. ^(realm::util::Optional<realm::app::AppError> error) {
  69. [self handleResponse:error completion:completion];
  70. });
  71. }
  72. @end