parse 4.0.1 → 4.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.js +17995 -26193
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +8739 -17728
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +2 -20
- package/lib/browser/AnonymousUtils.js +6 -35
- package/lib/browser/Cloud.js +12 -70
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -184
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -1
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -35
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -13
- package/lib/browser/LiveQueryClient.js +87 -204
- package/lib/browser/LiveQuerySubscription.js +10 -39
- package/lib/browser/LocalDatastore.js +451 -1081
- package/lib/browser/LocalDatastoreController.js +145 -602
- package/lib/browser/LocalDatastoreController.react-native.js +137 -573
- package/lib/browser/LocalDatastoreUtils.js +2 -12
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +42 -222
- package/lib/browser/Parse.js +12 -106
- package/lib/browser/ParseACL.js +33 -141
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -88
- package/lib/browser/ParseError.js +63 -90
- package/lib/browser/ParseFile.js +129 -685
- package/lib/browser/ParseGeoPoint.js +23 -82
- package/lib/browser/ParseHooks.js +1 -34
- package/lib/browser/ParseInstallation.js +4 -32
- package/lib/browser/ParseLiveQuery.js +96 -505
- package/lib/browser/ParseObject.js +628 -1840
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -63
- package/lib/browser/ParseQuery.js +404 -1505
- package/lib/browser/ParseRelation.js +12 -61
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -201
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -43
- package/lib/browser/RESTController.js +18 -140
- package/lib/browser/SingleInstanceStateController.js +19 -137
- package/lib/browser/Socket.weapp.js +2 -12
- package/lib/browser/Storage.js +10 -73
- package/lib/browser/StorageController.browser.js +4 -17
- package/lib/browser/StorageController.default.js +4 -17
- package/lib/browser/StorageController.react-native.js +6 -33
- package/lib/browser/StorageController.weapp.js +5 -16
- package/lib/browser/TaskQueue.js +1 -22
- package/lib/browser/UniqueInstanceStateController.js +19 -142
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -16
- package/lib/browser/canBeSerialized.js +3 -33
- package/lib/browser/decode.js +3 -33
- package/lib/browser/encode.js +9 -70
- package/lib/browser/equals.js +2 -25
- package/lib/browser/escape.js +1 -8
- package/lib/browser/isRevocableSession.js +2 -11
- package/lib/browser/parseDate.js +2 -13
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -17
- package/lib/browser/unsavedChildren.js +6 -50
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -18
- package/lib/node/AnonymousUtils.js +5 -37
- package/lib/node/Cloud.js +10 -66
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -220
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -1
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -37
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -15
- package/lib/node/LiveQueryClient.js +56 -136
- package/lib/node/LiveQuerySubscription.js +7 -16
- package/lib/node/LocalDatastore.js +19 -175
- package/lib/node/LocalDatastoreController.js +6 -38
- package/lib/node/LocalDatastoreController.react-native.js +6 -45
- package/lib/node/LocalDatastoreUtils.js +1 -6
- package/lib/node/ObjectStateMutations.js +13 -93
- package/lib/node/OfflineQuery.js +20 -152
- package/lib/node/Parse.js +11 -99
- package/lib/node/ParseACL.js +32 -150
- package/lib/node/ParseCLP.js +69 -262
- package/lib/node/ParseConfig.js +16 -84
- package/lib/node/ParseError.js +61 -65
- package/lib/node/ParseFile.js +50 -205
- package/lib/node/ParseGeoPoint.js +21 -82
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -10
- package/lib/node/ParseLiveQuery.js +10 -36
- package/lib/node/ParseObject.js +193 -939
- package/lib/node/ParseOp.js +31 -255
- package/lib/node/ParsePolygon.js +12 -62
- package/lib/node/ParseQuery.js +170 -882
- package/lib/node/ParseRelation.js +11 -61
- package/lib/node/ParseRole.js +10 -57
- package/lib/node/ParseSchema.js +46 -222
- package/lib/node/ParseSession.js +8 -50
- package/lib/node/ParseUser.js +107 -576
- package/lib/node/Push.js +4 -37
- package/lib/node/RESTController.js +8 -110
- package/lib/node/SingleInstanceStateController.js +17 -130
- package/lib/node/Socket.weapp.js +2 -9
- package/lib/node/Storage.js +10 -83
- package/lib/node/StorageController.browser.js +4 -23
- package/lib/node/StorageController.default.js +5 -21
- package/lib/node/StorageController.react-native.js +6 -40
- package/lib/node/StorageController.weapp.js +6 -21
- package/lib/node/TaskQueue.js +1 -17
- package/lib/node/UniqueInstanceStateController.js +16 -133
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -12
- package/lib/node/canBeSerialized.js +2 -28
- package/lib/node/decode.js +1 -26
- package/lib/node/encode.js +3 -54
- package/lib/node/equals.js +0 -18
- package/lib/node/escape.js +1 -6
- package/lib/node/isRevocableSession.js +1 -5
- package/lib/node/parseDate.js +1 -7
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -11
- package/lib/node/unsavedChildren.js +2 -38
- package/lib/node/uuid.js +6 -1
- package/lib/react-native/Analytics.js +0 -9
- package/lib/react-native/AnonymousUtils.js +0 -10
- package/lib/react-native/Cloud.js +0 -26
- package/lib/react-native/CoreManager.js +1 -5
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +4 -52
- package/lib/react-native/FacebookUtils.js +0 -22
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -6
- package/lib/react-native/LiveQueryClient.js +24 -101
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +6 -113
- package/lib/react-native/LocalDatastoreController.js +0 -21
- package/lib/react-native/LocalDatastoreController.react-native.js +4 -31
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +0 -34
- package/lib/react-native/OfflineQuery.js +2 -137
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +32 -96
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +4 -72
- package/lib/react-native/ParseGeoPoint.js +0 -17
- package/lib/react-native/ParseHooks.js +0 -30
- package/lib/react-native/ParseInstallation.js +1 -23
- package/lib/react-native/ParseLiveQuery.js +3 -25
- package/lib/react-native/ParseObject.js +4 -371
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +6 -262
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +0 -51
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +1 -224
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +1 -70
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +2 -12
- package/lib/react-native/Storage.js +0 -24
- package/lib/react-native/StorageController.browser.js +0 -2
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -2
- package/lib/react-native/TaskQueue.js +0 -15
- package/lib/react-native/UniqueInstanceStateController.js +0 -47
- package/lib/react-native/Xhr.weapp.js +0 -16
- package/lib/react-native/arrayContainsObject.js +0 -5
- package/lib/react-native/canBeSerialized.js +0 -18
- package/lib/react-native/decode.js +0 -21
- package/lib/react-native/encode.js +0 -25
- package/lib/react-native/equals.js +0 -18
- package/lib/react-native/escape.js +0 -1
- package/lib/react-native/isRevocableSession.js +0 -1
- package/lib/react-native/parseDate.js +0 -3
- package/lib/react-native/promiseUtils.js +0 -13
- package/lib/react-native/unique.js +0 -4
- package/lib/react-native/unsavedChildren.js +0 -21
- package/lib/react-native/uuid.js +3 -1
- package/lib/weapp/Analytics.js +2 -20
- package/lib/weapp/AnonymousUtils.js +6 -35
- package/lib/weapp/Cloud.js +12 -70
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -184
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -1
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -35
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -13
- package/lib/weapp/LiveQueryClient.js +87 -204
- package/lib/weapp/LiveQuerySubscription.js +10 -39
- package/lib/weapp/LocalDatastore.js +451 -1081
- package/lib/weapp/LocalDatastoreController.js +145 -602
- package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
- package/lib/weapp/LocalDatastoreUtils.js +2 -12
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +42 -222
- package/lib/weapp/Parse.js +12 -106
- package/lib/weapp/ParseACL.js +33 -141
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -88
- package/lib/weapp/ParseError.js +63 -90
- package/lib/weapp/ParseFile.js +130 -686
- package/lib/weapp/ParseGeoPoint.js +23 -82
- package/lib/weapp/ParseHooks.js +1 -34
- package/lib/weapp/ParseInstallation.js +4 -32
- package/lib/weapp/ParseLiveQuery.js +96 -505
- package/lib/weapp/ParseObject.js +628 -1840
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -63
- package/lib/weapp/ParseQuery.js +404 -1505
- package/lib/weapp/ParseRelation.js +12 -61
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -201
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -43
- package/lib/weapp/RESTController.js +18 -140
- package/lib/weapp/SingleInstanceStateController.js +19 -137
- package/lib/weapp/Socket.weapp.js +2 -12
- package/lib/weapp/Storage.js +10 -73
- package/lib/weapp/StorageController.browser.js +4 -17
- package/lib/weapp/StorageController.default.js +4 -17
- package/lib/weapp/StorageController.react-native.js +6 -33
- package/lib/weapp/StorageController.weapp.js +5 -16
- package/lib/weapp/TaskQueue.js +1 -22
- package/lib/weapp/UniqueInstanceStateController.js +19 -142
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -16
- package/lib/weapp/canBeSerialized.js +3 -33
- package/lib/weapp/decode.js +3 -33
- package/lib/weapp/encode.js +9 -70
- package/lib/weapp/equals.js +2 -25
- package/lib/weapp/escape.js +1 -8
- package/lib/weapp/isRevocableSession.js +2 -11
- package/lib/weapp/parseDate.js +2 -13
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -17
- package/lib/weapp/unsavedChildren.js +6 -50
- package/lib/weapp/uuid.js +1 -6
- package/package.json +45 -43
package/lib/node/ParseUser.js
CHANGED
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
9
|
-
|
|
10
8
|
var _isRevocableSession = _interopRequireDefault(require("./isRevocableSession"));
|
|
11
|
-
|
|
12
9
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
13
|
-
|
|
14
10
|
var _ParseObject = _interopRequireDefault(require("./ParseObject"));
|
|
15
|
-
|
|
16
11
|
var _ParseSession = _interopRequireDefault(require("./ParseSession"));
|
|
17
|
-
|
|
18
12
|
var _Storage = _interopRequireDefault(require("./Storage"));
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) {
|
|
21
14
|
return obj && obj.__esModule ? obj : {
|
|
22
15
|
default: obj
|
|
@@ -26,12 +19,12 @@ function _interopRequireDefault(obj) {
|
|
|
26
19
|
* @flow
|
|
27
20
|
*/
|
|
28
21
|
|
|
29
|
-
|
|
30
22
|
const CURRENT_USER_KEY = 'currentUser';
|
|
31
23
|
let canUseCurrentUser = !_CoreManager.default.get('IS_NODE');
|
|
32
24
|
let currentUserCacheMatchesDisk = false;
|
|
33
25
|
let currentUserCache = null;
|
|
34
26
|
const authProviders = {};
|
|
27
|
+
|
|
35
28
|
/**
|
|
36
29
|
* <p>A Parse.User object is a local representation of a user persisted to the
|
|
37
30
|
* Parse cloud. This class is a subclass of a Parse.Object, and retains the
|
|
@@ -42,22 +35,19 @@ const authProviders = {};
|
|
|
42
35
|
* @alias Parse.User
|
|
43
36
|
* @augments Parse.Object
|
|
44
37
|
*/
|
|
45
|
-
|
|
46
38
|
class ParseUser extends _ParseObject.default {
|
|
47
39
|
/**
|
|
48
40
|
* @param {object} attributes The initial set of data to store in the user.
|
|
49
41
|
*/
|
|
50
|
-
constructor(attributes
|
|
51
|
-
/*: ?AttributeMap*/
|
|
52
|
-
) {
|
|
42
|
+
constructor(attributes /*: ?AttributeMap*/) {
|
|
53
43
|
super('_User');
|
|
54
|
-
|
|
55
44
|
if (attributes && typeof attributes === 'object') {
|
|
56
45
|
if (!this.set(attributes || {})) {
|
|
57
46
|
throw new Error("Can't create an invalid Parse User");
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
49
|
}
|
|
50
|
+
|
|
61
51
|
/**
|
|
62
52
|
* Request a revocable session token to replace the older style of token.
|
|
63
53
|
*
|
|
@@ -65,24 +55,16 @@ class ParseUser extends _ParseObject.default {
|
|
|
65
55
|
* @returns {Promise} A promise that is resolved when the replacement
|
|
66
56
|
* token has been fetched.
|
|
67
57
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_upgradeToRevocableSession(options
|
|
71
|
-
/*: RequestOptions*/
|
|
72
|
-
)
|
|
73
|
-
/*: Promise<void>*/
|
|
74
|
-
{
|
|
58
|
+
_upgradeToRevocableSession(options /*: RequestOptions*/) /*: Promise<void>*/{
|
|
75
59
|
options = options || {};
|
|
76
60
|
const upgradeOptions = {};
|
|
77
|
-
|
|
78
61
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
79
62
|
upgradeOptions.useMasterKey = options.useMasterKey;
|
|
80
63
|
}
|
|
81
|
-
|
|
82
64
|
const controller = _CoreManager.default.getUserController();
|
|
83
|
-
|
|
84
65
|
return controller.upgradeToRevocableSession(this, upgradeOptions);
|
|
85
66
|
}
|
|
67
|
+
|
|
86
68
|
/**
|
|
87
69
|
* Parse allows you to link your users with {@link https://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication 3rd party authentication}, enabling
|
|
88
70
|
* your users to sign up or log into your application using their existing identities.
|
|
@@ -98,23 +80,11 @@ class ParseUser extends _ParseObject.default {
|
|
|
98
80
|
* @param {object} saveOpts useMasterKey / sessionToken
|
|
99
81
|
* @returns {Promise} A promise that is fulfilled with the user is linked
|
|
100
82
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
linkWith(provider
|
|
104
|
-
/*: any*/
|
|
105
|
-
, options
|
|
106
|
-
/*: { authData?: AuthData }*/
|
|
107
|
-
, saveOpts
|
|
108
|
-
/*:: ?: FullOptions*/
|
|
109
|
-
= {})
|
|
110
|
-
/*: Promise<ParseUser>*/
|
|
111
|
-
{
|
|
83
|
+
linkWith(provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/ = {}) /*: Promise<ParseUser>*/{
|
|
112
84
|
saveOpts.sessionToken = saveOpts.sessionToken || this.getSessionToken() || '';
|
|
113
85
|
let authType;
|
|
114
|
-
|
|
115
86
|
if (typeof provider === 'string') {
|
|
116
87
|
authType = provider;
|
|
117
|
-
|
|
118
88
|
if (authProviders[provider]) {
|
|
119
89
|
provider = authProviders[provider];
|
|
120
90
|
} else {
|
|
@@ -122,11 +92,9 @@ class ParseUser extends _ParseObject.default {
|
|
|
122
92
|
restoreAuthentication() {
|
|
123
93
|
return true;
|
|
124
94
|
},
|
|
125
|
-
|
|
126
95
|
getAuthType() {
|
|
127
96
|
return authType;
|
|
128
97
|
}
|
|
129
|
-
|
|
130
98
|
};
|
|
131
99
|
authProviders[authProvider.getAuthType()] = authProvider;
|
|
132
100
|
provider = authProvider;
|
|
@@ -134,18 +102,13 @@ class ParseUser extends _ParseObject.default {
|
|
|
134
102
|
} else {
|
|
135
103
|
authType = provider.getAuthType();
|
|
136
104
|
}
|
|
137
|
-
|
|
138
105
|
if (options && options.hasOwnProperty('authData')) {
|
|
139
106
|
const authData = this.get('authData') || {};
|
|
140
|
-
|
|
141
107
|
if (typeof authData !== 'object') {
|
|
142
108
|
throw new Error('Invalid type: authData field should be an object');
|
|
143
109
|
}
|
|
144
|
-
|
|
145
110
|
authData[authType] = options.authData;
|
|
146
|
-
|
|
147
111
|
const controller = _CoreManager.default.getUserController();
|
|
148
|
-
|
|
149
112
|
return controller.linkWith(this, authData, saveOpts);
|
|
150
113
|
} else {
|
|
151
114
|
return new Promise((resolve, reject) => {
|
|
@@ -166,6 +129,7 @@ class ParseUser extends _ParseObject.default {
|
|
|
166
129
|
});
|
|
167
130
|
}
|
|
168
131
|
}
|
|
132
|
+
|
|
169
133
|
/**
|
|
170
134
|
* @param provider
|
|
171
135
|
* @param options
|
|
@@ -173,93 +137,68 @@ class ParseUser extends _ParseObject.default {
|
|
|
173
137
|
* @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
|
|
174
138
|
* @returns {Promise}
|
|
175
139
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
_linkWith(provider
|
|
179
|
-
/*: any*/
|
|
180
|
-
, options
|
|
181
|
-
/*: { authData?: AuthData }*/
|
|
182
|
-
, saveOpts
|
|
183
|
-
/*:: ?: FullOptions*/
|
|
184
|
-
= {})
|
|
185
|
-
/*: Promise<ParseUser>*/
|
|
186
|
-
{
|
|
140
|
+
_linkWith(provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/ = {}) /*: Promise<ParseUser>*/{
|
|
187
141
|
return this.linkWith(provider, options, saveOpts);
|
|
188
142
|
}
|
|
143
|
+
|
|
189
144
|
/**
|
|
190
145
|
* Synchronizes auth data for a provider (e.g. puts the access token in the
|
|
191
146
|
* right place to be used by the Facebook SDK).
|
|
192
147
|
*
|
|
193
148
|
* @param provider
|
|
194
149
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
_synchronizeAuthData(provider
|
|
198
|
-
/*: string*/
|
|
199
|
-
) {
|
|
150
|
+
_synchronizeAuthData(provider /*: string*/) {
|
|
200
151
|
if (!this.isCurrent() || !provider) {
|
|
201
152
|
return;
|
|
202
153
|
}
|
|
203
|
-
|
|
204
154
|
let authType;
|
|
205
|
-
|
|
206
155
|
if (typeof provider === 'string') {
|
|
207
156
|
authType = provider;
|
|
208
157
|
provider = authProviders[authType];
|
|
209
158
|
} else {
|
|
210
159
|
authType = provider.getAuthType();
|
|
211
160
|
}
|
|
212
|
-
|
|
213
161
|
const authData = this.get('authData');
|
|
214
|
-
|
|
215
162
|
if (!provider || !authData || typeof authData !== 'object') {
|
|
216
163
|
return;
|
|
217
164
|
}
|
|
218
|
-
|
|
219
165
|
const success = provider.restoreAuthentication(authData[authType]);
|
|
220
|
-
|
|
221
166
|
if (!success) {
|
|
222
167
|
this._unlinkFrom(provider);
|
|
223
168
|
}
|
|
224
169
|
}
|
|
170
|
+
|
|
225
171
|
/**
|
|
226
172
|
* Synchronizes authData for all providers.
|
|
227
173
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
174
|
_synchronizeAllAuthData() {
|
|
231
175
|
const authData = this.get('authData');
|
|
232
|
-
|
|
233
176
|
if (typeof authData !== 'object') {
|
|
234
177
|
return;
|
|
235
178
|
}
|
|
236
|
-
|
|
237
179
|
for (const key in authData) {
|
|
238
180
|
this._synchronizeAuthData(key);
|
|
239
181
|
}
|
|
240
182
|
}
|
|
183
|
+
|
|
241
184
|
/**
|
|
242
185
|
* Removes null values from authData (which exist temporarily for unlinking)
|
|
243
186
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
187
|
_cleanupAuthData() {
|
|
247
188
|
if (!this.isCurrent()) {
|
|
248
189
|
return;
|
|
249
190
|
}
|
|
250
|
-
|
|
251
191
|
const authData = this.get('authData');
|
|
252
|
-
|
|
253
192
|
if (typeof authData !== 'object') {
|
|
254
193
|
return;
|
|
255
194
|
}
|
|
256
|
-
|
|
257
195
|
for (const key in authData) {
|
|
258
196
|
if (!authData[key]) {
|
|
259
197
|
delete authData[key];
|
|
260
198
|
}
|
|
261
199
|
}
|
|
262
200
|
}
|
|
201
|
+
|
|
263
202
|
/**
|
|
264
203
|
* Unlinks a user from a service.
|
|
265
204
|
*
|
|
@@ -268,213 +207,158 @@ class ParseUser extends _ParseObject.default {
|
|
|
268
207
|
* @returns {Promise} A promise that is fulfilled when the unlinking
|
|
269
208
|
* finishes.
|
|
270
209
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
_unlinkFrom(provider
|
|
274
|
-
/*: any*/
|
|
275
|
-
, options
|
|
276
|
-
/*:: ?: FullOptions*/
|
|
277
|
-
)
|
|
278
|
-
/*: Promise<ParseUser>*/
|
|
279
|
-
{
|
|
210
|
+
_unlinkFrom(provider /*: any*/, options /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
|
|
280
211
|
return this.linkWith(provider, {
|
|
281
212
|
authData: null
|
|
282
213
|
}, options).then(() => {
|
|
283
214
|
this._synchronizeAuthData(provider);
|
|
284
|
-
|
|
285
215
|
return Promise.resolve(this);
|
|
286
216
|
});
|
|
287
217
|
}
|
|
218
|
+
|
|
288
219
|
/**
|
|
289
220
|
* Checks whether a user is linked to a service.
|
|
290
221
|
*
|
|
291
222
|
* @param {object} provider service to link to
|
|
292
223
|
* @returns {boolean} true if link was successful
|
|
293
224
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
_isLinked(provider
|
|
297
|
-
/*: any*/
|
|
298
|
-
)
|
|
299
|
-
/*: boolean*/
|
|
300
|
-
{
|
|
225
|
+
_isLinked(provider /*: any*/) /*: boolean*/{
|
|
301
226
|
let authType;
|
|
302
|
-
|
|
303
227
|
if (typeof provider === 'string') {
|
|
304
228
|
authType = provider;
|
|
305
229
|
} else {
|
|
306
230
|
authType = provider.getAuthType();
|
|
307
231
|
}
|
|
308
|
-
|
|
309
232
|
const authData = this.get('authData') || {};
|
|
310
|
-
|
|
311
233
|
if (typeof authData !== 'object') {
|
|
312
234
|
return false;
|
|
313
235
|
}
|
|
314
|
-
|
|
315
236
|
return !!authData[authType];
|
|
316
237
|
}
|
|
238
|
+
|
|
317
239
|
/**
|
|
318
240
|
* Deauthenticates all providers.
|
|
319
241
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
242
|
_logOutWithAll() {
|
|
323
243
|
const authData = this.get('authData');
|
|
324
|
-
|
|
325
244
|
if (typeof authData !== 'object') {
|
|
326
245
|
return;
|
|
327
246
|
}
|
|
328
|
-
|
|
329
247
|
for (const key in authData) {
|
|
330
248
|
this._logOutWith(key);
|
|
331
249
|
}
|
|
332
250
|
}
|
|
251
|
+
|
|
333
252
|
/**
|
|
334
253
|
* Deauthenticates a single provider (e.g. removing access tokens from the
|
|
335
254
|
* Facebook SDK).
|
|
336
255
|
*
|
|
337
256
|
* @param {object} provider service to logout of
|
|
338
257
|
*/
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
_logOutWith(provider
|
|
342
|
-
/*: any*/
|
|
343
|
-
) {
|
|
258
|
+
_logOutWith(provider /*: any*/) {
|
|
344
259
|
if (!this.isCurrent()) {
|
|
345
260
|
return;
|
|
346
261
|
}
|
|
347
|
-
|
|
348
262
|
if (typeof provider === 'string') {
|
|
349
263
|
provider = authProviders[provider];
|
|
350
264
|
}
|
|
351
|
-
|
|
352
265
|
if (provider && provider.deauthenticate) {
|
|
353
266
|
provider.deauthenticate();
|
|
354
267
|
}
|
|
355
268
|
}
|
|
269
|
+
|
|
356
270
|
/**
|
|
357
271
|
* Class instance method used to maintain specific keys when a fetch occurs.
|
|
358
272
|
* Used to ensure that the session token is not lost.
|
|
359
273
|
*
|
|
360
274
|
* @returns {object} sessionToken
|
|
361
275
|
*/
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
_preserveFieldsOnFetch()
|
|
365
|
-
/*: AttributeMap*/
|
|
366
|
-
{
|
|
276
|
+
_preserveFieldsOnFetch() /*: AttributeMap*/{
|
|
367
277
|
return {
|
|
368
278
|
sessionToken: this.get('sessionToken')
|
|
369
279
|
};
|
|
370
280
|
}
|
|
281
|
+
|
|
371
282
|
/**
|
|
372
283
|
* Returns true if <code>current</code> would return this user.
|
|
373
284
|
*
|
|
374
285
|
* @returns {boolean} true if user is cached on disk
|
|
375
286
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
isCurrent()
|
|
379
|
-
/*: boolean*/
|
|
380
|
-
{
|
|
287
|
+
isCurrent() /*: boolean*/{
|
|
381
288
|
const current = ParseUser.current();
|
|
382
289
|
return !!current && current.id === this.id;
|
|
383
290
|
}
|
|
291
|
+
|
|
384
292
|
/**
|
|
385
293
|
* Returns true if <code>current</code> would return this user.
|
|
386
294
|
*
|
|
387
295
|
* @returns {Promise<boolean>} true if user is cached on disk
|
|
388
296
|
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
async isCurrentAsync()
|
|
392
|
-
/*: Promise<boolean>*/
|
|
393
|
-
{
|
|
297
|
+
async isCurrentAsync() /*: Promise<boolean>*/{
|
|
394
298
|
const current = await ParseUser.currentAsync();
|
|
395
299
|
return !!current && current.id === this.id;
|
|
396
300
|
}
|
|
301
|
+
|
|
397
302
|
/**
|
|
398
303
|
* Returns get("username").
|
|
399
304
|
*
|
|
400
305
|
* @returns {string}
|
|
401
306
|
*/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
getUsername()
|
|
405
|
-
/*: ?string*/
|
|
406
|
-
{
|
|
307
|
+
getUsername() /*: ?string*/{
|
|
407
308
|
const username = this.get('username');
|
|
408
|
-
|
|
409
309
|
if (username == null || typeof username === 'string') {
|
|
410
310
|
return username;
|
|
411
311
|
}
|
|
412
|
-
|
|
413
312
|
return '';
|
|
414
313
|
}
|
|
314
|
+
|
|
415
315
|
/**
|
|
416
316
|
* Calls set("username", username, options) and returns the result.
|
|
417
317
|
*
|
|
418
318
|
* @param {string} username
|
|
419
319
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
setUsername(username
|
|
423
|
-
/*: string*/
|
|
424
|
-
) {
|
|
320
|
+
setUsername(username /*: string*/) {
|
|
425
321
|
// Strip anonymity
|
|
426
322
|
const authData = this.get('authData');
|
|
427
|
-
|
|
428
323
|
if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) {
|
|
429
324
|
// We need to set anonymous to null instead of deleting it in order to remove it from Parse.
|
|
430
325
|
authData.anonymous = null;
|
|
431
326
|
}
|
|
432
|
-
|
|
433
327
|
this.set('username', username);
|
|
434
328
|
}
|
|
329
|
+
|
|
435
330
|
/**
|
|
436
331
|
* Calls set("password", password, options) and returns the result.
|
|
437
332
|
*
|
|
438
333
|
* @param {string} password User's Password
|
|
439
334
|
*/
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
setPassword(password
|
|
443
|
-
/*: string*/
|
|
444
|
-
) {
|
|
335
|
+
setPassword(password /*: string*/) {
|
|
445
336
|
this.set('password', password);
|
|
446
337
|
}
|
|
338
|
+
|
|
447
339
|
/**
|
|
448
340
|
* Returns get("email").
|
|
449
341
|
*
|
|
450
342
|
* @returns {string} User's Email
|
|
451
343
|
*/
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
getEmail()
|
|
455
|
-
/*: ?string*/
|
|
456
|
-
{
|
|
344
|
+
getEmail() /*: ?string*/{
|
|
457
345
|
const email = this.get('email');
|
|
458
|
-
|
|
459
346
|
if (email == null || typeof email === 'string') {
|
|
460
347
|
return email;
|
|
461
348
|
}
|
|
462
|
-
|
|
463
349
|
return '';
|
|
464
350
|
}
|
|
351
|
+
|
|
465
352
|
/**
|
|
466
353
|
* Calls set("email", email) and returns the result.
|
|
467
354
|
*
|
|
468
355
|
* @param {string} email
|
|
469
356
|
* @returns {boolean}
|
|
470
357
|
*/
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
setEmail(email
|
|
474
|
-
/*: string*/
|
|
475
|
-
) {
|
|
358
|
+
setEmail(email /*: string*/) {
|
|
476
359
|
return this.set('email', email);
|
|
477
360
|
}
|
|
361
|
+
|
|
478
362
|
/**
|
|
479
363
|
* Returns the session token for this user, if the user has been logged in,
|
|
480
364
|
* or if it is the result of a query with the master key. Otherwise, returns
|
|
@@ -482,32 +366,24 @@ class ParseUser extends _ParseObject.default {
|
|
|
482
366
|
*
|
|
483
367
|
* @returns {string} the session token, or undefined
|
|
484
368
|
*/
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
getSessionToken()
|
|
488
|
-
/*: ?string*/
|
|
489
|
-
{
|
|
369
|
+
getSessionToken() /*: ?string*/{
|
|
490
370
|
const token = this.get('sessionToken');
|
|
491
|
-
|
|
492
371
|
if (token == null || typeof token === 'string') {
|
|
493
372
|
return token;
|
|
494
373
|
}
|
|
495
|
-
|
|
496
374
|
return '';
|
|
497
375
|
}
|
|
376
|
+
|
|
498
377
|
/**
|
|
499
378
|
* Checks whether this user is the current user and has been authenticated.
|
|
500
379
|
*
|
|
501
380
|
* @returns {boolean} whether this user is the current user and is logged in.
|
|
502
381
|
*/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
authenticated()
|
|
506
|
-
/*: boolean*/
|
|
507
|
-
{
|
|
382
|
+
authenticated() /*: boolean*/{
|
|
508
383
|
const current = ParseUser.current();
|
|
509
384
|
return !!this.get('sessionToken') && !!current && current.id === this.id;
|
|
510
385
|
}
|
|
386
|
+
|
|
511
387
|
/**
|
|
512
388
|
* Signs up a new user. You should call this instead of save for
|
|
513
389
|
* new Parse.Users. This will create a new Parse.User on the server, and
|
|
@@ -521,34 +397,22 @@ class ParseUser extends _ParseObject.default {
|
|
|
521
397
|
* @returns {Promise} A promise that is fulfilled when the signup
|
|
522
398
|
* finishes.
|
|
523
399
|
*/
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
signUp(attrs
|
|
527
|
-
/*: AttributeMap*/
|
|
528
|
-
, options
|
|
529
|
-
/*:: ?: FullOptions*/
|
|
530
|
-
)
|
|
531
|
-
/*: Promise<ParseUser>*/
|
|
532
|
-
{
|
|
400
|
+
signUp(attrs /*: AttributeMap*/, options /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
|
|
533
401
|
options = options || {};
|
|
534
402
|
const signupOptions = {};
|
|
535
|
-
|
|
536
403
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
537
404
|
signupOptions.useMasterKey = options.useMasterKey;
|
|
538
405
|
}
|
|
539
|
-
|
|
540
406
|
if (options.hasOwnProperty('installationId')) {
|
|
541
407
|
signupOptions.installationId = options.installationId;
|
|
542
408
|
}
|
|
543
|
-
|
|
544
409
|
if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
|
|
545
410
|
signupOptions.context = options.context;
|
|
546
411
|
}
|
|
547
|
-
|
|
548
412
|
const controller = _CoreManager.default.getUserController();
|
|
549
|
-
|
|
550
413
|
return controller.signUp(this, attrs, signupOptions);
|
|
551
414
|
}
|
|
415
|
+
|
|
552
416
|
/**
|
|
553
417
|
* Logs in a Parse.User. On success, this saves the session to disk,
|
|
554
418
|
* so you can retrieve the currently logged in user using
|
|
@@ -560,34 +424,24 @@ class ParseUser extends _ParseObject.default {
|
|
|
560
424
|
* @returns {Promise} A promise that is fulfilled with the user when
|
|
561
425
|
* the login is complete.
|
|
562
426
|
*/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
logIn(options
|
|
566
|
-
/*:: ?: FullOptions*/
|
|
567
|
-
)
|
|
568
|
-
/*: Promise<ParseUser>*/
|
|
569
|
-
{
|
|
427
|
+
logIn(options /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
|
|
570
428
|
options = options || {};
|
|
571
429
|
const loginOptions = {
|
|
572
430
|
usePost: true
|
|
573
431
|
};
|
|
574
|
-
|
|
575
432
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
576
433
|
loginOptions.useMasterKey = options.useMasterKey;
|
|
577
434
|
}
|
|
578
|
-
|
|
579
435
|
if (options.hasOwnProperty('installationId')) {
|
|
580
436
|
loginOptions.installationId = options.installationId;
|
|
581
437
|
}
|
|
582
|
-
|
|
583
438
|
if (options.hasOwnProperty('usePost')) {
|
|
584
439
|
loginOptions.usePost = options.usePost;
|
|
585
440
|
}
|
|
586
|
-
|
|
587
441
|
const controller = _CoreManager.default.getUserController();
|
|
588
|
-
|
|
589
442
|
return controller.logIn(this, loginOptions);
|
|
590
443
|
}
|
|
444
|
+
|
|
591
445
|
/**
|
|
592
446
|
* Wrap the default save behavior with functionality to save to local
|
|
593
447
|
* storage if this is current user.
|
|
@@ -595,20 +449,15 @@ class ParseUser extends _ParseObject.default {
|
|
|
595
449
|
* @param {...any} args
|
|
596
450
|
* @returns {Promise}
|
|
597
451
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
async save(...args)
|
|
601
|
-
/*: Promise<ParseUser>*/
|
|
602
|
-
{
|
|
452
|
+
async save(...args /*: Array<any>*/) /*: Promise<ParseUser>*/{
|
|
603
453
|
await super.save.apply(this, args);
|
|
604
454
|
const current = await this.isCurrentAsync();
|
|
605
|
-
|
|
606
455
|
if (current) {
|
|
607
456
|
return _CoreManager.default.getUserController().updateUserOnDisk(this);
|
|
608
457
|
}
|
|
609
|
-
|
|
610
458
|
return this;
|
|
611
459
|
}
|
|
460
|
+
|
|
612
461
|
/**
|
|
613
462
|
* Wrap the default destroy behavior with functionality that logs out
|
|
614
463
|
* the current user when it is destroyed
|
|
@@ -616,20 +465,15 @@ class ParseUser extends _ParseObject.default {
|
|
|
616
465
|
* @param {...any} args
|
|
617
466
|
* @returns {Parse.User}
|
|
618
467
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
async destroy(...args)
|
|
622
|
-
/*: Promise<ParseUser>*/
|
|
623
|
-
{
|
|
468
|
+
async destroy(...args /*: Array<any>*/) /*: Promise<ParseUser>*/{
|
|
624
469
|
await super.destroy.apply(this, args);
|
|
625
470
|
const current = await this.isCurrentAsync();
|
|
626
|
-
|
|
627
471
|
if (current) {
|
|
628
472
|
return _CoreManager.default.getUserController().removeUserFromDisk();
|
|
629
473
|
}
|
|
630
|
-
|
|
631
474
|
return this;
|
|
632
475
|
}
|
|
476
|
+
|
|
633
477
|
/**
|
|
634
478
|
* Wrap the default fetch behavior with functionality to save to local
|
|
635
479
|
* storage if this is current user.
|
|
@@ -637,20 +481,15 @@ class ParseUser extends _ParseObject.default {
|
|
|
637
481
|
* @param {...any} args
|
|
638
482
|
* @returns {Parse.User}
|
|
639
483
|
*/
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
async fetch(...args)
|
|
643
|
-
/*: Promise<ParseUser>*/
|
|
644
|
-
{
|
|
484
|
+
async fetch(...args /*: Array<any>*/) /*: Promise<ParseUser>*/{
|
|
645
485
|
await super.fetch.apply(this, args);
|
|
646
486
|
const current = await this.isCurrentAsync();
|
|
647
|
-
|
|
648
487
|
if (current) {
|
|
649
488
|
return _CoreManager.default.getUserController().updateUserOnDisk(this);
|
|
650
489
|
}
|
|
651
|
-
|
|
652
490
|
return this;
|
|
653
491
|
}
|
|
492
|
+
|
|
654
493
|
/**
|
|
655
494
|
* Wrap the default fetchWithInclude behavior with functionality to save to local
|
|
656
495
|
* storage if this is current user.
|
|
@@ -658,20 +497,15 @@ class ParseUser extends _ParseObject.default {
|
|
|
658
497
|
* @param {...any} args
|
|
659
498
|
* @returns {Parse.User}
|
|
660
499
|
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
async fetchWithInclude(...args)
|
|
664
|
-
/*: Promise<ParseUser>*/
|
|
665
|
-
{
|
|
500
|
+
async fetchWithInclude(...args /*: Array<any>*/) /*: Promise<ParseUser>*/{
|
|
666
501
|
await super.fetchWithInclude.apply(this, args);
|
|
667
502
|
const current = await this.isCurrentAsync();
|
|
668
|
-
|
|
669
503
|
if (current) {
|
|
670
504
|
return _CoreManager.default.getUserController().updateUserOnDisk(this);
|
|
671
505
|
}
|
|
672
|
-
|
|
673
506
|
return this;
|
|
674
507
|
}
|
|
508
|
+
|
|
675
509
|
/**
|
|
676
510
|
* Verify whether a given password is the password of the current user.
|
|
677
511
|
*
|
|
@@ -680,22 +514,14 @@ class ParseUser extends _ParseObject.default {
|
|
|
680
514
|
* @returns {Promise} A promise that is fulfilled with a user
|
|
681
515
|
* when the password is correct.
|
|
682
516
|
*/
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
verifyPassword(password
|
|
686
|
-
/*: string*/
|
|
687
|
-
, options
|
|
688
|
-
/*:: ?: RequestOptions*/
|
|
689
|
-
)
|
|
690
|
-
/*: Promise<ParseUser>*/
|
|
691
|
-
{
|
|
517
|
+
verifyPassword(password /*: string*/, options /*:: ?: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
692
518
|
const username = this.getUsername() || '';
|
|
693
519
|
return ParseUser.verifyPassword(username, password, options);
|
|
694
520
|
}
|
|
695
|
-
|
|
696
521
|
static readOnlyAttributes() {
|
|
697
522
|
return ['sessionToken'];
|
|
698
523
|
}
|
|
524
|
+
|
|
699
525
|
/**
|
|
700
526
|
* Adds functionality to the existing Parse.User class.
|
|
701
527
|
*
|
|
@@ -704,13 +530,7 @@ class ParseUser extends _ParseObject.default {
|
|
|
704
530
|
* @static
|
|
705
531
|
* @returns {Parse.User} The newly extended Parse.User class
|
|
706
532
|
*/
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
static extend(protoProps
|
|
710
|
-
/*: { [prop: string]: any }*/
|
|
711
|
-
, classProps
|
|
712
|
-
/*: { [prop: string]: any }*/
|
|
713
|
-
) {
|
|
533
|
+
static extend(protoProps /*: { [prop: string]: any }*/, classProps /*: { [prop: string]: any }*/) {
|
|
714
534
|
if (protoProps) {
|
|
715
535
|
for (const prop in protoProps) {
|
|
716
536
|
if (prop !== 'className') {
|
|
@@ -723,7 +543,6 @@ class ParseUser extends _ParseObject.default {
|
|
|
723
543
|
}
|
|
724
544
|
}
|
|
725
545
|
}
|
|
726
|
-
|
|
727
546
|
if (classProps) {
|
|
728
547
|
for (const prop in classProps) {
|
|
729
548
|
if (prop !== 'className') {
|
|
@@ -736,9 +555,9 @@ class ParseUser extends _ParseObject.default {
|
|
|
736
555
|
}
|
|
737
556
|
}
|
|
738
557
|
}
|
|
739
|
-
|
|
740
558
|
return ParseUser;
|
|
741
559
|
}
|
|
560
|
+
|
|
742
561
|
/**
|
|
743
562
|
* Retrieves the currently logged in ParseUser with a valid session,
|
|
744
563
|
* either from memory or localStorage, if necessary.
|
|
@@ -746,19 +565,14 @@ class ParseUser extends _ParseObject.default {
|
|
|
746
565
|
* @static
|
|
747
566
|
* @returns {Parse.Object} The currently logged in Parse.User.
|
|
748
567
|
*/
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
static current()
|
|
752
|
-
/*: ?ParseUser*/
|
|
753
|
-
{
|
|
568
|
+
static current() /*: ?ParseUser*/{
|
|
754
569
|
if (!canUseCurrentUser) {
|
|
755
570
|
return null;
|
|
756
571
|
}
|
|
757
|
-
|
|
758
572
|
const controller = _CoreManager.default.getUserController();
|
|
759
|
-
|
|
760
573
|
return controller.currentUser();
|
|
761
574
|
}
|
|
575
|
+
|
|
762
576
|
/**
|
|
763
577
|
* Retrieves the currently logged in ParseUser from asynchronous Storage.
|
|
764
578
|
*
|
|
@@ -766,19 +580,14 @@ class ParseUser extends _ParseObject.default {
|
|
|
766
580
|
* @returns {Promise} A Promise that is resolved with the currently
|
|
767
581
|
* logged in Parse User
|
|
768
582
|
*/
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
static currentAsync()
|
|
772
|
-
/*: Promise<?ParseUser>*/
|
|
773
|
-
{
|
|
583
|
+
static currentAsync() /*: Promise<?ParseUser>*/{
|
|
774
584
|
if (!canUseCurrentUser) {
|
|
775
585
|
return Promise.resolve(null);
|
|
776
586
|
}
|
|
777
|
-
|
|
778
587
|
const controller = _CoreManager.default.getUserController();
|
|
779
|
-
|
|
780
588
|
return controller.currentUserAsync();
|
|
781
589
|
}
|
|
590
|
+
|
|
782
591
|
/**
|
|
783
592
|
* Signs up a new user with a username (or email) and password.
|
|
784
593
|
* This will create a new Parse.User on the server, and also persist the
|
|
@@ -793,23 +602,14 @@ class ParseUser extends _ParseObject.default {
|
|
|
793
602
|
* @returns {Promise} A promise that is fulfilled with the user when
|
|
794
603
|
* the signup completes.
|
|
795
604
|
*/
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
static signUp(username
|
|
799
|
-
/*: string*/
|
|
800
|
-
, password
|
|
801
|
-
/*: string*/
|
|
802
|
-
, attrs
|
|
803
|
-
/*: AttributeMap*/
|
|
804
|
-
, options
|
|
805
|
-
/*:: ?: FullOptions*/
|
|
806
|
-
) {
|
|
605
|
+
static signUp(username /*: string*/, password /*: string*/, attrs /*: AttributeMap*/, options /*:: ?: FullOptions*/) {
|
|
807
606
|
attrs = attrs || {};
|
|
808
607
|
attrs.username = username;
|
|
809
608
|
attrs.password = password;
|
|
810
609
|
const user = new this(attrs);
|
|
811
610
|
return user.signUp({}, options);
|
|
812
611
|
}
|
|
612
|
+
|
|
813
613
|
/**
|
|
814
614
|
* Logs in a user with a username (or email) and password. On success, this
|
|
815
615
|
* saves the session to disk, so you can retrieve the currently logged in
|
|
@@ -822,30 +622,20 @@ class ParseUser extends _ParseObject.default {
|
|
|
822
622
|
* @returns {Promise} A promise that is fulfilled with the user when
|
|
823
623
|
* the login completes.
|
|
824
624
|
*/
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
static logIn(username
|
|
828
|
-
/*: string*/
|
|
829
|
-
, password
|
|
830
|
-
/*: string*/
|
|
831
|
-
, options
|
|
832
|
-
/*:: ?: FullOptions*/
|
|
833
|
-
) {
|
|
625
|
+
static logIn(username /*: string*/, password /*: string*/, options /*:: ?: FullOptions*/) {
|
|
834
626
|
if (typeof username !== 'string') {
|
|
835
627
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
|
|
836
628
|
} else if (typeof password !== 'string') {
|
|
837
629
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
|
|
838
630
|
}
|
|
839
|
-
|
|
840
631
|
const user = new this();
|
|
841
|
-
|
|
842
632
|
user._finishFetch({
|
|
843
633
|
username: username,
|
|
844
634
|
password: password
|
|
845
635
|
});
|
|
846
|
-
|
|
847
636
|
return user.logIn(options);
|
|
848
637
|
}
|
|
638
|
+
|
|
849
639
|
/**
|
|
850
640
|
* Logs in a user with a session token. On success, this saves the session
|
|
851
641
|
* to disk, so you can retrieve the currently logged in user using
|
|
@@ -857,33 +647,22 @@ class ParseUser extends _ParseObject.default {
|
|
|
857
647
|
* @returns {Promise} A promise that is fulfilled with the user when
|
|
858
648
|
* the login completes.
|
|
859
649
|
*/
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
static become(sessionToken
|
|
863
|
-
/*: string*/
|
|
864
|
-
, options
|
|
865
|
-
/*:: ?: RequestOptions*/
|
|
866
|
-
) {
|
|
650
|
+
static become(sessionToken /*: string*/, options /*:: ?: RequestOptions*/) {
|
|
867
651
|
if (!canUseCurrentUser) {
|
|
868
652
|
throw new Error('It is not memory-safe to become a user in a server environment');
|
|
869
653
|
}
|
|
870
|
-
|
|
871
654
|
options = options || {};
|
|
872
|
-
const becomeOptions
|
|
873
|
-
/*: RequestOptions*/
|
|
874
|
-
= {
|
|
655
|
+
const becomeOptions /*: RequestOptions*/ = {
|
|
875
656
|
sessionToken: sessionToken
|
|
876
657
|
};
|
|
877
|
-
|
|
878
658
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
879
659
|
becomeOptions.useMasterKey = options.useMasterKey;
|
|
880
660
|
}
|
|
881
|
-
|
|
882
661
|
const controller = _CoreManager.default.getUserController();
|
|
883
|
-
|
|
884
662
|
const user = new this();
|
|
885
663
|
return controller.become(user, becomeOptions);
|
|
886
664
|
}
|
|
665
|
+
|
|
887
666
|
/**
|
|
888
667
|
* Retrieves a user with a session token.
|
|
889
668
|
*
|
|
@@ -892,28 +671,18 @@ class ParseUser extends _ParseObject.default {
|
|
|
892
671
|
* @static
|
|
893
672
|
* @returns {Promise} A promise that is fulfilled with the user is fetched.
|
|
894
673
|
*/
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
static me(sessionToken
|
|
898
|
-
/*: string*/
|
|
899
|
-
, options
|
|
900
|
-
/*:: ?: RequestOptions*/
|
|
901
|
-
= {}) {
|
|
674
|
+
static me(sessionToken /*: string*/, options /*:: ?: RequestOptions*/ = {}) {
|
|
902
675
|
const controller = _CoreManager.default.getUserController();
|
|
903
|
-
|
|
904
|
-
const meOptions
|
|
905
|
-
/*: RequestOptions*/
|
|
906
|
-
= {
|
|
676
|
+
const meOptions /*: RequestOptions*/ = {
|
|
907
677
|
sessionToken: sessionToken
|
|
908
678
|
};
|
|
909
|
-
|
|
910
679
|
if (options.useMasterKey) {
|
|
911
680
|
meOptions.useMasterKey = options.useMasterKey;
|
|
912
681
|
}
|
|
913
|
-
|
|
914
682
|
const user = new this();
|
|
915
683
|
return controller.me(user, meOptions);
|
|
916
684
|
}
|
|
685
|
+
|
|
917
686
|
/**
|
|
918
687
|
* Logs in a user with a session token. On success, this saves the session
|
|
919
688
|
* to disk, so you can retrieve the currently logged in user using
|
|
@@ -924,16 +693,12 @@ class ParseUser extends _ParseObject.default {
|
|
|
924
693
|
* @returns {Promise} A promise that is fulfilled with the user when
|
|
925
694
|
* the login completes.
|
|
926
695
|
*/
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
static hydrate(userJSON
|
|
930
|
-
/*: AttributeMap*/
|
|
931
|
-
) {
|
|
696
|
+
static hydrate(userJSON /*: AttributeMap*/) {
|
|
932
697
|
const controller = _CoreManager.default.getUserController();
|
|
933
|
-
|
|
934
698
|
const user = new this();
|
|
935
699
|
return controller.hydrate(user, userJSON);
|
|
936
700
|
}
|
|
701
|
+
|
|
937
702
|
/**
|
|
938
703
|
* Static version of {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
|
|
939
704
|
*
|
|
@@ -943,20 +708,11 @@ class ParseUser extends _ParseObject.default {
|
|
|
943
708
|
* @static
|
|
944
709
|
* @returns {Promise}
|
|
945
710
|
*/
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
static logInWith(provider
|
|
949
|
-
/*: any*/
|
|
950
|
-
, options
|
|
951
|
-
/*: { authData?: AuthData }*/
|
|
952
|
-
, saveOpts
|
|
953
|
-
/*:: ?: FullOptions*/
|
|
954
|
-
)
|
|
955
|
-
/*: Promise<ParseUser>*/
|
|
956
|
-
{
|
|
711
|
+
static logInWith(provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
|
|
957
712
|
const user = new this();
|
|
958
713
|
return user.linkWith(provider, options, saveOpts);
|
|
959
714
|
}
|
|
715
|
+
|
|
960
716
|
/**
|
|
961
717
|
* Logs out the currently logged in user session. This will remove the
|
|
962
718
|
* session from disk, log out of linked services, and future calls to
|
|
@@ -967,15 +723,11 @@ class ParseUser extends _ParseObject.default {
|
|
|
967
723
|
* @returns {Promise} A promise that is resolved when the session is
|
|
968
724
|
* destroyed on the server.
|
|
969
725
|
*/
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
static logOut(options
|
|
973
|
-
/*: RequestOptions*/
|
|
974
|
-
= {}) {
|
|
726
|
+
static logOut(options /*: RequestOptions*/ = {}) {
|
|
975
727
|
const controller = _CoreManager.default.getUserController();
|
|
976
|
-
|
|
977
728
|
return controller.logOut(options);
|
|
978
729
|
}
|
|
730
|
+
|
|
979
731
|
/**
|
|
980
732
|
* Requests a password reset email to be sent to the specified email address
|
|
981
733
|
* associated with the user account. This email allows the user to securely
|
|
@@ -987,24 +739,16 @@ class ParseUser extends _ParseObject.default {
|
|
|
987
739
|
* @static
|
|
988
740
|
* @returns {Promise}
|
|
989
741
|
*/
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
static requestPasswordReset(email
|
|
993
|
-
/*: string*/
|
|
994
|
-
, options
|
|
995
|
-
/*:: ?: RequestOptions*/
|
|
996
|
-
) {
|
|
742
|
+
static requestPasswordReset(email /*: string*/, options /*:: ?: RequestOptions*/) {
|
|
997
743
|
options = options || {};
|
|
998
744
|
const requestOptions = {};
|
|
999
|
-
|
|
1000
745
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1001
746
|
requestOptions.useMasterKey = options.useMasterKey;
|
|
1002
747
|
}
|
|
1003
|
-
|
|
1004
748
|
const controller = _CoreManager.default.getUserController();
|
|
1005
|
-
|
|
1006
749
|
return controller.requestPasswordReset(email, requestOptions);
|
|
1007
750
|
}
|
|
751
|
+
|
|
1008
752
|
/**
|
|
1009
753
|
* Request an email verification.
|
|
1010
754
|
*
|
|
@@ -1014,24 +758,16 @@ class ParseUser extends _ParseObject.default {
|
|
|
1014
758
|
* @static
|
|
1015
759
|
* @returns {Promise}
|
|
1016
760
|
*/
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
static requestEmailVerification(email
|
|
1020
|
-
/*: string*/
|
|
1021
|
-
, options
|
|
1022
|
-
/*:: ?: RequestOptions*/
|
|
1023
|
-
) {
|
|
761
|
+
static requestEmailVerification(email /*: string*/, options /*:: ?: RequestOptions*/) {
|
|
1024
762
|
options = options || {};
|
|
1025
763
|
const requestOptions = {};
|
|
1026
|
-
|
|
1027
764
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1028
765
|
requestOptions.useMasterKey = options.useMasterKey;
|
|
1029
766
|
}
|
|
1030
|
-
|
|
1031
767
|
const controller = _CoreManager.default.getUserController();
|
|
1032
|
-
|
|
1033
768
|
return controller.requestEmailVerification(email, requestOptions);
|
|
1034
769
|
}
|
|
770
|
+
|
|
1035
771
|
/**
|
|
1036
772
|
* Verify whether a given password is the password of the current user.
|
|
1037
773
|
*
|
|
@@ -1042,34 +778,22 @@ class ParseUser extends _ParseObject.default {
|
|
|
1042
778
|
* @returns {Promise} A promise that is fulfilled with a user
|
|
1043
779
|
* when the password is correct.
|
|
1044
780
|
*/
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
static verifyPassword(username
|
|
1048
|
-
/*: string*/
|
|
1049
|
-
, password
|
|
1050
|
-
/*: string*/
|
|
1051
|
-
, options
|
|
1052
|
-
/*:: ?: RequestOptions*/
|
|
1053
|
-
) {
|
|
781
|
+
static verifyPassword(username /*: string*/, password /*: string*/, options /*:: ?: RequestOptions*/) {
|
|
1054
782
|
if (typeof username !== 'string') {
|
|
1055
783
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
|
|
1056
784
|
}
|
|
1057
|
-
|
|
1058
785
|
if (typeof password !== 'string') {
|
|
1059
786
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
|
|
1060
787
|
}
|
|
1061
|
-
|
|
1062
788
|
options = options || {};
|
|
1063
789
|
const verificationOption = {};
|
|
1064
|
-
|
|
1065
790
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1066
791
|
verificationOption.useMasterKey = options.useMasterKey;
|
|
1067
792
|
}
|
|
1068
|
-
|
|
1069
793
|
const controller = _CoreManager.default.getUserController();
|
|
1070
|
-
|
|
1071
794
|
return controller.verifyPassword(username, password, verificationOption);
|
|
1072
795
|
}
|
|
796
|
+
|
|
1073
797
|
/**
|
|
1074
798
|
* Allow someone to define a custom User class without className
|
|
1075
799
|
* being rewritten to _User. The default behavior is to rewrite
|
|
@@ -1079,13 +803,10 @@ class ParseUser extends _ParseObject.default {
|
|
|
1079
803
|
* @param {boolean} isAllowed Whether or not to allow custom User class
|
|
1080
804
|
* @static
|
|
1081
805
|
*/
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
static allowCustomUserClass(isAllowed
|
|
1085
|
-
/*: boolean*/
|
|
1086
|
-
) {
|
|
806
|
+
static allowCustomUserClass(isAllowed /*: boolean*/) {
|
|
1087
807
|
_CoreManager.default.set('PERFORM_USER_REWRITE', !isAllowed);
|
|
1088
808
|
}
|
|
809
|
+
|
|
1089
810
|
/**
|
|
1090
811
|
* Allows a legacy application to start using revocable sessions. If the
|
|
1091
812
|
* current session token is not revocable, a request will be made for a new,
|
|
@@ -1100,25 +821,18 @@ class ParseUser extends _ParseObject.default {
|
|
|
1100
821
|
* completed. If a replacement session token is requested, the promise
|
|
1101
822
|
* will be resolved after a new token has been fetched.
|
|
1102
823
|
*/
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
static enableRevocableSession(options
|
|
1106
|
-
/*:: ?: RequestOptions*/
|
|
1107
|
-
) {
|
|
824
|
+
static enableRevocableSession(options /*:: ?: RequestOptions*/) {
|
|
1108
825
|
options = options || {};
|
|
1109
|
-
|
|
1110
826
|
_CoreManager.default.set('FORCE_REVOCABLE_SESSION', true);
|
|
1111
|
-
|
|
1112
827
|
if (canUseCurrentUser) {
|
|
1113
828
|
const current = ParseUser.current();
|
|
1114
|
-
|
|
1115
829
|
if (current) {
|
|
1116
830
|
return current._upgradeToRevocableSession(options);
|
|
1117
831
|
}
|
|
1118
832
|
}
|
|
1119
|
-
|
|
1120
833
|
return Promise.resolve();
|
|
1121
834
|
}
|
|
835
|
+
|
|
1122
836
|
/**
|
|
1123
837
|
* Enables the use of become or the current user in a server
|
|
1124
838
|
* environment. These features are disabled by default, since they depend on
|
|
@@ -1126,11 +840,10 @@ class ParseUser extends _ParseObject.default {
|
|
|
1126
840
|
*
|
|
1127
841
|
* @static
|
|
1128
842
|
*/
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
843
|
static enableUnsafeCurrentUser() {
|
|
1132
844
|
canUseCurrentUser = true;
|
|
1133
845
|
}
|
|
846
|
+
|
|
1134
847
|
/**
|
|
1135
848
|
* Disables the use of become or the current user in any environment.
|
|
1136
849
|
* These features are disabled on servers by default, since they depend on
|
|
@@ -1138,11 +851,10 @@ class ParseUser extends _ParseObject.default {
|
|
|
1138
851
|
*
|
|
1139
852
|
* @static
|
|
1140
853
|
*/
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
854
|
static disableUnsafeCurrentUser() {
|
|
1144
855
|
canUseCurrentUser = false;
|
|
1145
856
|
}
|
|
857
|
+
|
|
1146
858
|
/**
|
|
1147
859
|
* When registering users with {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith} a basic auth provider
|
|
1148
860
|
* is automatically created for you.
|
|
@@ -1155,19 +867,16 @@ class ParseUser extends _ParseObject.default {
|
|
|
1155
867
|
* @see {@link https://docs.parseplatform.org/js/guide/#custom-authentication-module Custom Authentication Module}
|
|
1156
868
|
* @static
|
|
1157
869
|
*/
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
/*: any*/
|
|
1162
|
-
) {
|
|
1163
|
-
authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider.
|
|
1164
|
-
|
|
870
|
+
static _registerAuthenticationProvider(provider /*: any*/) {
|
|
871
|
+
authProviders[provider.getAuthType()] = provider;
|
|
872
|
+
// Synchronize the current user with the auth provider.
|
|
1165
873
|
ParseUser.currentAsync().then(current => {
|
|
1166
874
|
if (current) {
|
|
1167
875
|
current._synchronizeAuthData(provider.getAuthType());
|
|
1168
876
|
}
|
|
1169
877
|
});
|
|
1170
878
|
}
|
|
879
|
+
|
|
1171
880
|
/**
|
|
1172
881
|
* @param provider
|
|
1173
882
|
* @param options
|
|
@@ -1176,330 +885,200 @@ class ParseUser extends _ParseObject.default {
|
|
|
1176
885
|
* @static
|
|
1177
886
|
* @returns {Promise}
|
|
1178
887
|
*/
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
static _logInWith(provider
|
|
1182
|
-
/*: any*/
|
|
1183
|
-
, options
|
|
1184
|
-
/*: { authData?: AuthData }*/
|
|
1185
|
-
, saveOpts
|
|
1186
|
-
/*:: ?: FullOptions*/
|
|
1187
|
-
) {
|
|
888
|
+
static _logInWith(provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/) {
|
|
1188
889
|
const user = new this();
|
|
1189
890
|
return user.linkWith(provider, options, saveOpts);
|
|
1190
891
|
}
|
|
1191
|
-
|
|
1192
892
|
static _clearCache() {
|
|
1193
893
|
currentUserCache = null;
|
|
1194
894
|
currentUserCacheMatchesDisk = false;
|
|
1195
895
|
}
|
|
1196
|
-
|
|
1197
|
-
static _setCurrentUserCache(user
|
|
1198
|
-
/*: ParseUser*/
|
|
1199
|
-
) {
|
|
896
|
+
static _setCurrentUserCache(user /*: ParseUser*/) {
|
|
1200
897
|
currentUserCache = user;
|
|
1201
898
|
}
|
|
1202
|
-
|
|
1203
899
|
}
|
|
1204
|
-
|
|
1205
900
|
_ParseObject.default.registerSubclass('_User', ParseUser);
|
|
1206
|
-
|
|
1207
901
|
const DefaultController = {
|
|
1208
902
|
updateUserOnDisk(user) {
|
|
1209
903
|
const path = _Storage.default.generatePath(CURRENT_USER_KEY);
|
|
1210
|
-
|
|
1211
904
|
const json = user.toJSON();
|
|
1212
905
|
delete json.password;
|
|
1213
906
|
json.className = '_User';
|
|
1214
907
|
let userData = JSON.stringify(json);
|
|
1215
|
-
|
|
1216
908
|
if (_CoreManager.default.get('ENCRYPTED_USER')) {
|
|
1217
909
|
const crypto = _CoreManager.default.getCryptoController();
|
|
1218
|
-
|
|
1219
910
|
userData = crypto.encrypt(json, _CoreManager.default.get('ENCRYPTED_KEY'));
|
|
1220
911
|
}
|
|
1221
|
-
|
|
1222
912
|
return _Storage.default.setItemAsync(path, userData).then(() => {
|
|
1223
913
|
return user;
|
|
1224
914
|
});
|
|
1225
915
|
},
|
|
1226
|
-
|
|
1227
916
|
removeUserFromDisk() {
|
|
1228
917
|
const path = _Storage.default.generatePath(CURRENT_USER_KEY);
|
|
1229
|
-
|
|
1230
918
|
currentUserCacheMatchesDisk = true;
|
|
1231
919
|
currentUserCache = null;
|
|
1232
920
|
return _Storage.default.removeItemAsync(path);
|
|
1233
921
|
},
|
|
1234
|
-
|
|
1235
922
|
setCurrentUser(user) {
|
|
1236
923
|
currentUserCache = user;
|
|
1237
|
-
|
|
1238
924
|
user._cleanupAuthData();
|
|
1239
|
-
|
|
1240
925
|
user._synchronizeAllAuthData();
|
|
1241
|
-
|
|
1242
926
|
return DefaultController.updateUserOnDisk(user);
|
|
1243
927
|
},
|
|
1244
|
-
|
|
1245
|
-
currentUser()
|
|
1246
|
-
/*: ?ParseUser*/
|
|
1247
|
-
{
|
|
928
|
+
currentUser() /*: ?ParseUser*/{
|
|
1248
929
|
if (currentUserCache) {
|
|
1249
930
|
return currentUserCache;
|
|
1250
931
|
}
|
|
1251
|
-
|
|
1252
932
|
if (currentUserCacheMatchesDisk) {
|
|
1253
933
|
return null;
|
|
1254
934
|
}
|
|
1255
|
-
|
|
1256
935
|
if (_Storage.default.async()) {
|
|
1257
936
|
throw new Error('Cannot call currentUser() when using a platform with an async ' + 'storage system. Call currentUserAsync() instead.');
|
|
1258
937
|
}
|
|
1259
|
-
|
|
1260
938
|
const path = _Storage.default.generatePath(CURRENT_USER_KEY);
|
|
1261
|
-
|
|
1262
939
|
let userData = _Storage.default.getItem(path);
|
|
1263
|
-
|
|
1264
940
|
currentUserCacheMatchesDisk = true;
|
|
1265
|
-
|
|
1266
941
|
if (!userData) {
|
|
1267
942
|
currentUserCache = null;
|
|
1268
943
|
return null;
|
|
1269
944
|
}
|
|
1270
|
-
|
|
1271
945
|
if (_CoreManager.default.get('ENCRYPTED_USER')) {
|
|
1272
946
|
const crypto = _CoreManager.default.getCryptoController();
|
|
1273
|
-
|
|
1274
947
|
userData = crypto.decrypt(userData, _CoreManager.default.get('ENCRYPTED_KEY'));
|
|
1275
948
|
}
|
|
1276
|
-
|
|
1277
949
|
userData = JSON.parse(userData);
|
|
1278
|
-
|
|
1279
950
|
if (!userData.className) {
|
|
1280
951
|
userData.className = '_User';
|
|
1281
952
|
}
|
|
1282
|
-
|
|
1283
953
|
if (userData._id) {
|
|
1284
954
|
if (userData.objectId !== userData._id) {
|
|
1285
955
|
userData.objectId = userData._id;
|
|
1286
956
|
}
|
|
1287
|
-
|
|
1288
957
|
delete userData._id;
|
|
1289
958
|
}
|
|
1290
|
-
|
|
1291
959
|
if (userData._sessionToken) {
|
|
1292
960
|
userData.sessionToken = userData._sessionToken;
|
|
1293
961
|
delete userData._sessionToken;
|
|
1294
962
|
}
|
|
1295
|
-
|
|
1296
963
|
const current = _ParseObject.default.fromJSON(userData);
|
|
1297
|
-
|
|
1298
964
|
currentUserCache = current;
|
|
1299
|
-
|
|
1300
965
|
current._synchronizeAllAuthData();
|
|
1301
|
-
|
|
1302
966
|
return current;
|
|
1303
967
|
},
|
|
1304
|
-
|
|
1305
|
-
currentUserAsync()
|
|
1306
|
-
/*: Promise<?ParseUser>*/
|
|
1307
|
-
{
|
|
968
|
+
currentUserAsync() /*: Promise<?ParseUser>*/{
|
|
1308
969
|
if (currentUserCache) {
|
|
1309
970
|
return Promise.resolve(currentUserCache);
|
|
1310
971
|
}
|
|
1311
|
-
|
|
1312
972
|
if (currentUserCacheMatchesDisk) {
|
|
1313
973
|
return Promise.resolve(null);
|
|
1314
974
|
}
|
|
1315
|
-
|
|
1316
975
|
const path = _Storage.default.generatePath(CURRENT_USER_KEY);
|
|
1317
|
-
|
|
1318
976
|
return _Storage.default.getItemAsync(path).then(userData => {
|
|
1319
977
|
currentUserCacheMatchesDisk = true;
|
|
1320
|
-
|
|
1321
978
|
if (!userData) {
|
|
1322
979
|
currentUserCache = null;
|
|
1323
980
|
return Promise.resolve(null);
|
|
1324
981
|
}
|
|
1325
|
-
|
|
1326
982
|
if (_CoreManager.default.get('ENCRYPTED_USER')) {
|
|
1327
983
|
const crypto = _CoreManager.default.getCryptoController();
|
|
1328
|
-
|
|
1329
984
|
userData = crypto.decrypt(userData.toString(), _CoreManager.default.get('ENCRYPTED_KEY'));
|
|
1330
985
|
}
|
|
1331
|
-
|
|
1332
986
|
userData = JSON.parse(userData);
|
|
1333
|
-
|
|
1334
987
|
if (!userData.className) {
|
|
1335
988
|
userData.className = '_User';
|
|
1336
989
|
}
|
|
1337
|
-
|
|
1338
990
|
if (userData._id) {
|
|
1339
991
|
if (userData.objectId !== userData._id) {
|
|
1340
992
|
userData.objectId = userData._id;
|
|
1341
993
|
}
|
|
1342
|
-
|
|
1343
994
|
delete userData._id;
|
|
1344
995
|
}
|
|
1345
|
-
|
|
1346
996
|
if (userData._sessionToken) {
|
|
1347
997
|
userData.sessionToken = userData._sessionToken;
|
|
1348
998
|
delete userData._sessionToken;
|
|
1349
999
|
}
|
|
1350
|
-
|
|
1351
1000
|
const current = _ParseObject.default.fromJSON(userData);
|
|
1352
|
-
|
|
1353
1001
|
currentUserCache = current;
|
|
1354
|
-
|
|
1355
1002
|
current._synchronizeAllAuthData();
|
|
1356
|
-
|
|
1357
1003
|
return Promise.resolve(current);
|
|
1358
1004
|
});
|
|
1359
1005
|
},
|
|
1360
|
-
|
|
1361
|
-
signUp(user
|
|
1362
|
-
/*: ParseUser*/
|
|
1363
|
-
, attrs
|
|
1364
|
-
/*: AttributeMap*/
|
|
1365
|
-
, options
|
|
1366
|
-
/*: RequestOptions*/
|
|
1367
|
-
)
|
|
1368
|
-
/*: Promise<ParseUser>*/
|
|
1369
|
-
{
|
|
1006
|
+
signUp(user /*: ParseUser*/, attrs /*: AttributeMap*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
1370
1007
|
const username = attrs && attrs.username || user.get('username');
|
|
1371
1008
|
const password = attrs && attrs.password || user.get('password');
|
|
1372
|
-
|
|
1373
1009
|
if (!username || !username.length) {
|
|
1374
1010
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty username.'));
|
|
1375
1011
|
}
|
|
1376
|
-
|
|
1377
1012
|
if (!password || !password.length) {
|
|
1378
1013
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty password.'));
|
|
1379
1014
|
}
|
|
1380
|
-
|
|
1381
1015
|
return user.save(attrs, options).then(() => {
|
|
1382
1016
|
// Clear the password field
|
|
1383
1017
|
user._finishFetch({
|
|
1384
1018
|
password: undefined
|
|
1385
1019
|
});
|
|
1386
|
-
|
|
1387
1020
|
if (canUseCurrentUser) {
|
|
1388
1021
|
return DefaultController.setCurrentUser(user);
|
|
1389
1022
|
}
|
|
1390
|
-
|
|
1391
1023
|
return user;
|
|
1392
1024
|
});
|
|
1393
1025
|
},
|
|
1394
|
-
|
|
1395
|
-
logIn(user
|
|
1396
|
-
/*: ParseUser*/
|
|
1397
|
-
, options
|
|
1398
|
-
/*: RequestOptions*/
|
|
1399
|
-
)
|
|
1400
|
-
/*: Promise<ParseUser>*/
|
|
1401
|
-
{
|
|
1026
|
+
logIn(user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
1402
1027
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1403
|
-
|
|
1404
1028
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
1405
|
-
|
|
1406
1029
|
const auth = {
|
|
1407
1030
|
username: user.get('username'),
|
|
1408
1031
|
password: user.get('password')
|
|
1409
1032
|
};
|
|
1410
1033
|
return RESTController.request(options.usePost ? 'POST' : 'GET', 'login', auth, options).then(response => {
|
|
1411
1034
|
user._migrateId(response.objectId);
|
|
1412
|
-
|
|
1413
1035
|
user._setExisted(true);
|
|
1414
|
-
|
|
1415
1036
|
stateController.setPendingOp(user._getStateIdentifier(), 'username', undefined);
|
|
1416
1037
|
stateController.setPendingOp(user._getStateIdentifier(), 'password', undefined);
|
|
1417
1038
|
response.password = undefined;
|
|
1418
|
-
|
|
1419
1039
|
user._finishFetch(response);
|
|
1420
|
-
|
|
1421
1040
|
if (!canUseCurrentUser) {
|
|
1422
1041
|
// We can't set the current user, so just return the one we logged in
|
|
1423
1042
|
return Promise.resolve(user);
|
|
1424
1043
|
}
|
|
1425
|
-
|
|
1426
1044
|
return DefaultController.setCurrentUser(user);
|
|
1427
1045
|
});
|
|
1428
1046
|
},
|
|
1429
|
-
|
|
1430
|
-
become(user
|
|
1431
|
-
/*: ParseUser*/
|
|
1432
|
-
, options
|
|
1433
|
-
/*: RequestOptions*/
|
|
1434
|
-
)
|
|
1435
|
-
/*: Promise<ParseUser>*/
|
|
1436
|
-
{
|
|
1047
|
+
become(user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
1437
1048
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1438
|
-
|
|
1439
1049
|
return RESTController.request('GET', 'users/me', {}, options).then(response => {
|
|
1440
1050
|
user._finishFetch(response);
|
|
1441
|
-
|
|
1442
1051
|
user._setExisted(true);
|
|
1443
|
-
|
|
1444
1052
|
return DefaultController.setCurrentUser(user);
|
|
1445
1053
|
});
|
|
1446
1054
|
},
|
|
1447
|
-
|
|
1448
|
-
hydrate(user
|
|
1449
|
-
/*: ParseUser*/
|
|
1450
|
-
, userJSON
|
|
1451
|
-
/*: AttributeMap*/
|
|
1452
|
-
)
|
|
1453
|
-
/*: Promise<ParseUser>*/
|
|
1454
|
-
{
|
|
1055
|
+
hydrate(user /*: ParseUser*/, userJSON /*: AttributeMap*/) /*: Promise<ParseUser>*/{
|
|
1455
1056
|
user._finishFetch(userJSON);
|
|
1456
|
-
|
|
1457
1057
|
user._setExisted(true);
|
|
1458
|
-
|
|
1459
1058
|
if (userJSON.sessionToken && canUseCurrentUser) {
|
|
1460
1059
|
return DefaultController.setCurrentUser(user);
|
|
1461
1060
|
} else {
|
|
1462
1061
|
return Promise.resolve(user);
|
|
1463
1062
|
}
|
|
1464
1063
|
},
|
|
1465
|
-
|
|
1466
|
-
me(user
|
|
1467
|
-
/*: ParseUser*/
|
|
1468
|
-
, options
|
|
1469
|
-
/*: RequestOptions*/
|
|
1470
|
-
)
|
|
1471
|
-
/*: Promise<ParseUser>*/
|
|
1472
|
-
{
|
|
1064
|
+
me(user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
1473
1065
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1474
|
-
|
|
1475
1066
|
return RESTController.request('GET', 'users/me', {}, options).then(response => {
|
|
1476
1067
|
user._finishFetch(response);
|
|
1477
|
-
|
|
1478
1068
|
user._setExisted(true);
|
|
1479
|
-
|
|
1480
1069
|
return user;
|
|
1481
1070
|
});
|
|
1482
1071
|
},
|
|
1483
|
-
|
|
1484
|
-
logOut(options
|
|
1485
|
-
/*: RequestOptions*/
|
|
1486
|
-
)
|
|
1487
|
-
/*: Promise<ParseUser>*/
|
|
1488
|
-
{
|
|
1072
|
+
logOut(options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
|
|
1489
1073
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1490
|
-
|
|
1491
1074
|
if (options.sessionToken) {
|
|
1492
1075
|
return RESTController.request('POST', 'logout', {}, options);
|
|
1493
1076
|
}
|
|
1494
|
-
|
|
1495
1077
|
return DefaultController.currentUserAsync().then(currentUser => {
|
|
1496
1078
|
const path = _Storage.default.generatePath(CURRENT_USER_KEY);
|
|
1497
|
-
|
|
1498
1079
|
let promise = _Storage.default.removeItemAsync(path);
|
|
1499
|
-
|
|
1500
1080
|
if (currentUser !== null) {
|
|
1501
1081
|
const currentSession = currentUser.getSessionToken();
|
|
1502
|
-
|
|
1503
1082
|
if (currentSession && (0, _isRevocableSession.default)(currentSession)) {
|
|
1504
1083
|
promise = promise.then(() => {
|
|
1505
1084
|
return RESTController.request('POST', 'logout', {}, {
|
|
@@ -1507,113 +1086,65 @@ const DefaultController = {
|
|
|
1507
1086
|
});
|
|
1508
1087
|
});
|
|
1509
1088
|
}
|
|
1510
|
-
|
|
1511
1089
|
currentUser._logOutWithAll();
|
|
1512
|
-
|
|
1513
1090
|
currentUser._finishFetch({
|
|
1514
1091
|
sessionToken: undefined
|
|
1515
1092
|
});
|
|
1516
1093
|
}
|
|
1517
|
-
|
|
1518
1094
|
currentUserCacheMatchesDisk = true;
|
|
1519
1095
|
currentUserCache = null;
|
|
1520
1096
|
return promise;
|
|
1521
1097
|
});
|
|
1522
1098
|
},
|
|
1523
|
-
|
|
1524
|
-
requestPasswordReset(email
|
|
1525
|
-
/*: string*/
|
|
1526
|
-
, options
|
|
1527
|
-
/*: RequestOptions*/
|
|
1528
|
-
) {
|
|
1099
|
+
requestPasswordReset(email /*: string*/, options /*: RequestOptions*/) {
|
|
1529
1100
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1530
|
-
|
|
1531
1101
|
return RESTController.request('POST', 'requestPasswordReset', {
|
|
1532
1102
|
email: email
|
|
1533
1103
|
}, options);
|
|
1534
1104
|
},
|
|
1535
|
-
|
|
1536
|
-
async upgradeToRevocableSession(user
|
|
1537
|
-
/*: ParseUser*/
|
|
1538
|
-
, options
|
|
1539
|
-
/*: RequestOptions*/
|
|
1540
|
-
) {
|
|
1105
|
+
async upgradeToRevocableSession(user /*: ParseUser*/, options /*: RequestOptions*/) {
|
|
1541
1106
|
const token = user.getSessionToken();
|
|
1542
|
-
|
|
1543
1107
|
if (!token) {
|
|
1544
1108
|
return Promise.reject(new _ParseError.default(_ParseError.default.SESSION_MISSING, 'Cannot upgrade a user with no session token'));
|
|
1545
1109
|
}
|
|
1546
|
-
|
|
1547
1110
|
options.sessionToken = token;
|
|
1548
|
-
|
|
1549
1111
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1550
|
-
|
|
1551
1112
|
const result = await RESTController.request('POST', 'upgradeToRevocableSession', {}, options);
|
|
1552
1113
|
const session = new _ParseSession.default();
|
|
1553
|
-
|
|
1554
1114
|
session._finishFetch(result);
|
|
1555
|
-
|
|
1556
1115
|
user._finishFetch({
|
|
1557
1116
|
sessionToken: session.getSessionToken()
|
|
1558
1117
|
});
|
|
1559
|
-
|
|
1560
1118
|
const current = await user.isCurrentAsync();
|
|
1561
|
-
|
|
1562
1119
|
if (current) {
|
|
1563
1120
|
return DefaultController.setCurrentUser(user);
|
|
1564
1121
|
}
|
|
1565
|
-
|
|
1566
1122
|
return Promise.resolve(user);
|
|
1567
1123
|
},
|
|
1568
|
-
|
|
1569
|
-
linkWith(user
|
|
1570
|
-
/*: ParseUser*/
|
|
1571
|
-
, authData
|
|
1572
|
-
/*: AuthData*/
|
|
1573
|
-
, options
|
|
1574
|
-
/*: FullOptions*/
|
|
1575
|
-
) {
|
|
1124
|
+
linkWith(user /*: ParseUser*/, authData /*: AuthData*/, options /*: FullOptions*/) {
|
|
1576
1125
|
return user.save({
|
|
1577
1126
|
authData
|
|
1578
1127
|
}, options).then(() => {
|
|
1579
1128
|
if (canUseCurrentUser) {
|
|
1580
1129
|
return DefaultController.setCurrentUser(user);
|
|
1581
1130
|
}
|
|
1582
|
-
|
|
1583
1131
|
return user;
|
|
1584
1132
|
});
|
|
1585
1133
|
},
|
|
1586
|
-
|
|
1587
|
-
verifyPassword(username
|
|
1588
|
-
/*: string*/
|
|
1589
|
-
, password
|
|
1590
|
-
/*: string*/
|
|
1591
|
-
, options
|
|
1592
|
-
/*: RequestOptions*/
|
|
1593
|
-
) {
|
|
1134
|
+
verifyPassword(username /*: string*/, password /*: string*/, options /*: RequestOptions*/) {
|
|
1594
1135
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1595
|
-
|
|
1596
1136
|
return RESTController.request('GET', 'verifyPassword', {
|
|
1597
1137
|
username,
|
|
1598
1138
|
password
|
|
1599
1139
|
}, options);
|
|
1600
1140
|
},
|
|
1601
|
-
|
|
1602
|
-
requestEmailVerification(email
|
|
1603
|
-
/*: string*/
|
|
1604
|
-
, options
|
|
1605
|
-
/*: RequestOptions*/
|
|
1606
|
-
) {
|
|
1141
|
+
requestEmailVerification(email /*: string*/, options /*: RequestOptions*/) {
|
|
1607
1142
|
const RESTController = _CoreManager.default.getRESTController();
|
|
1608
|
-
|
|
1609
1143
|
return RESTController.request('POST', 'verificationEmailRequest', {
|
|
1610
1144
|
email: email
|
|
1611
1145
|
}, options);
|
|
1612
1146
|
}
|
|
1613
|
-
|
|
1614
1147
|
};
|
|
1615
|
-
|
|
1616
1148
|
_CoreManager.default.setUserController(DefaultController);
|
|
1617
|
-
|
|
1618
1149
|
var _default = ParseUser;
|
|
1619
1150
|
exports.default = _default;
|