ParseUser.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  7. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  8. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  9. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  10. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  11. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  12. var _CoreManager = _interopRequireDefault(require("./CoreManager"));
  13. var _isRevocableSession = _interopRequireDefault(require("./isRevocableSession"));
  14. var _ParseError = _interopRequireDefault(require("./ParseError"));
  15. var _ParseObject2 = _interopRequireDefault(require("./ParseObject"));
  16. var _ParseSession = _interopRequireDefault(require("./ParseSession"));
  17. var _Storage = _interopRequireDefault(require("./Storage"));
  18. function _regeneratorRuntime() {
  19. "use strict";
  20. _regeneratorRuntime = function () {
  21. return exports;
  22. };
  23. var exports = {},
  24. Op = Object.prototype,
  25. hasOwn = Op.hasOwnProperty,
  26. $Symbol = "function" == typeof Symbol ? Symbol : {},
  27. iteratorSymbol = $Symbol.iterator || "@@iterator",
  28. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  29. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  30. function define(obj, key, value) {
  31. return Object.defineProperty(obj, key, {
  32. value: value,
  33. enumerable: !0,
  34. configurable: !0,
  35. writable: !0
  36. }), obj[key];
  37. }
  38. try {
  39. define({}, "");
  40. } catch (err) {
  41. define = function (obj, key, value) {
  42. return obj[key] = value;
  43. };
  44. }
  45. function wrap(innerFn, outerFn, self, tryLocsList) {
  46. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  47. generator = Object.create(protoGenerator.prototype),
  48. context = new Context(tryLocsList || []);
  49. return generator._invoke = function (innerFn, self, context) {
  50. var state = "suspendedStart";
  51. return function (method, arg) {
  52. if ("executing" === state) throw new Error("Generator is already running");
  53. if ("completed" === state) {
  54. if ("throw" === method) throw arg;
  55. return doneResult();
  56. }
  57. for (context.method = method, context.arg = arg;;) {
  58. var delegate = context.delegate;
  59. if (delegate) {
  60. var delegateResult = maybeInvokeDelegate(delegate, context);
  61. if (delegateResult) {
  62. if (delegateResult === ContinueSentinel) continue;
  63. return delegateResult;
  64. }
  65. }
  66. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  67. if ("suspendedStart" === state) throw state = "completed", context.arg;
  68. context.dispatchException(context.arg);
  69. } else "return" === context.method && context.abrupt("return", context.arg);
  70. state = "executing";
  71. var record = tryCatch(innerFn, self, context);
  72. if ("normal" === record.type) {
  73. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  74. return {
  75. value: record.arg,
  76. done: context.done
  77. };
  78. }
  79. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  80. }
  81. };
  82. }(innerFn, self, context), generator;
  83. }
  84. function tryCatch(fn, obj, arg) {
  85. try {
  86. return {
  87. type: "normal",
  88. arg: fn.call(obj, arg)
  89. };
  90. } catch (err) {
  91. return {
  92. type: "throw",
  93. arg: err
  94. };
  95. }
  96. }
  97. exports.wrap = wrap;
  98. var ContinueSentinel = {};
  99. function Generator() {}
  100. function GeneratorFunction() {}
  101. function GeneratorFunctionPrototype() {}
  102. var IteratorPrototype = {};
  103. define(IteratorPrototype, iteratorSymbol, function () {
  104. return this;
  105. });
  106. var getProto = Object.getPrototypeOf,
  107. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  108. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  109. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  110. function defineIteratorMethods(prototype) {
  111. ["next", "throw", "return"].forEach(function (method) {
  112. define(prototype, method, function (arg) {
  113. return this._invoke(method, arg);
  114. });
  115. });
  116. }
  117. function AsyncIterator(generator, PromiseImpl) {
  118. function invoke(method, arg, resolve, reject) {
  119. var record = tryCatch(generator[method], generator, arg);
  120. if ("throw" !== record.type) {
  121. var result = record.arg,
  122. value = result.value;
  123. return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  124. invoke("next", value, resolve, reject);
  125. }, function (err) {
  126. invoke("throw", err, resolve, reject);
  127. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  128. result.value = unwrapped, resolve(result);
  129. }, function (error) {
  130. return invoke("throw", error, resolve, reject);
  131. });
  132. }
  133. reject(record.arg);
  134. }
  135. var previousPromise;
  136. this._invoke = function (method, arg) {
  137. function callInvokeWithMethodAndArg() {
  138. return new PromiseImpl(function (resolve, reject) {
  139. invoke(method, arg, resolve, reject);
  140. });
  141. }
  142. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  143. };
  144. }
  145. function maybeInvokeDelegate(delegate, context) {
  146. var method = delegate.iterator[context.method];
  147. if (undefined === method) {
  148. if (context.delegate = null, "throw" === context.method) {
  149. if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
  150. context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
  151. }
  152. return ContinueSentinel;
  153. }
  154. var record = tryCatch(method, delegate.iterator, context.arg);
  155. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  156. var info = record.arg;
  157. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  158. }
  159. function pushTryEntry(locs) {
  160. var entry = {
  161. tryLoc: locs[0]
  162. };
  163. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  164. }
  165. function resetTryEntry(entry) {
  166. var record = entry.completion || {};
  167. record.type = "normal", delete record.arg, entry.completion = record;
  168. }
  169. function Context(tryLocsList) {
  170. this.tryEntries = [{
  171. tryLoc: "root"
  172. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  173. }
  174. function values(iterable) {
  175. if (iterable) {
  176. var iteratorMethod = iterable[iteratorSymbol];
  177. if (iteratorMethod) return iteratorMethod.call(iterable);
  178. if ("function" == typeof iterable.next) return iterable;
  179. if (!isNaN(iterable.length)) {
  180. var i = -1,
  181. next = function next() {
  182. for (; ++i < iterable.length;) {
  183. if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  184. }
  185. return next.value = undefined, next.done = !0, next;
  186. };
  187. return next.next = next;
  188. }
  189. }
  190. return {
  191. next: doneResult
  192. };
  193. }
  194. function doneResult() {
  195. return {
  196. value: undefined,
  197. done: !0
  198. };
  199. }
  200. return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  201. var ctor = "function" == typeof genFun && genFun.constructor;
  202. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  203. }, exports.mark = function (genFun) {
  204. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  205. }, exports.awrap = function (arg) {
  206. return {
  207. __await: arg
  208. };
  209. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  210. return this;
  211. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  212. void 0 === PromiseImpl && (PromiseImpl = Promise);
  213. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  214. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  215. return result.done ? result.value : iter.next();
  216. });
  217. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  218. return this;
  219. }), define(Gp, "toString", function () {
  220. return "[object Generator]";
  221. }), exports.keys = function (object) {
  222. var keys = [];
  223. for (var key in object) {
  224. keys.push(key);
  225. }
  226. return keys.reverse(), function next() {
  227. for (; keys.length;) {
  228. var key = keys.pop();
  229. if (key in object) return next.value = key, next.done = !1, next;
  230. }
  231. return next.done = !0, next;
  232. };
  233. }, exports.values = values, Context.prototype = {
  234. constructor: Context,
  235. reset: function (skipTempReset) {
  236. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
  237. "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  238. }
  239. },
  240. stop: function () {
  241. this.done = !0;
  242. var rootRecord = this.tryEntries[0].completion;
  243. if ("throw" === rootRecord.type) throw rootRecord.arg;
  244. return this.rval;
  245. },
  246. dispatchException: function (exception) {
  247. if (this.done) throw exception;
  248. var context = this;
  249. function handle(loc, caught) {
  250. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  251. }
  252. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  253. var entry = this.tryEntries[i],
  254. record = entry.completion;
  255. if ("root" === entry.tryLoc) return handle("end");
  256. if (entry.tryLoc <= this.prev) {
  257. var hasCatch = hasOwn.call(entry, "catchLoc"),
  258. hasFinally = hasOwn.call(entry, "finallyLoc");
  259. if (hasCatch && hasFinally) {
  260. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  261. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  262. } else if (hasCatch) {
  263. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  264. } else {
  265. if (!hasFinally) throw new Error("try statement without catch or finally");
  266. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  267. }
  268. }
  269. }
  270. },
  271. abrupt: function (type, arg) {
  272. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  273. var entry = this.tryEntries[i];
  274. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  275. var finallyEntry = entry;
  276. break;
  277. }
  278. }
  279. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  280. var record = finallyEntry ? finallyEntry.completion : {};
  281. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  282. },
  283. complete: function (record, afterLoc) {
  284. if ("throw" === record.type) throw record.arg;
  285. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  286. },
  287. finish: function (finallyLoc) {
  288. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  289. var entry = this.tryEntries[i];
  290. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  291. }
  292. },
  293. catch: function (tryLoc) {
  294. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  295. var entry = this.tryEntries[i];
  296. if (entry.tryLoc === tryLoc) {
  297. var record = entry.completion;
  298. if ("throw" === record.type) {
  299. var thrown = record.arg;
  300. resetTryEntry(entry);
  301. }
  302. return thrown;
  303. }
  304. }
  305. throw new Error("illegal catch attempt");
  306. },
  307. delegateYield: function (iterable, resultName, nextLoc) {
  308. return this.delegate = {
  309. iterator: values(iterable),
  310. resultName: resultName,
  311. nextLoc: nextLoc
  312. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  313. }
  314. }, exports;
  315. }
  316. function _createSuper(Derived) {
  317. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  318. return function () {
  319. var Super = (0, _getPrototypeOf2.default)(Derived),
  320. result;
  321. if (hasNativeReflectConstruct) {
  322. var NewTarget = (0, _getPrototypeOf2.default)(this).constructor;
  323. result = Reflect.construct(Super, arguments, NewTarget);
  324. } else {
  325. result = Super.apply(this, arguments);
  326. }
  327. return (0, _possibleConstructorReturn2.default)(this, result);
  328. };
  329. }
  330. function _isNativeReflectConstruct() {
  331. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  332. if (Reflect.construct.sham) return false;
  333. if (typeof Proxy === "function") return true;
  334. try {
  335. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  336. return true;
  337. } catch (e) {
  338. return false;
  339. }
  340. }
  341. var CURRENT_USER_KEY = 'currentUser';
  342. var canUseCurrentUser = !_CoreManager.default.get('IS_NODE');
  343. var currentUserCacheMatchesDisk = false;
  344. var currentUserCache = null;
  345. var authProviders = {};
  346. var ParseUser = function (_ParseObject) {
  347. (0, _inherits2.default)(ParseUser, _ParseObject);
  348. var _super = _createSuper(ParseUser);
  349. function ParseUser(attributes) {
  350. var _this;
  351. (0, _classCallCheck2.default)(this, ParseUser);
  352. _this = _super.call(this, '_User');
  353. if (attributes && typeof attributes === 'object') {
  354. if (!_this.set(attributes || {})) {
  355. throw new Error("Can't create an invalid Parse User");
  356. }
  357. }
  358. return _this;
  359. }
  360. (0, _createClass2.default)(ParseUser, [{
  361. key: "_upgradeToRevocableSession",
  362. value: function (options) {
  363. options = options || {};
  364. var upgradeOptions = {};
  365. if (options.hasOwnProperty('useMasterKey')) {
  366. upgradeOptions.useMasterKey = options.useMasterKey;
  367. }
  368. var controller = _CoreManager.default.getUserController();
  369. return controller.upgradeToRevocableSession(this, upgradeOptions);
  370. }
  371. }, {
  372. key: "linkWith",
  373. value: function (provider, options) {
  374. var _this2 = this;
  375. var saveOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  376. saveOpts.sessionToken = saveOpts.sessionToken || this.getSessionToken() || '';
  377. var authType;
  378. if (typeof provider === 'string') {
  379. authType = provider;
  380. if (authProviders[provider]) {
  381. provider = authProviders[provider];
  382. } else {
  383. var authProvider = {
  384. restoreAuthentication: function () {
  385. return true;
  386. },
  387. getAuthType: function () {
  388. return authType;
  389. }
  390. };
  391. authProviders[authProvider.getAuthType()] = authProvider;
  392. provider = authProvider;
  393. }
  394. } else {
  395. authType = provider.getAuthType();
  396. }
  397. if (options && options.hasOwnProperty('authData')) {
  398. var authData = this.get('authData') || {};
  399. if (typeof authData !== 'object') {
  400. throw new Error('Invalid type: authData field should be an object');
  401. }
  402. authData[authType] = options.authData;
  403. var controller = _CoreManager.default.getUserController();
  404. return controller.linkWith(this, authData, saveOpts);
  405. } else {
  406. return new Promise(function (resolve, reject) {
  407. provider.authenticate({
  408. success: function (provider, result) {
  409. var opts = {};
  410. opts.authData = result;
  411. _this2.linkWith(provider, opts, saveOpts).then(function () {
  412. resolve(_this2);
  413. }, function (error) {
  414. reject(error);
  415. });
  416. },
  417. error: function (provider, _error) {
  418. reject(_error);
  419. }
  420. });
  421. });
  422. }
  423. }
  424. }, {
  425. key: "_linkWith",
  426. value: function (provider, options) {
  427. var saveOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  428. return this.linkWith(provider, options, saveOpts);
  429. }
  430. }, {
  431. key: "_synchronizeAuthData",
  432. value: function (provider) {
  433. if (!this.isCurrent() || !provider) {
  434. return;
  435. }
  436. var authType;
  437. if (typeof provider === 'string') {
  438. authType = provider;
  439. provider = authProviders[authType];
  440. } else {
  441. authType = provider.getAuthType();
  442. }
  443. var authData = this.get('authData');
  444. if (!provider || !authData || typeof authData !== 'object') {
  445. return;
  446. }
  447. var success = provider.restoreAuthentication(authData[authType]);
  448. if (!success) {
  449. this._unlinkFrom(provider);
  450. }
  451. }
  452. }, {
  453. key: "_synchronizeAllAuthData",
  454. value: function () {
  455. var authData = this.get('authData');
  456. if (typeof authData !== 'object') {
  457. return;
  458. }
  459. for (var _key in authData) {
  460. this._synchronizeAuthData(_key);
  461. }
  462. }
  463. }, {
  464. key: "_cleanupAuthData",
  465. value: function () {
  466. if (!this.isCurrent()) {
  467. return;
  468. }
  469. var authData = this.get('authData');
  470. if (typeof authData !== 'object') {
  471. return;
  472. }
  473. for (var _key2 in authData) {
  474. if (!authData[_key2]) {
  475. delete authData[_key2];
  476. }
  477. }
  478. }
  479. }, {
  480. key: "_unlinkFrom",
  481. value: function (provider, options) {
  482. var _this3 = this;
  483. return this.linkWith(provider, {
  484. authData: null
  485. }, options).then(function () {
  486. _this3._synchronizeAuthData(provider);
  487. return Promise.resolve(_this3);
  488. });
  489. }
  490. }, {
  491. key: "_isLinked",
  492. value: function (provider) {
  493. var authType;
  494. if (typeof provider === 'string') {
  495. authType = provider;
  496. } else {
  497. authType = provider.getAuthType();
  498. }
  499. var authData = this.get('authData') || {};
  500. if (typeof authData !== 'object') {
  501. return false;
  502. }
  503. return !!authData[authType];
  504. }
  505. }, {
  506. key: "_logOutWithAll",
  507. value: function () {
  508. var authData = this.get('authData');
  509. if (typeof authData !== 'object') {
  510. return;
  511. }
  512. for (var _key3 in authData) {
  513. this._logOutWith(_key3);
  514. }
  515. }
  516. }, {
  517. key: "_logOutWith",
  518. value: function (provider) {
  519. if (!this.isCurrent()) {
  520. return;
  521. }
  522. if (typeof provider === 'string') {
  523. provider = authProviders[provider];
  524. }
  525. if (provider && provider.deauthenticate) {
  526. provider.deauthenticate();
  527. }
  528. }
  529. }, {
  530. key: "_preserveFieldsOnFetch",
  531. value: function () {
  532. return {
  533. sessionToken: this.get('sessionToken')
  534. };
  535. }
  536. }, {
  537. key: "isCurrent",
  538. value: function () {
  539. var current = ParseUser.current();
  540. return !!current && current.id === this.id;
  541. }
  542. }, {
  543. key: "isCurrentAsync",
  544. value: function () {
  545. var current;
  546. return _regeneratorRuntime().async(function (_context) {
  547. while (1) {
  548. switch (_context.prev = _context.next) {
  549. case 0:
  550. _context.next = 2;
  551. return _regeneratorRuntime().awrap(ParseUser.currentAsync());
  552. case 2:
  553. current = _context.sent;
  554. return _context.abrupt("return", !!current && current.id === this.id);
  555. case 4:
  556. case "end":
  557. return _context.stop();
  558. }
  559. }
  560. }, null, this, null, Promise);
  561. }
  562. }, {
  563. key: "getUsername",
  564. value: function () {
  565. var username = this.get('username');
  566. if (username == null || typeof username === 'string') {
  567. return username;
  568. }
  569. return '';
  570. }
  571. }, {
  572. key: "setUsername",
  573. value: function (username) {
  574. var authData = this.get('authData');
  575. if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) {
  576. authData.anonymous = null;
  577. }
  578. this.set('username', username);
  579. }
  580. }, {
  581. key: "setPassword",
  582. value: function (password) {
  583. this.set('password', password);
  584. }
  585. }, {
  586. key: "getEmail",
  587. value: function () {
  588. var email = this.get('email');
  589. if (email == null || typeof email === 'string') {
  590. return email;
  591. }
  592. return '';
  593. }
  594. }, {
  595. key: "setEmail",
  596. value: function (email) {
  597. return this.set('email', email);
  598. }
  599. }, {
  600. key: "getSessionToken",
  601. value: function () {
  602. var token = this.get('sessionToken');
  603. if (token == null || typeof token === 'string') {
  604. return token;
  605. }
  606. return '';
  607. }
  608. }, {
  609. key: "authenticated",
  610. value: function () {
  611. var current = ParseUser.current();
  612. return !!this.get('sessionToken') && !!current && current.id === this.id;
  613. }
  614. }, {
  615. key: "signUp",
  616. value: function (attrs, options) {
  617. options = options || {};
  618. var signupOptions = {};
  619. if (options.hasOwnProperty('useMasterKey')) {
  620. signupOptions.useMasterKey = options.useMasterKey;
  621. }
  622. if (options.hasOwnProperty('installationId')) {
  623. signupOptions.installationId = options.installationId;
  624. }
  625. if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
  626. signupOptions.context = options.context;
  627. }
  628. var controller = _CoreManager.default.getUserController();
  629. return controller.signUp(this, attrs, signupOptions);
  630. }
  631. }, {
  632. key: "logIn",
  633. value: function (options) {
  634. options = options || {};
  635. var loginOptions = {
  636. usePost: true
  637. };
  638. if (options.hasOwnProperty('useMasterKey')) {
  639. loginOptions.useMasterKey = options.useMasterKey;
  640. }
  641. if (options.hasOwnProperty('installationId')) {
  642. loginOptions.installationId = options.installationId;
  643. }
  644. if (options.hasOwnProperty('usePost')) {
  645. loginOptions.usePost = options.usePost;
  646. }
  647. var controller = _CoreManager.default.getUserController();
  648. return controller.logIn(this, loginOptions);
  649. }
  650. }, {
  651. key: "save",
  652. value: function () {
  653. var _len,
  654. args,
  655. _key4,
  656. current,
  657. _args2 = arguments;
  658. return _regeneratorRuntime().async(function (_context2) {
  659. while (1) {
  660. switch (_context2.prev = _context2.next) {
  661. case 0:
  662. for (_len = _args2.length, args = new Array(_len), _key4 = 0; _key4 < _len; _key4++) {
  663. args[_key4] = _args2[_key4];
  664. }
  665. _context2.next = 3;
  666. return _regeneratorRuntime().awrap((0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "save", this).apply(this, args));
  667. case 3:
  668. _context2.next = 5;
  669. return _regeneratorRuntime().awrap(this.isCurrentAsync());
  670. case 5:
  671. current = _context2.sent;
  672. if (!current) {
  673. _context2.next = 8;
  674. break;
  675. }
  676. return _context2.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  677. case 8:
  678. return _context2.abrupt("return", this);
  679. case 9:
  680. case "end":
  681. return _context2.stop();
  682. }
  683. }
  684. }, null, this, null, Promise);
  685. }
  686. }, {
  687. key: "destroy",
  688. value: function () {
  689. var _len2,
  690. args,
  691. _key5,
  692. current,
  693. _args3 = arguments;
  694. return _regeneratorRuntime().async(function (_context3) {
  695. while (1) {
  696. switch (_context3.prev = _context3.next) {
  697. case 0:
  698. for (_len2 = _args3.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
  699. args[_key5] = _args3[_key5];
  700. }
  701. _context3.next = 3;
  702. return _regeneratorRuntime().awrap((0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "destroy", this).apply(this, args));
  703. case 3:
  704. _context3.next = 5;
  705. return _regeneratorRuntime().awrap(this.isCurrentAsync());
  706. case 5:
  707. current = _context3.sent;
  708. if (!current) {
  709. _context3.next = 8;
  710. break;
  711. }
  712. return _context3.abrupt("return", _CoreManager.default.getUserController().removeUserFromDisk());
  713. case 8:
  714. return _context3.abrupt("return", this);
  715. case 9:
  716. case "end":
  717. return _context3.stop();
  718. }
  719. }
  720. }, null, this, null, Promise);
  721. }
  722. }, {
  723. key: "fetch",
  724. value: function () {
  725. var _len3,
  726. args,
  727. _key6,
  728. current,
  729. _args4 = arguments;
  730. return _regeneratorRuntime().async(function (_context4) {
  731. while (1) {
  732. switch (_context4.prev = _context4.next) {
  733. case 0:
  734. for (_len3 = _args4.length, args = new Array(_len3), _key6 = 0; _key6 < _len3; _key6++) {
  735. args[_key6] = _args4[_key6];
  736. }
  737. _context4.next = 3;
  738. return _regeneratorRuntime().awrap((0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetch", this).apply(this, args));
  739. case 3:
  740. _context4.next = 5;
  741. return _regeneratorRuntime().awrap(this.isCurrentAsync());
  742. case 5:
  743. current = _context4.sent;
  744. if (!current) {
  745. _context4.next = 8;
  746. break;
  747. }
  748. return _context4.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  749. case 8:
  750. return _context4.abrupt("return", this);
  751. case 9:
  752. case "end":
  753. return _context4.stop();
  754. }
  755. }
  756. }, null, this, null, Promise);
  757. }
  758. }, {
  759. key: "fetchWithInclude",
  760. value: function () {
  761. var _len4,
  762. args,
  763. _key7,
  764. current,
  765. _args5 = arguments;
  766. return _regeneratorRuntime().async(function (_context5) {
  767. while (1) {
  768. switch (_context5.prev = _context5.next) {
  769. case 0:
  770. for (_len4 = _args5.length, args = new Array(_len4), _key7 = 0; _key7 < _len4; _key7++) {
  771. args[_key7] = _args5[_key7];
  772. }
  773. _context5.next = 3;
  774. return _regeneratorRuntime().awrap((0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetchWithInclude", this).apply(this, args));
  775. case 3:
  776. _context5.next = 5;
  777. return _regeneratorRuntime().awrap(this.isCurrentAsync());
  778. case 5:
  779. current = _context5.sent;
  780. if (!current) {
  781. _context5.next = 8;
  782. break;
  783. }
  784. return _context5.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  785. case 8:
  786. return _context5.abrupt("return", this);
  787. case 9:
  788. case "end":
  789. return _context5.stop();
  790. }
  791. }
  792. }, null, this, null, Promise);
  793. }
  794. }, {
  795. key: "verifyPassword",
  796. value: function (password, options) {
  797. var username = this.getUsername() || '';
  798. return ParseUser.verifyPassword(username, password, options);
  799. }
  800. }], [{
  801. key: "readOnlyAttributes",
  802. value: function () {
  803. return ['sessionToken'];
  804. }
  805. }, {
  806. key: "extend",
  807. value: function (protoProps, classProps) {
  808. if (protoProps) {
  809. for (var _prop in protoProps) {
  810. if (_prop !== 'className') {
  811. Object.defineProperty(ParseUser.prototype, _prop, {
  812. value: protoProps[_prop],
  813. enumerable: false,
  814. writable: true,
  815. configurable: true
  816. });
  817. }
  818. }
  819. }
  820. if (classProps) {
  821. for (var _prop2 in classProps) {
  822. if (_prop2 !== 'className') {
  823. Object.defineProperty(ParseUser, _prop2, {
  824. value: classProps[_prop2],
  825. enumerable: false,
  826. writable: true,
  827. configurable: true
  828. });
  829. }
  830. }
  831. }
  832. return ParseUser;
  833. }
  834. }, {
  835. key: "current",
  836. value: function () {
  837. if (!canUseCurrentUser) {
  838. return null;
  839. }
  840. var controller = _CoreManager.default.getUserController();
  841. return controller.currentUser();
  842. }
  843. }, {
  844. key: "currentAsync",
  845. value: function () {
  846. if (!canUseCurrentUser) {
  847. return Promise.resolve(null);
  848. }
  849. var controller = _CoreManager.default.getUserController();
  850. return controller.currentUserAsync();
  851. }
  852. }, {
  853. key: "signUp",
  854. value: function (username, password, attrs, options) {
  855. attrs = attrs || {};
  856. attrs.username = username;
  857. attrs.password = password;
  858. var user = new this(attrs);
  859. return user.signUp({}, options);
  860. }
  861. }, {
  862. key: "logIn",
  863. value: function (username, password, options) {
  864. if (typeof username !== 'string') {
  865. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
  866. } else if (typeof password !== 'string') {
  867. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
  868. }
  869. var user = new this();
  870. user._finishFetch({
  871. username: username,
  872. password: password
  873. });
  874. return user.logIn(options);
  875. }
  876. }, {
  877. key: "become",
  878. value: function (sessionToken, options) {
  879. if (!canUseCurrentUser) {
  880. throw new Error('It is not memory-safe to become a user in a server environment');
  881. }
  882. options = options || {};
  883. var becomeOptions = {
  884. sessionToken: sessionToken
  885. };
  886. if (options.hasOwnProperty('useMasterKey')) {
  887. becomeOptions.useMasterKey = options.useMasterKey;
  888. }
  889. var controller = _CoreManager.default.getUserController();
  890. var user = new this();
  891. return controller.become(user, becomeOptions);
  892. }
  893. }, {
  894. key: "me",
  895. value: function (sessionToken) {
  896. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  897. var controller = _CoreManager.default.getUserController();
  898. var meOptions = {
  899. sessionToken: sessionToken
  900. };
  901. if (options.useMasterKey) {
  902. meOptions.useMasterKey = options.useMasterKey;
  903. }
  904. var user = new this();
  905. return controller.me(user, meOptions);
  906. }
  907. }, {
  908. key: "hydrate",
  909. value: function (userJSON) {
  910. var controller = _CoreManager.default.getUserController();
  911. var user = new this();
  912. return controller.hydrate(user, userJSON);
  913. }
  914. }, {
  915. key: "logInWith",
  916. value: function (provider, options, saveOpts) {
  917. var user = new this();
  918. return user.linkWith(provider, options, saveOpts);
  919. }
  920. }, {
  921. key: "logOut",
  922. value: function () {
  923. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  924. var controller = _CoreManager.default.getUserController();
  925. return controller.logOut(options);
  926. }
  927. }, {
  928. key: "requestPasswordReset",
  929. value: function (email, options) {
  930. options = options || {};
  931. var requestOptions = {};
  932. if (options.hasOwnProperty('useMasterKey')) {
  933. requestOptions.useMasterKey = options.useMasterKey;
  934. }
  935. var controller = _CoreManager.default.getUserController();
  936. return controller.requestPasswordReset(email, requestOptions);
  937. }
  938. }, {
  939. key: "requestEmailVerification",
  940. value: function (email, options) {
  941. options = options || {};
  942. var requestOptions = {};
  943. if (options.hasOwnProperty('useMasterKey')) {
  944. requestOptions.useMasterKey = options.useMasterKey;
  945. }
  946. var controller = _CoreManager.default.getUserController();
  947. return controller.requestEmailVerification(email, requestOptions);
  948. }
  949. }, {
  950. key: "verifyPassword",
  951. value: function (username, password, options) {
  952. if (typeof username !== 'string') {
  953. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
  954. }
  955. if (typeof password !== 'string') {
  956. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
  957. }
  958. options = options || {};
  959. var verificationOption = {};
  960. if (options.hasOwnProperty('useMasterKey')) {
  961. verificationOption.useMasterKey = options.useMasterKey;
  962. }
  963. var controller = _CoreManager.default.getUserController();
  964. return controller.verifyPassword(username, password, verificationOption);
  965. }
  966. }, {
  967. key: "allowCustomUserClass",
  968. value: function (isAllowed) {
  969. _CoreManager.default.set('PERFORM_USER_REWRITE', !isAllowed);
  970. }
  971. }, {
  972. key: "enableRevocableSession",
  973. value: function (options) {
  974. options = options || {};
  975. _CoreManager.default.set('FORCE_REVOCABLE_SESSION', true);
  976. if (canUseCurrentUser) {
  977. var current = ParseUser.current();
  978. if (current) {
  979. return current._upgradeToRevocableSession(options);
  980. }
  981. }
  982. return Promise.resolve();
  983. }
  984. }, {
  985. key: "enableUnsafeCurrentUser",
  986. value: function () {
  987. canUseCurrentUser = true;
  988. }
  989. }, {
  990. key: "disableUnsafeCurrentUser",
  991. value: function () {
  992. canUseCurrentUser = false;
  993. }
  994. }, {
  995. key: "_registerAuthenticationProvider",
  996. value: function (provider) {
  997. authProviders[provider.getAuthType()] = provider;
  998. ParseUser.currentAsync().then(function (current) {
  999. if (current) {
  1000. current._synchronizeAuthData(provider.getAuthType());
  1001. }
  1002. });
  1003. }
  1004. }, {
  1005. key: "_logInWith",
  1006. value: function (provider, options, saveOpts) {
  1007. var user = new this();
  1008. return user.linkWith(provider, options, saveOpts);
  1009. }
  1010. }, {
  1011. key: "_clearCache",
  1012. value: function () {
  1013. currentUserCache = null;
  1014. currentUserCacheMatchesDisk = false;
  1015. }
  1016. }, {
  1017. key: "_setCurrentUserCache",
  1018. value: function (user) {
  1019. currentUserCache = user;
  1020. }
  1021. }]);
  1022. return ParseUser;
  1023. }(_ParseObject2.default);
  1024. _ParseObject2.default.registerSubclass('_User', ParseUser);
  1025. var DefaultController = {
  1026. updateUserOnDisk: function (user) {
  1027. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1028. var json = user.toJSON();
  1029. delete json.password;
  1030. json.className = '_User';
  1031. var userData = JSON.stringify(json);
  1032. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1033. var crypto = _CoreManager.default.getCryptoController();
  1034. userData = crypto.encrypt(json, _CoreManager.default.get('ENCRYPTED_KEY'));
  1035. }
  1036. return _Storage.default.setItemAsync(path, userData).then(function () {
  1037. return user;
  1038. });
  1039. },
  1040. removeUserFromDisk: function () {
  1041. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1042. currentUserCacheMatchesDisk = true;
  1043. currentUserCache = null;
  1044. return _Storage.default.removeItemAsync(path);
  1045. },
  1046. setCurrentUser: function (user) {
  1047. currentUserCache = user;
  1048. user._cleanupAuthData();
  1049. user._synchronizeAllAuthData();
  1050. return DefaultController.updateUserOnDisk(user);
  1051. },
  1052. currentUser: function () {
  1053. if (currentUserCache) {
  1054. return currentUserCache;
  1055. }
  1056. if (currentUserCacheMatchesDisk) {
  1057. return null;
  1058. }
  1059. if (_Storage.default.async()) {
  1060. throw new Error('Cannot call currentUser() when using a platform with an async ' + 'storage system. Call currentUserAsync() instead.');
  1061. }
  1062. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1063. var userData = _Storage.default.getItem(path);
  1064. currentUserCacheMatchesDisk = true;
  1065. if (!userData) {
  1066. currentUserCache = null;
  1067. return null;
  1068. }
  1069. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1070. var crypto = _CoreManager.default.getCryptoController();
  1071. userData = crypto.decrypt(userData, _CoreManager.default.get('ENCRYPTED_KEY'));
  1072. }
  1073. userData = JSON.parse(userData);
  1074. if (!userData.className) {
  1075. userData.className = '_User';
  1076. }
  1077. if (userData._id) {
  1078. if (userData.objectId !== userData._id) {
  1079. userData.objectId = userData._id;
  1080. }
  1081. delete userData._id;
  1082. }
  1083. if (userData._sessionToken) {
  1084. userData.sessionToken = userData._sessionToken;
  1085. delete userData._sessionToken;
  1086. }
  1087. var current = _ParseObject2.default.fromJSON(userData);
  1088. currentUserCache = current;
  1089. current._synchronizeAllAuthData();
  1090. return current;
  1091. },
  1092. currentUserAsync: function () {
  1093. if (currentUserCache) {
  1094. return Promise.resolve(currentUserCache);
  1095. }
  1096. if (currentUserCacheMatchesDisk) {
  1097. return Promise.resolve(null);
  1098. }
  1099. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1100. return _Storage.default.getItemAsync(path).then(function (userData) {
  1101. currentUserCacheMatchesDisk = true;
  1102. if (!userData) {
  1103. currentUserCache = null;
  1104. return Promise.resolve(null);
  1105. }
  1106. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1107. var crypto = _CoreManager.default.getCryptoController();
  1108. userData = crypto.decrypt(userData.toString(), _CoreManager.default.get('ENCRYPTED_KEY'));
  1109. }
  1110. userData = JSON.parse(userData);
  1111. if (!userData.className) {
  1112. userData.className = '_User';
  1113. }
  1114. if (userData._id) {
  1115. if (userData.objectId !== userData._id) {
  1116. userData.objectId = userData._id;
  1117. }
  1118. delete userData._id;
  1119. }
  1120. if (userData._sessionToken) {
  1121. userData.sessionToken = userData._sessionToken;
  1122. delete userData._sessionToken;
  1123. }
  1124. var current = _ParseObject2.default.fromJSON(userData);
  1125. currentUserCache = current;
  1126. current._synchronizeAllAuthData();
  1127. return Promise.resolve(current);
  1128. });
  1129. },
  1130. signUp: function (user, attrs, options) {
  1131. var username = attrs && attrs.username || user.get('username');
  1132. var password = attrs && attrs.password || user.get('password');
  1133. if (!username || !username.length) {
  1134. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty username.'));
  1135. }
  1136. if (!password || !password.length) {
  1137. return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty password.'));
  1138. }
  1139. return user.save(attrs, options).then(function () {
  1140. user._finishFetch({
  1141. password: undefined
  1142. });
  1143. if (canUseCurrentUser) {
  1144. return DefaultController.setCurrentUser(user);
  1145. }
  1146. return user;
  1147. });
  1148. },
  1149. logIn: function (user, options) {
  1150. var RESTController = _CoreManager.default.getRESTController();
  1151. var stateController = _CoreManager.default.getObjectStateController();
  1152. var auth = {
  1153. username: user.get('username'),
  1154. password: user.get('password')
  1155. };
  1156. return RESTController.request(options.usePost ? 'POST' : 'GET', 'login', auth, options).then(function (response) {
  1157. user._migrateId(response.objectId);
  1158. user._setExisted(true);
  1159. stateController.setPendingOp(user._getStateIdentifier(), 'username', undefined);
  1160. stateController.setPendingOp(user._getStateIdentifier(), 'password', undefined);
  1161. response.password = undefined;
  1162. user._finishFetch(response);
  1163. if (!canUseCurrentUser) {
  1164. return Promise.resolve(user);
  1165. }
  1166. return DefaultController.setCurrentUser(user);
  1167. });
  1168. },
  1169. become: function (user, options) {
  1170. var RESTController = _CoreManager.default.getRESTController();
  1171. return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
  1172. user._finishFetch(response);
  1173. user._setExisted(true);
  1174. return DefaultController.setCurrentUser(user);
  1175. });
  1176. },
  1177. hydrate: function (user, userJSON) {
  1178. user._finishFetch(userJSON);
  1179. user._setExisted(true);
  1180. if (userJSON.sessionToken && canUseCurrentUser) {
  1181. return DefaultController.setCurrentUser(user);
  1182. } else {
  1183. return Promise.resolve(user);
  1184. }
  1185. },
  1186. me: function (user, options) {
  1187. var RESTController = _CoreManager.default.getRESTController();
  1188. return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
  1189. user._finishFetch(response);
  1190. user._setExisted(true);
  1191. return user;
  1192. });
  1193. },
  1194. logOut: function (options) {
  1195. var RESTController = _CoreManager.default.getRESTController();
  1196. if (options.sessionToken) {
  1197. return RESTController.request('POST', 'logout', {}, options);
  1198. }
  1199. return DefaultController.currentUserAsync().then(function (currentUser) {
  1200. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1201. var promise = _Storage.default.removeItemAsync(path);
  1202. if (currentUser !== null) {
  1203. var currentSession = currentUser.getSessionToken();
  1204. if (currentSession && (0, _isRevocableSession.default)(currentSession)) {
  1205. promise = promise.then(function () {
  1206. return RESTController.request('POST', 'logout', {}, {
  1207. sessionToken: currentSession
  1208. });
  1209. });
  1210. }
  1211. currentUser._logOutWithAll();
  1212. currentUser._finishFetch({
  1213. sessionToken: undefined
  1214. });
  1215. }
  1216. currentUserCacheMatchesDisk = true;
  1217. currentUserCache = null;
  1218. return promise;
  1219. });
  1220. },
  1221. requestPasswordReset: function (email, options) {
  1222. var RESTController = _CoreManager.default.getRESTController();
  1223. return RESTController.request('POST', 'requestPasswordReset', {
  1224. email: email
  1225. }, options);
  1226. },
  1227. upgradeToRevocableSession: function (user, options) {
  1228. var token, RESTController, result, session, current;
  1229. return _regeneratorRuntime().async(function (_context6) {
  1230. while (1) {
  1231. switch (_context6.prev = _context6.next) {
  1232. case 0:
  1233. token = user.getSessionToken();
  1234. if (token) {
  1235. _context6.next = 3;
  1236. break;
  1237. }
  1238. return _context6.abrupt("return", Promise.reject(new _ParseError.default(_ParseError.default.SESSION_MISSING, 'Cannot upgrade a user with no session token')));
  1239. case 3:
  1240. options.sessionToken = token;
  1241. RESTController = _CoreManager.default.getRESTController();
  1242. _context6.next = 7;
  1243. return _regeneratorRuntime().awrap(RESTController.request('POST', 'upgradeToRevocableSession', {}, options));
  1244. case 7:
  1245. result = _context6.sent;
  1246. session = new _ParseSession.default();
  1247. session._finishFetch(result);
  1248. user._finishFetch({
  1249. sessionToken: session.getSessionToken()
  1250. });
  1251. _context6.next = 13;
  1252. return _regeneratorRuntime().awrap(user.isCurrentAsync());
  1253. case 13:
  1254. current = _context6.sent;
  1255. if (!current) {
  1256. _context6.next = 16;
  1257. break;
  1258. }
  1259. return _context6.abrupt("return", DefaultController.setCurrentUser(user));
  1260. case 16:
  1261. return _context6.abrupt("return", Promise.resolve(user));
  1262. case 17:
  1263. case "end":
  1264. return _context6.stop();
  1265. }
  1266. }
  1267. }, null, null, null, Promise);
  1268. },
  1269. linkWith: function (user, authData, options) {
  1270. return user.save({
  1271. authData: authData
  1272. }, options).then(function () {
  1273. if (canUseCurrentUser) {
  1274. return DefaultController.setCurrentUser(user);
  1275. }
  1276. return user;
  1277. });
  1278. },
  1279. verifyPassword: function (username, password, options) {
  1280. var RESTController = _CoreManager.default.getRESTController();
  1281. return RESTController.request('GET', 'verifyPassword', {
  1282. username: username,
  1283. password: password
  1284. }, options);
  1285. },
  1286. requestEmailVerification: function (email, options) {
  1287. var RESTController = _CoreManager.default.getRESTController();
  1288. return RESTController.request('POST', 'verificationEmailRequest', {
  1289. email: email
  1290. }, options);
  1291. }
  1292. };
  1293. _CoreManager.default.setUserController(DefaultController);
  1294. var _default = ParseUser;
  1295. exports.default = _default;