RLMEmailPasswordAuth.mm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, RLMWrapCompletion(completion));
  31. }
  32. - (void)confirmUser:(NSString *)token
  33. tokenId:(NSString *)tokenId
  34. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  35. self.client.confirm_user(token.UTF8String, tokenId.UTF8String, RLMWrapCompletion(completion));
  36. }
  37. - (void)retryCustomConfirmation:(NSString *)email
  38. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  39. self.client.retry_custom_confirmation(email.UTF8String, RLMWrapCompletion(completion));
  40. }
  41. - (void)resendConfirmationEmail:(NSString *)email
  42. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  43. self.client.resend_confirmation_email(email.UTF8String, RLMWrapCompletion(completion));
  44. }
  45. - (void)sendResetPasswordEmail:(NSString *)email
  46. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  47. self.client.send_reset_password_email(email.UTF8String, RLMWrapCompletion(completion));
  48. }
  49. - (void)resetPasswordTo:(NSString *)password
  50. token:(NSString *)token
  51. tokenId:(NSString *)tokenId
  52. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  53. self.client.reset_password(password.UTF8String, token.UTF8String, tokenId.UTF8String,
  54. RLMWrapCompletion(completion));
  55. }
  56. - (void)callResetPasswordFunction:(NSString *)email
  57. password:(NSString *)password
  58. args:(NSArray<id<RLMBSON>> *)args
  59. completion:(RLMEmailPasswordAuthOptionalErrorBlock)completion {
  60. self.client.call_reset_password_function(email.UTF8String,
  61. password.UTF8String,
  62. static_cast<realm::bson::BsonArray>(RLMConvertRLMBSONToBson(args)),
  63. RLMWrapCompletion(completion));
  64. }
  65. @end