-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathAccountService.h
133 lines (99 loc) · 4.25 KB
/
AccountService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#import <Foundation/Foundation.h>
@import WordPressData;
NS_ASSUME_NONNULL_BEGIN
@class WPAccount;
@class RemoteUser;
extern NSString *const WPAccountDefaultWordPressComAccountChangedNotification;
extern NSNotificationName const WPAccountEmailAndDefaultBlogUpdatedNotification;
@interface AccountService : CoreDataService
///------------------------------------
/// @name Default WordPress.com account
///------------------------------------
/**
Sets the default WordPress.com account
@param account the account to set as default for WordPress.com
@see defaultWordPressComAccount
@see removeDefaultWordPressComAccount
*/
- (void)setDefaultWordPressComAccount:(WPAccount *)account;
/**
Removes the default WordPress.com account. Should only be called from the Main Thread
@see defaultWordPressComAccount
@see setDefaultWordPressComAccount:
*/
- (void)removeDefaultWordPressComAccount;
/**
Query to check if an email address is paired to a wpcom account. Used in the
magic links signup flow.
@param email
@param success
@param failure
*/
- (void)isEmailAvailable:(NSString *)email success:(void (^)(BOOL available))success failure:(void (^)(NSError *error))failure;
/**
Query to check if a username is available. Used in the signup flow.
@param email
@param success
@param failure
*/
- (void)isUsernameAvailable:(NSString *)username
success:(void (^)(BOOL available))success
failure:(void (^)(NSError *error))failure;
/**
Requests a verification email to be sent to the email address associated with the current account.
@param success
@param failure
*/
- (void)requestVerificationEmail:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
///-----------------------
/// @name Account creation
///-----------------------
/**
Creates a new WordPress.com account or updates the password if there is a matching account
There can only be one WordPress.com account per username, so if one already exists for the given `username` its password is updated
Uses a background managed object context.
@param username the WordPress.com account's username
@param authToken the OAuth2 token returned by signIntoWordPressDotComWithUsername:authToken:
@return The ID of the WordPress.com `WPAccount` object for the given `username`
*/
- (NSManagedObjectID *)createOrUpdateAccountWithUsername:(NSString *)username authToken:(NSString *)authToken;
/**
Updates user details including username, email, userID, avatarURL, and default blog.
@param account WPAccount to be updated
*/
- (void)updateUserDetailsForAccount:(WPAccount *)account
success:(nullable void (^)(void))success
failure:(nullable void (^)(NSError *error))failure;
/**
Updates the default blog for the specified account. The default blog will be the one whose siteID matches
the accounts primaryBlogID.
*/
- (void)updateDefaultBlogIfNeeded:(WPAccount *)account inContext:(NSManagedObjectContext *)context;
/**
Syncs the details for the account associated with the provided auth token, then
creates or updates a WPAccount with the synced information.
@param authToken The auth token associated with the account being created/updated.
@param success A success block.
@param failure A failure block.
*/
- (void)createOrUpdateAccountWithAuthToken:(NSString *)authToken
success:(void (^)(WPAccount * _Nonnull))success
failure:(void (^)(NSError * _Nonnull))failure;
- (NSManagedObjectID *)createOrUpdateAccountWithUserDetails:(RemoteUser *)remoteUser authToken:(NSString *)authToken;
/**
Initializes the WordPress iOS Extensions with the WordPress.com Default Account.
*/
- (void)setupAppExtensionsWithDefaultAccount;
/**
Removes an account if it's not the default account and there are no associated blogs
*/
- (void)purgeAccountIfUnused:(WPAccount *)account;
/**
Restores a disassociated default WordPress.com account if the current defaultWordPressCom account is nil
and another candidate account is found. This method bypasses the normal setter to avoid triggering unintended
side-effects from dispatching account changed notifications.
*/
- (void)restoreDisassociatedAccountIfNecessary;
@end
NS_ASSUME_NONNULL_END