@pisell/pisellos 3.0.68 → 3.0.70
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/modules/Order/index.js +4 -2
- package/dist/modules/Order/types.d.ts +1 -0
- package/dist/plugins/request.d.ts +1 -0
- package/dist/solution/BookingByStep/index.d.ts +5 -1
- package/dist/solution/BookingByStep/index.js +31 -7
- package/dist/solution/RegisterAndLogin/config.d.ts +87 -0
- package/dist/solution/RegisterAndLogin/config.js +792 -0
- package/dist/solution/RegisterAndLogin/index.d.ts +189 -0
- package/dist/solution/RegisterAndLogin/index.js +2667 -0
- package/dist/solution/RegisterAndLogin/types.d.ts +444 -0
- package/dist/solution/RegisterAndLogin/types.js +231 -0
- package/dist/solution/RegisterAndLogin/utils.d.ts +95 -0
- package/dist/solution/RegisterAndLogin/utils.js +322 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Order/index.js +5 -2
- package/lib/modules/Order/types.d.ts +1 -0
- package/lib/plugins/request.d.ts +1 -0
- package/lib/solution/BookingByStep/index.d.ts +5 -1
- package/lib/solution/BookingByStep/index.js +9 -2
- package/lib/solution/RegisterAndLogin/config.d.ts +87 -0
- package/lib/solution/RegisterAndLogin/config.js +594 -0
- package/lib/solution/RegisterAndLogin/index.d.ts +189 -0
- package/lib/solution/RegisterAndLogin/index.js +1593 -0
- package/lib/solution/RegisterAndLogin/types.d.ts +444 -0
- package/lib/solution/RegisterAndLogin/types.js +78 -0
- package/lib/solution/RegisterAndLogin/utils.d.ts +95 -0
- package/lib/solution/RegisterAndLogin/utils.js +279 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,2667 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
11
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
13
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
14
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
16
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
import { BaseModule } from "../../modules/BaseModule";
|
|
21
|
+
import { RegisterAndLoginHooks, VerificationCodeType, VerificationPurpose } from "./types";
|
|
22
|
+
import { createApiCaller } from "./config";
|
|
23
|
+
export * from "./types";
|
|
24
|
+
export * from "./config";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 注册登录解决方案实现
|
|
28
|
+
*/
|
|
29
|
+
export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
30
|
+
_inherits(RegisterAndLoginImpl, _BaseModule);
|
|
31
|
+
var _super = _createSuper(RegisterAndLoginImpl);
|
|
32
|
+
function RegisterAndLoginImpl(name, version) {
|
|
33
|
+
var _this;
|
|
34
|
+
_classCallCheck(this, RegisterAndLoginImpl);
|
|
35
|
+
_this = _super.call(this, name, version);
|
|
36
|
+
// 提供给 baseModule 用的默认名称和默认版本
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "defaultName", 'registerAndLogin');
|
|
38
|
+
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "isSolution", true);
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
42
|
+
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "apiCaller", void 0);
|
|
44
|
+
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "channel", 'default');
|
|
46
|
+
// 内存缓存
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "countriesCache", null);
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 重新发送邮箱注册链接
|
|
53
|
+
*/
|
|
54
|
+
_createClass(RegisterAndLoginImpl, [{
|
|
55
|
+
key: "resendEmailRegisterLink",
|
|
56
|
+
value: (function () {
|
|
57
|
+
var _resendEmailRegisterLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
58
|
+
var error, response;
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
_context.prev = 0;
|
|
63
|
+
if (this.store.emailRegisterLinkCode) {
|
|
64
|
+
_context.next = 5;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
error = '没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink';
|
|
68
|
+
this.store.error = error;
|
|
69
|
+
return _context.abrupt("return", {
|
|
70
|
+
status: false,
|
|
71
|
+
message: error
|
|
72
|
+
});
|
|
73
|
+
case 5:
|
|
74
|
+
this.store.isLoading = true;
|
|
75
|
+
this.store.error = null;
|
|
76
|
+
_context.next = 9;
|
|
77
|
+
return this.apiCaller.call('resendEmailRegisterLink', {
|
|
78
|
+
code: this.store.emailRegisterLinkCode
|
|
79
|
+
});
|
|
80
|
+
case 9:
|
|
81
|
+
response = _context.sent;
|
|
82
|
+
if (!response.status) {
|
|
83
|
+
_context.next = 15;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
_context.next = 13;
|
|
87
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
88
|
+
target: 'resend',
|
|
89
|
+
purpose: VerificationPurpose.REGISTER
|
|
90
|
+
});
|
|
91
|
+
case 13:
|
|
92
|
+
_context.next = 18;
|
|
93
|
+
break;
|
|
94
|
+
case 15:
|
|
95
|
+
this.store.error = response.message || '重新发送注册邀请链接失败';
|
|
96
|
+
_context.next = 18;
|
|
97
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
98
|
+
target: 'resend',
|
|
99
|
+
error: this.store.error
|
|
100
|
+
});
|
|
101
|
+
case 18:
|
|
102
|
+
return _context.abrupt("return", response);
|
|
103
|
+
case 21:
|
|
104
|
+
_context.prev = 21;
|
|
105
|
+
_context.t0 = _context["catch"](0);
|
|
106
|
+
this.store.error = '重新发送注册邀请链接失败';
|
|
107
|
+
_context.next = 26;
|
|
108
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
109
|
+
target: 'resend',
|
|
110
|
+
error: this.store.error
|
|
111
|
+
});
|
|
112
|
+
case 26:
|
|
113
|
+
return _context.abrupt("return", _context.t0);
|
|
114
|
+
case 27:
|
|
115
|
+
_context.prev = 27;
|
|
116
|
+
this.store.isLoading = false;
|
|
117
|
+
return _context.finish(27);
|
|
118
|
+
case 30:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee, this, [[0, 21, 27, 30]]);
|
|
123
|
+
}));
|
|
124
|
+
function resendEmailRegisterLink() {
|
|
125
|
+
return _resendEmailRegisterLink.apply(this, arguments);
|
|
126
|
+
}
|
|
127
|
+
return resendEmailRegisterLink;
|
|
128
|
+
}()
|
|
129
|
+
/**
|
|
130
|
+
* 邮箱验证码注册
|
|
131
|
+
* @param params 注册参数
|
|
132
|
+
* @returns 注册结果
|
|
133
|
+
*/
|
|
134
|
+
)
|
|
135
|
+
}, {
|
|
136
|
+
key: "emailCodeRegister",
|
|
137
|
+
value: (function () {
|
|
138
|
+
var _emailCodeRegister = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
139
|
+
var response, _response$data, user, token, refreshToken, expiresAt;
|
|
140
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
141
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
_context2.prev = 0;
|
|
144
|
+
this.store.isLoading = true;
|
|
145
|
+
this.store.error = null;
|
|
146
|
+
_context2.next = 5;
|
|
147
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
|
|
148
|
+
case 5:
|
|
149
|
+
_context2.next = 7;
|
|
150
|
+
return this.apiCaller.call('emailCodeRegister', params);
|
|
151
|
+
case 7:
|
|
152
|
+
response = _context2.sent;
|
|
153
|
+
if (!(response.status && response.data)) {
|
|
154
|
+
_context2.next = 15;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
_response$data = response.data, user = _response$data.user, token = _response$data.token, refreshToken = _response$data.refreshToken, expiresAt = _response$data.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
|
|
158
|
+
if (token) {
|
|
159
|
+
this.store.currentUser = user;
|
|
160
|
+
this.store.isLoggedIn = true;
|
|
161
|
+
|
|
162
|
+
// 保存到本地存储
|
|
163
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
164
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
165
|
+
// if (refreshToken) {
|
|
166
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
167
|
+
// }
|
|
168
|
+
}
|
|
169
|
+
_context2.next = 13;
|
|
170
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
|
|
171
|
+
case 13:
|
|
172
|
+
_context2.next = 18;
|
|
173
|
+
break;
|
|
174
|
+
case 15:
|
|
175
|
+
this.store.error = response.message || '邮箱验证码注册失败';
|
|
176
|
+
_context2.next = 18;
|
|
177
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
178
|
+
error: this.store.error,
|
|
179
|
+
params: params
|
|
180
|
+
});
|
|
181
|
+
case 18:
|
|
182
|
+
return _context2.abrupt("return", response);
|
|
183
|
+
case 21:
|
|
184
|
+
_context2.prev = 21;
|
|
185
|
+
_context2.t0 = _context2["catch"](0);
|
|
186
|
+
this.store.error = '邮箱验证码注册失败';
|
|
187
|
+
_context2.next = 26;
|
|
188
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
189
|
+
error: this.store.error,
|
|
190
|
+
params: params
|
|
191
|
+
});
|
|
192
|
+
case 26:
|
|
193
|
+
throw _context2.t0;
|
|
194
|
+
case 27:
|
|
195
|
+
_context2.prev = 27;
|
|
196
|
+
this.store.isLoading = false;
|
|
197
|
+
return _context2.finish(27);
|
|
198
|
+
case 30:
|
|
199
|
+
case "end":
|
|
200
|
+
return _context2.stop();
|
|
201
|
+
}
|
|
202
|
+
}, _callee2, this, [[0, 21, 27, 30]]);
|
|
203
|
+
}));
|
|
204
|
+
function emailCodeRegister(_x) {
|
|
205
|
+
return _emailCodeRegister.apply(this, arguments);
|
|
206
|
+
}
|
|
207
|
+
return emailCodeRegister;
|
|
208
|
+
}()
|
|
209
|
+
/**
|
|
210
|
+
* 手机验证码注册
|
|
211
|
+
*/
|
|
212
|
+
)
|
|
213
|
+
}, {
|
|
214
|
+
key: "phoneCodeRegister",
|
|
215
|
+
value: (function () {
|
|
216
|
+
var _phoneCodeRegister = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
217
|
+
var response, _response$data2, user, token, refreshToken, expiresAt;
|
|
218
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
219
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
220
|
+
case 0:
|
|
221
|
+
_context3.prev = 0;
|
|
222
|
+
this.store.isLoading = true;
|
|
223
|
+
this.store.error = null;
|
|
224
|
+
_context3.next = 5;
|
|
225
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
|
|
226
|
+
case 5:
|
|
227
|
+
_context3.next = 7;
|
|
228
|
+
return this.apiCaller.call('phoneCodeRegister', params);
|
|
229
|
+
case 7:
|
|
230
|
+
response = _context3.sent;
|
|
231
|
+
if (!(response.status && response.data)) {
|
|
232
|
+
_context3.next = 15;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
_response$data2 = response.data, user = _response$data2.user, token = _response$data2.token, refreshToken = _response$data2.refreshToken, expiresAt = _response$data2.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
|
|
236
|
+
if (token) {
|
|
237
|
+
this.store.currentUser = user;
|
|
238
|
+
this.store.isLoggedIn = true;
|
|
239
|
+
|
|
240
|
+
// 保存到本地存储
|
|
241
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
242
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
243
|
+
// if (refreshToken) {
|
|
244
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
245
|
+
// }
|
|
246
|
+
}
|
|
247
|
+
_context3.next = 13;
|
|
248
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
|
|
249
|
+
case 13:
|
|
250
|
+
_context3.next = 18;
|
|
251
|
+
break;
|
|
252
|
+
case 15:
|
|
253
|
+
this.store.error = response.message || '注册失败';
|
|
254
|
+
_context3.next = 18;
|
|
255
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
256
|
+
error: this.store.error,
|
|
257
|
+
params: params
|
|
258
|
+
});
|
|
259
|
+
case 18:
|
|
260
|
+
return _context3.abrupt("return", response);
|
|
261
|
+
case 21:
|
|
262
|
+
_context3.prev = 21;
|
|
263
|
+
_context3.t0 = _context3["catch"](0);
|
|
264
|
+
this.store.error = _context3.t0.message || '注册失败';
|
|
265
|
+
_context3.next = 26;
|
|
266
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
267
|
+
error: this.store.error,
|
|
268
|
+
params: params
|
|
269
|
+
});
|
|
270
|
+
case 26:
|
|
271
|
+
throw _context3.t0;
|
|
272
|
+
case 27:
|
|
273
|
+
_context3.prev = 27;
|
|
274
|
+
this.store.isLoading = false;
|
|
275
|
+
return _context3.finish(27);
|
|
276
|
+
case 30:
|
|
277
|
+
case "end":
|
|
278
|
+
return _context3.stop();
|
|
279
|
+
}
|
|
280
|
+
}, _callee3, this, [[0, 21, 27, 30]]);
|
|
281
|
+
}));
|
|
282
|
+
function phoneCodeRegister(_x2) {
|
|
283
|
+
return _phoneCodeRegister.apply(this, arguments);
|
|
284
|
+
}
|
|
285
|
+
return phoneCodeRegister;
|
|
286
|
+
}())
|
|
287
|
+
}, {
|
|
288
|
+
key: "initialize",
|
|
289
|
+
value: function () {
|
|
290
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(core, options) {
|
|
291
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
292
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
293
|
+
case 0:
|
|
294
|
+
this.core = core;
|
|
295
|
+
|
|
296
|
+
// 初始化状态
|
|
297
|
+
this.store = _objectSpread({
|
|
298
|
+
currentUser: null,
|
|
299
|
+
isLoggedIn: false,
|
|
300
|
+
isLoading: false,
|
|
301
|
+
verificationCodeSent: {},
|
|
302
|
+
oauthConfig: options.oauthConfig || {},
|
|
303
|
+
error: null
|
|
304
|
+
}, options.store);
|
|
305
|
+
this.otherParams = options.otherParams || {};
|
|
306
|
+
|
|
307
|
+
// 获取渠道信息
|
|
308
|
+
this.channel = this.otherParams.channel || 'default';
|
|
309
|
+
|
|
310
|
+
// 获取依赖的插件
|
|
311
|
+
this.request = core.getPlugin('request');
|
|
312
|
+
this.window = core.getPlugin('window');
|
|
313
|
+
if (this.request) {
|
|
314
|
+
_context4.next = 8;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
throw new Error('RegisterAndLogin 模块需要 request 插件支持');
|
|
318
|
+
case 8:
|
|
319
|
+
if (this.window) {
|
|
320
|
+
_context4.next = 10;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
throw new Error('RegisterAndLogin 模块需要 window 插件支持');
|
|
324
|
+
case 10:
|
|
325
|
+
// 创建 API 调用器
|
|
326
|
+
this.apiCaller = createApiCaller(this.request, this.channel);
|
|
327
|
+
|
|
328
|
+
// 尝试从本地存储恢复登录状态
|
|
329
|
+
_context4.next = 13;
|
|
330
|
+
return this.restoreLoginState();
|
|
331
|
+
case 13:
|
|
332
|
+
// 预先调用获取区号的方法,初始内存缓存
|
|
333
|
+
this.getCountries();
|
|
334
|
+
console.log('[RegisterAndLogin] 初始化完成');
|
|
335
|
+
_context4.next = 17;
|
|
336
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onInited, {});
|
|
337
|
+
case 17:
|
|
338
|
+
case "end":
|
|
339
|
+
return _context4.stop();
|
|
340
|
+
}
|
|
341
|
+
}, _callee4, this);
|
|
342
|
+
}));
|
|
343
|
+
function initialize(_x3, _x4) {
|
|
344
|
+
return _initialize.apply(this, arguments);
|
|
345
|
+
}
|
|
346
|
+
return initialize;
|
|
347
|
+
}()
|
|
348
|
+
/**
|
|
349
|
+
* 从本地存储恢复登录状态
|
|
350
|
+
*/
|
|
351
|
+
}, {
|
|
352
|
+
key: "restoreLoginState",
|
|
353
|
+
value: (function () {
|
|
354
|
+
var _restoreLoginState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
355
|
+
var token, userInfo, user;
|
|
356
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
357
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
358
|
+
case 0:
|
|
359
|
+
_context5.prev = 0;
|
|
360
|
+
token = this.window.localStorage.getItem('auth_token');
|
|
361
|
+
userInfo = this.window.localStorage.getItem('user_info');
|
|
362
|
+
if (!(token && userInfo)) {
|
|
363
|
+
_context5.next = 9;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
user = JSON.parse(userInfo);
|
|
367
|
+
this.store.currentUser = user;
|
|
368
|
+
this.store.isLoggedIn = true;
|
|
369
|
+
|
|
370
|
+
// 验证 token 是否仍然有效
|
|
371
|
+
_context5.next = 9;
|
|
372
|
+
return this.validateToken(token);
|
|
373
|
+
case 9:
|
|
374
|
+
_context5.next = 15;
|
|
375
|
+
break;
|
|
376
|
+
case 11:
|
|
377
|
+
_context5.prev = 11;
|
|
378
|
+
_context5.t0 = _context5["catch"](0);
|
|
379
|
+
console.warn('[RegisterAndLogin] 恢复登录状态失败:', _context5.t0);
|
|
380
|
+
this.clearLoginState();
|
|
381
|
+
case 15:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context5.stop();
|
|
384
|
+
}
|
|
385
|
+
}, _callee5, this, [[0, 11]]);
|
|
386
|
+
}));
|
|
387
|
+
function restoreLoginState() {
|
|
388
|
+
return _restoreLoginState.apply(this, arguments);
|
|
389
|
+
}
|
|
390
|
+
return restoreLoginState;
|
|
391
|
+
}()
|
|
392
|
+
/**
|
|
393
|
+
* 验证 token 有效性
|
|
394
|
+
*/
|
|
395
|
+
)
|
|
396
|
+
}, {
|
|
397
|
+
key: "validateToken",
|
|
398
|
+
value: (function () {
|
|
399
|
+
var _validateToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(token) {
|
|
400
|
+
var response;
|
|
401
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
402
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
403
|
+
case 0:
|
|
404
|
+
_context6.prev = 0;
|
|
405
|
+
_context6.next = 3;
|
|
406
|
+
return this.apiCaller.call('validateToken', token);
|
|
407
|
+
case 3:
|
|
408
|
+
response = _context6.sent;
|
|
409
|
+
if (!(response.status && response.data)) {
|
|
410
|
+
_context6.next = 9;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
this.store.currentUser = response.data;
|
|
414
|
+
return _context6.abrupt("return", true);
|
|
415
|
+
case 9:
|
|
416
|
+
this.clearLoginState();
|
|
417
|
+
return _context6.abrupt("return", false);
|
|
418
|
+
case 11:
|
|
419
|
+
_context6.next = 18;
|
|
420
|
+
break;
|
|
421
|
+
case 13:
|
|
422
|
+
_context6.prev = 13;
|
|
423
|
+
_context6.t0 = _context6["catch"](0);
|
|
424
|
+
console.warn('[RegisterAndLogin] Token 验证失败:', _context6.t0);
|
|
425
|
+
this.clearLoginState();
|
|
426
|
+
return _context6.abrupt("return", false);
|
|
427
|
+
case 18:
|
|
428
|
+
case "end":
|
|
429
|
+
return _context6.stop();
|
|
430
|
+
}
|
|
431
|
+
}, _callee6, this, [[0, 13]]);
|
|
432
|
+
}));
|
|
433
|
+
function validateToken(_x5) {
|
|
434
|
+
return _validateToken.apply(this, arguments);
|
|
435
|
+
}
|
|
436
|
+
return validateToken;
|
|
437
|
+
}()
|
|
438
|
+
/**
|
|
439
|
+
* 清除登录状态
|
|
440
|
+
*/
|
|
441
|
+
)
|
|
442
|
+
}, {
|
|
443
|
+
key: "clearLoginState",
|
|
444
|
+
value: function clearLoginState() {
|
|
445
|
+
this.store.currentUser = null;
|
|
446
|
+
this.store.isLoggedIn = false;
|
|
447
|
+
this.window.localStorage.removeItem('auth_token');
|
|
448
|
+
this.window.localStorage.removeItem('user_info');
|
|
449
|
+
this.window.localStorage.removeItem('refresh_token');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* 发送邮箱验证码
|
|
454
|
+
*/
|
|
455
|
+
}, {
|
|
456
|
+
key: "sendEmailVerificationCode",
|
|
457
|
+
value: (function () {
|
|
458
|
+
var _sendEmailVerificationCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
|
|
459
|
+
var response, now;
|
|
460
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
461
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
462
|
+
case 0:
|
|
463
|
+
_context7.prev = 0;
|
|
464
|
+
this.store.isLoading = true;
|
|
465
|
+
this.store.error = null;
|
|
466
|
+
_context7.next = 5;
|
|
467
|
+
return this.apiCaller.call('sendEmailVerificationCode', params);
|
|
468
|
+
case 5:
|
|
469
|
+
response = _context7.sent;
|
|
470
|
+
if (!response.status) {
|
|
471
|
+
_context7.next = 13;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
// 记录验证码发送状态
|
|
475
|
+
now = Date.now();
|
|
476
|
+
this.store.verificationCodeSent[params.target] = {
|
|
477
|
+
sent: true,
|
|
478
|
+
sentAt: now,
|
|
479
|
+
expiresAt: now + 5 * 60 * 1000 // 5分钟过期
|
|
480
|
+
};
|
|
481
|
+
_context7.next = 11;
|
|
482
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
483
|
+
target: params.target,
|
|
484
|
+
purpose: params.purpose
|
|
485
|
+
});
|
|
486
|
+
case 11:
|
|
487
|
+
_context7.next = 16;
|
|
488
|
+
break;
|
|
489
|
+
case 13:
|
|
490
|
+
this.store.error = response.message || '发送验证码失败';
|
|
491
|
+
_context7.next = 16;
|
|
492
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
493
|
+
target: params.target,
|
|
494
|
+
error: this.store.error
|
|
495
|
+
});
|
|
496
|
+
case 16:
|
|
497
|
+
return _context7.abrupt("return", response);
|
|
498
|
+
case 19:
|
|
499
|
+
_context7.prev = 19;
|
|
500
|
+
_context7.t0 = _context7["catch"](0);
|
|
501
|
+
this.store.error = '发送验证码失败';
|
|
502
|
+
_context7.next = 24;
|
|
503
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
504
|
+
target: params.target,
|
|
505
|
+
error: this.store.error
|
|
506
|
+
});
|
|
507
|
+
case 24:
|
|
508
|
+
return _context7.abrupt("return", _context7.t0);
|
|
509
|
+
case 25:
|
|
510
|
+
_context7.prev = 25;
|
|
511
|
+
this.store.isLoading = false;
|
|
512
|
+
return _context7.finish(25);
|
|
513
|
+
case 28:
|
|
514
|
+
case "end":
|
|
515
|
+
return _context7.stop();
|
|
516
|
+
}
|
|
517
|
+
}, _callee7, this, [[0, 19, 25, 28]]);
|
|
518
|
+
}));
|
|
519
|
+
function sendEmailVerificationCode(_x6) {
|
|
520
|
+
return _sendEmailVerificationCode.apply(this, arguments);
|
|
521
|
+
}
|
|
522
|
+
return sendEmailVerificationCode;
|
|
523
|
+
}()
|
|
524
|
+
/**
|
|
525
|
+
* 发送邮箱登录验证码
|
|
526
|
+
*/
|
|
527
|
+
)
|
|
528
|
+
}, {
|
|
529
|
+
key: "sendEmailLoginCode",
|
|
530
|
+
value: (function () {
|
|
531
|
+
var _sendEmailLoginCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
532
|
+
var response, now;
|
|
533
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
534
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
535
|
+
case 0:
|
|
536
|
+
_context8.prev = 0;
|
|
537
|
+
this.store.isLoading = true;
|
|
538
|
+
this.store.error = null;
|
|
539
|
+
_context8.next = 5;
|
|
540
|
+
return this.apiCaller.call('sendEmailLoginCode', params);
|
|
541
|
+
case 5:
|
|
542
|
+
response = _context8.sent;
|
|
543
|
+
if (!response.status) {
|
|
544
|
+
_context8.next = 13;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
// 记录验证码发送状态
|
|
548
|
+
now = Date.now();
|
|
549
|
+
this.store.verificationCodeSent[params.target] = {
|
|
550
|
+
sent: true,
|
|
551
|
+
sentAt: now,
|
|
552
|
+
expiresAt: now + 5 * 60 * 1000 // 5分钟过期
|
|
553
|
+
};
|
|
554
|
+
_context8.next = 11;
|
|
555
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
556
|
+
target: params.target,
|
|
557
|
+
purpose: params.purpose
|
|
558
|
+
});
|
|
559
|
+
case 11:
|
|
560
|
+
_context8.next = 16;
|
|
561
|
+
break;
|
|
562
|
+
case 13:
|
|
563
|
+
this.store.error = response.message || '发送验证码失败';
|
|
564
|
+
_context8.next = 16;
|
|
565
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
566
|
+
target: params.target,
|
|
567
|
+
error: this.store.error
|
|
568
|
+
});
|
|
569
|
+
case 16:
|
|
570
|
+
return _context8.abrupt("return", response);
|
|
571
|
+
case 19:
|
|
572
|
+
_context8.prev = 19;
|
|
573
|
+
_context8.t0 = _context8["catch"](0);
|
|
574
|
+
this.store.error = '发送验证码失败';
|
|
575
|
+
_context8.next = 24;
|
|
576
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
577
|
+
target: params.target,
|
|
578
|
+
error: this.store.error
|
|
579
|
+
});
|
|
580
|
+
case 24:
|
|
581
|
+
return _context8.abrupt("return", _context8.t0);
|
|
582
|
+
case 25:
|
|
583
|
+
_context8.prev = 25;
|
|
584
|
+
this.store.isLoading = false;
|
|
585
|
+
return _context8.finish(25);
|
|
586
|
+
case 28:
|
|
587
|
+
case "end":
|
|
588
|
+
return _context8.stop();
|
|
589
|
+
}
|
|
590
|
+
}, _callee8, this, [[0, 19, 25, 28]]);
|
|
591
|
+
}));
|
|
592
|
+
function sendEmailLoginCode(_x7) {
|
|
593
|
+
return _sendEmailLoginCode.apply(this, arguments);
|
|
594
|
+
}
|
|
595
|
+
return sendEmailLoginCode;
|
|
596
|
+
}()
|
|
597
|
+
/**
|
|
598
|
+
* 发送手机号注册验证码
|
|
599
|
+
*/
|
|
600
|
+
)
|
|
601
|
+
}, {
|
|
602
|
+
key: "sendSmsRegisterCode",
|
|
603
|
+
value: (function () {
|
|
604
|
+
var _sendSmsRegisterCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
605
|
+
var response, now;
|
|
606
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
607
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
608
|
+
case 0:
|
|
609
|
+
_context9.prev = 0;
|
|
610
|
+
this.store.isLoading = true;
|
|
611
|
+
this.store.error = null;
|
|
612
|
+
_context9.next = 5;
|
|
613
|
+
return this.apiCaller.call('sendSmsRegisterCode', params);
|
|
614
|
+
case 5:
|
|
615
|
+
response = _context9.sent;
|
|
616
|
+
if (!response.status) {
|
|
617
|
+
_context9.next = 13;
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
// 记录验证码发送状态
|
|
621
|
+
now = Date.now();
|
|
622
|
+
this.store.verificationCodeSent[params.phone] = {
|
|
623
|
+
sent: true,
|
|
624
|
+
sentAt: now,
|
|
625
|
+
expiresAt: now + 5 * 60 * 1000 // 5分钟过期
|
|
626
|
+
};
|
|
627
|
+
_context9.next = 11;
|
|
628
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationSent, {
|
|
629
|
+
target: params.phone,
|
|
630
|
+
purpose: VerificationPurpose.REGISTER
|
|
631
|
+
});
|
|
632
|
+
case 11:
|
|
633
|
+
_context9.next = 16;
|
|
634
|
+
break;
|
|
635
|
+
case 13:
|
|
636
|
+
this.store.error = response.message || '发送注册验证码失败';
|
|
637
|
+
_context9.next = 16;
|
|
638
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
|
|
639
|
+
target: params.phone,
|
|
640
|
+
error: this.store.error
|
|
641
|
+
});
|
|
642
|
+
case 16:
|
|
643
|
+
return _context9.abrupt("return", response);
|
|
644
|
+
case 19:
|
|
645
|
+
_context9.prev = 19;
|
|
646
|
+
_context9.t0 = _context9["catch"](0);
|
|
647
|
+
this.store.error = '发送注册验证码失败';
|
|
648
|
+
_context9.next = 24;
|
|
649
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
|
|
650
|
+
target: params.phone,
|
|
651
|
+
error: this.store.error
|
|
652
|
+
});
|
|
653
|
+
case 24:
|
|
654
|
+
return _context9.abrupt("return", _context9.t0);
|
|
655
|
+
case 25:
|
|
656
|
+
_context9.prev = 25;
|
|
657
|
+
this.store.isLoading = false;
|
|
658
|
+
return _context9.finish(25);
|
|
659
|
+
case 28:
|
|
660
|
+
case "end":
|
|
661
|
+
return _context9.stop();
|
|
662
|
+
}
|
|
663
|
+
}, _callee9, this, [[0, 19, 25, 28]]);
|
|
664
|
+
}));
|
|
665
|
+
function sendSmsRegisterCode(_x8) {
|
|
666
|
+
return _sendSmsRegisterCode.apply(this, arguments);
|
|
667
|
+
}
|
|
668
|
+
return sendSmsRegisterCode;
|
|
669
|
+
}()
|
|
670
|
+
/**
|
|
671
|
+
* 发送邮箱注册邀请链接
|
|
672
|
+
*/
|
|
673
|
+
)
|
|
674
|
+
}, {
|
|
675
|
+
key: "sendEmailRegisterLink",
|
|
676
|
+
value: (function () {
|
|
677
|
+
var _sendEmailRegisterLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(email) {
|
|
678
|
+
var response, _response$data3, now;
|
|
679
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
680
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
681
|
+
case 0:
|
|
682
|
+
_context10.prev = 0;
|
|
683
|
+
this.store.isLoading = true;
|
|
684
|
+
this.store.error = null;
|
|
685
|
+
_context10.next = 5;
|
|
686
|
+
return this.apiCaller.call('sendEmailRegisterLink', email);
|
|
687
|
+
case 5:
|
|
688
|
+
response = _context10.sent;
|
|
689
|
+
if (!response.status) {
|
|
690
|
+
_context10.next = 14;
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
// 保存返回的 code
|
|
694
|
+
if ((_response$data3 = response.data) !== null && _response$data3 !== void 0 && _response$data3.code) {
|
|
695
|
+
this.store.emailRegisterLinkCode = response.data.code;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// 记录邀请链接发送状态
|
|
699
|
+
now = Date.now();
|
|
700
|
+
this.store.verificationCodeSent[email] = {
|
|
701
|
+
sent: true,
|
|
702
|
+
sentAt: now,
|
|
703
|
+
expiresAt: now + 24 * 60 * 60 * 1000 // 24小时过期
|
|
704
|
+
};
|
|
705
|
+
_context10.next = 12;
|
|
706
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
707
|
+
target: email,
|
|
708
|
+
purpose: VerificationPurpose.REGISTER
|
|
709
|
+
});
|
|
710
|
+
case 12:
|
|
711
|
+
_context10.next = 17;
|
|
712
|
+
break;
|
|
713
|
+
case 14:
|
|
714
|
+
this.store.error = response.message || '发送注册邀请链接失败';
|
|
715
|
+
_context10.next = 17;
|
|
716
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
717
|
+
target: email,
|
|
718
|
+
error: this.store.error
|
|
719
|
+
});
|
|
720
|
+
case 17:
|
|
721
|
+
return _context10.abrupt("return", response);
|
|
722
|
+
case 20:
|
|
723
|
+
_context10.prev = 20;
|
|
724
|
+
_context10.t0 = _context10["catch"](0);
|
|
725
|
+
this.store.error = '发送注册邀请链接失败';
|
|
726
|
+
_context10.next = 25;
|
|
727
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
728
|
+
target: email,
|
|
729
|
+
error: this.store.error
|
|
730
|
+
});
|
|
731
|
+
case 25:
|
|
732
|
+
return _context10.abrupt("return", _context10.t0);
|
|
733
|
+
case 26:
|
|
734
|
+
_context10.prev = 26;
|
|
735
|
+
this.store.isLoading = false;
|
|
736
|
+
return _context10.finish(26);
|
|
737
|
+
case 29:
|
|
738
|
+
case "end":
|
|
739
|
+
return _context10.stop();
|
|
740
|
+
}
|
|
741
|
+
}, _callee10, this, [[0, 20, 26, 29]]);
|
|
742
|
+
}));
|
|
743
|
+
function sendEmailRegisterLink(_x9) {
|
|
744
|
+
return _sendEmailRegisterLink.apply(this, arguments);
|
|
745
|
+
}
|
|
746
|
+
return sendEmailRegisterLink;
|
|
747
|
+
}()
|
|
748
|
+
/**
|
|
749
|
+
* 验证邮箱注册链接
|
|
750
|
+
*/
|
|
751
|
+
)
|
|
752
|
+
}, {
|
|
753
|
+
key: "verifyEmailRegistrationLink",
|
|
754
|
+
value: (function () {
|
|
755
|
+
var _verifyEmailRegistrationLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
756
|
+
var response;
|
|
757
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
758
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
759
|
+
case 0:
|
|
760
|
+
_context11.prev = 0;
|
|
761
|
+
this.store.isLoading = true;
|
|
762
|
+
this.store.error = null;
|
|
763
|
+
_context11.next = 5;
|
|
764
|
+
return this.apiCaller.call('verifyEmailRegistrationLink', params);
|
|
765
|
+
case 5:
|
|
766
|
+
response = _context11.sent;
|
|
767
|
+
if (!response.status) {
|
|
768
|
+
_context11.next = 11;
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
_context11.next = 9;
|
|
772
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationVerified, {
|
|
773
|
+
target: 'email-registration-link',
|
|
774
|
+
purpose: VerificationPurpose.REGISTER
|
|
775
|
+
});
|
|
776
|
+
case 9:
|
|
777
|
+
_context11.next = 14;
|
|
778
|
+
break;
|
|
779
|
+
case 11:
|
|
780
|
+
this.store.error = response.message || '邮箱注册链接验证失败';
|
|
781
|
+
_context11.next = 14;
|
|
782
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
783
|
+
target: 'email-registration-link',
|
|
784
|
+
error: this.store.error
|
|
785
|
+
});
|
|
786
|
+
case 14:
|
|
787
|
+
return _context11.abrupt("return", response);
|
|
788
|
+
case 17:
|
|
789
|
+
_context11.prev = 17;
|
|
790
|
+
_context11.t0 = _context11["catch"](0);
|
|
791
|
+
this.store.error = '邮箱注册链接验证失败';
|
|
792
|
+
_context11.next = 22;
|
|
793
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
794
|
+
target: 'email-registration-link',
|
|
795
|
+
error: this.store.error
|
|
796
|
+
});
|
|
797
|
+
case 22:
|
|
798
|
+
return _context11.abrupt("return", _context11.t0);
|
|
799
|
+
case 23:
|
|
800
|
+
_context11.prev = 23;
|
|
801
|
+
this.store.isLoading = false;
|
|
802
|
+
return _context11.finish(23);
|
|
803
|
+
case 26:
|
|
804
|
+
case "end":
|
|
805
|
+
return _context11.stop();
|
|
806
|
+
}
|
|
807
|
+
}, _callee11, this, [[0, 17, 23, 26]]);
|
|
808
|
+
}));
|
|
809
|
+
function verifyEmailRegistrationLink(_x10) {
|
|
810
|
+
return _verifyEmailRegistrationLink.apply(this, arguments);
|
|
811
|
+
}
|
|
812
|
+
return verifyEmailRegistrationLink;
|
|
813
|
+
}()
|
|
814
|
+
/**
|
|
815
|
+
* 邮箱密码登录
|
|
816
|
+
*/
|
|
817
|
+
)
|
|
818
|
+
}, {
|
|
819
|
+
key: "emailPasswordLogin",
|
|
820
|
+
value: (function () {
|
|
821
|
+
var _emailPasswordLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
|
|
822
|
+
var response;
|
|
823
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
824
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
825
|
+
case 0:
|
|
826
|
+
_context12.prev = 0;
|
|
827
|
+
this.store.isLoading = true;
|
|
828
|
+
this.store.error = null;
|
|
829
|
+
_context12.next = 5;
|
|
830
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
|
|
831
|
+
type: 'email-password',
|
|
832
|
+
email: params.email
|
|
833
|
+
});
|
|
834
|
+
case 5:
|
|
835
|
+
_context12.next = 7;
|
|
836
|
+
return this.apiCaller.call('emailPasswordLogin', params);
|
|
837
|
+
case 7:
|
|
838
|
+
response = _context12.sent;
|
|
839
|
+
if (!(response.status && response.data)) {
|
|
840
|
+
_context12.next = 17;
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
// 保存用户信息和 token
|
|
844
|
+
this.store.isLoggedIn = true;
|
|
845
|
+
this.store.userInfo = response.data.user;
|
|
846
|
+
this.store.token = response.data.token;
|
|
847
|
+
|
|
848
|
+
// 如果有 refreshToken,也保存
|
|
849
|
+
if (response.data.refreshToken) {
|
|
850
|
+
this.store.refreshToken = response.data.refreshToken;
|
|
851
|
+
}
|
|
852
|
+
_context12.next = 15;
|
|
853
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
|
|
854
|
+
user: response.data.user,
|
|
855
|
+
token: response.data.token,
|
|
856
|
+
loginType: 'email-password'
|
|
857
|
+
});
|
|
858
|
+
case 15:
|
|
859
|
+
_context12.next = 20;
|
|
860
|
+
break;
|
|
861
|
+
case 17:
|
|
862
|
+
this.store.error = response.message || '邮箱密码登录失败';
|
|
863
|
+
_context12.next = 20;
|
|
864
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
865
|
+
error: this.store.error,
|
|
866
|
+
loginType: 'email-password'
|
|
867
|
+
});
|
|
868
|
+
case 20:
|
|
869
|
+
return _context12.abrupt("return", response);
|
|
870
|
+
case 23:
|
|
871
|
+
_context12.prev = 23;
|
|
872
|
+
_context12.t0 = _context12["catch"](0);
|
|
873
|
+
this.store.error = '邮箱密码登录失败';
|
|
874
|
+
_context12.next = 28;
|
|
875
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
876
|
+
error: this.store.error,
|
|
877
|
+
loginType: 'email-password'
|
|
878
|
+
});
|
|
879
|
+
case 28:
|
|
880
|
+
return _context12.abrupt("return", _context12.t0);
|
|
881
|
+
case 29:
|
|
882
|
+
_context12.prev = 29;
|
|
883
|
+
this.store.isLoading = false;
|
|
884
|
+
return _context12.finish(29);
|
|
885
|
+
case 32:
|
|
886
|
+
case "end":
|
|
887
|
+
return _context12.stop();
|
|
888
|
+
}
|
|
889
|
+
}, _callee12, this, [[0, 23, 29, 32]]);
|
|
890
|
+
}));
|
|
891
|
+
function emailPasswordLogin(_x11) {
|
|
892
|
+
return _emailPasswordLogin.apply(this, arguments);
|
|
893
|
+
}
|
|
894
|
+
return emailPasswordLogin;
|
|
895
|
+
}()
|
|
896
|
+
/**
|
|
897
|
+
* 验证验证码
|
|
898
|
+
*/
|
|
899
|
+
)
|
|
900
|
+
}, {
|
|
901
|
+
key: "verifyCode",
|
|
902
|
+
value: (function () {
|
|
903
|
+
var _verifyCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
|
|
904
|
+
var response, hookName, _hookName;
|
|
905
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
906
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
907
|
+
case 0:
|
|
908
|
+
_context13.prev = 0;
|
|
909
|
+
this.store.isLoading = true;
|
|
910
|
+
this.store.error = null;
|
|
911
|
+
_context13.next = 5;
|
|
912
|
+
return this.apiCaller.call('verifyCode', params);
|
|
913
|
+
case 5:
|
|
914
|
+
response = _context13.sent;
|
|
915
|
+
if (!response.status) {
|
|
916
|
+
_context13.next = 12;
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
hookName = params.type === VerificationCodeType.EMAIL ? RegisterAndLoginHooks.onEmailVerificationVerified : RegisterAndLoginHooks.onSmsVerificationVerified;
|
|
920
|
+
_context13.next = 10;
|
|
921
|
+
return this.core.effects.emit(hookName, {
|
|
922
|
+
target: params.target,
|
|
923
|
+
purpose: params.purpose
|
|
924
|
+
});
|
|
925
|
+
case 10:
|
|
926
|
+
_context13.next = 16;
|
|
927
|
+
break;
|
|
928
|
+
case 12:
|
|
929
|
+
this.store.error = response.message || '验证码验证失败';
|
|
930
|
+
_hookName = params.type === VerificationCodeType.EMAIL ? RegisterAndLoginHooks.onEmailVerificationFailed : RegisterAndLoginHooks.onSmsVerificationFailed;
|
|
931
|
+
_context13.next = 16;
|
|
932
|
+
return this.core.effects.emit(_hookName, {
|
|
933
|
+
target: params.target,
|
|
934
|
+
error: this.store.error
|
|
935
|
+
});
|
|
936
|
+
case 16:
|
|
937
|
+
return _context13.abrupt("return", response);
|
|
938
|
+
case 19:
|
|
939
|
+
_context13.prev = 19;
|
|
940
|
+
_context13.t0 = _context13["catch"](0);
|
|
941
|
+
this.store.error = '验证码验证失败';
|
|
942
|
+
return _context13.abrupt("return", _context13.t0);
|
|
943
|
+
case 23:
|
|
944
|
+
_context13.prev = 23;
|
|
945
|
+
this.store.isLoading = false;
|
|
946
|
+
return _context13.finish(23);
|
|
947
|
+
case 26:
|
|
948
|
+
case "end":
|
|
949
|
+
return _context13.stop();
|
|
950
|
+
}
|
|
951
|
+
}, _callee13, this, [[0, 19, 23, 26]]);
|
|
952
|
+
}));
|
|
953
|
+
function verifyCode(_x12) {
|
|
954
|
+
return _verifyCode.apply(this, arguments);
|
|
955
|
+
}
|
|
956
|
+
return verifyCode;
|
|
957
|
+
}()
|
|
958
|
+
/**
|
|
959
|
+
* 用户注册
|
|
960
|
+
*/
|
|
961
|
+
)
|
|
962
|
+
}, {
|
|
963
|
+
key: "register",
|
|
964
|
+
value: (function () {
|
|
965
|
+
var _register = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
|
|
966
|
+
var response, _response$data4, user, token, refreshToken, expiresAt;
|
|
967
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
968
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
969
|
+
case 0:
|
|
970
|
+
_context14.prev = 0;
|
|
971
|
+
this.store.isLoading = true;
|
|
972
|
+
this.store.error = null;
|
|
973
|
+
_context14.next = 5;
|
|
974
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
|
|
975
|
+
case 5:
|
|
976
|
+
_context14.next = 7;
|
|
977
|
+
return this.apiCaller.call('register', params);
|
|
978
|
+
case 7:
|
|
979
|
+
response = _context14.sent;
|
|
980
|
+
if (!(response.status && response.data)) {
|
|
981
|
+
_context14.next = 15;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
_response$data4 = response.data, user = _response$data4.user, token = _response$data4.token, refreshToken = _response$data4.refreshToken, expiresAt = _response$data4.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
|
|
985
|
+
if (token) {
|
|
986
|
+
this.store.currentUser = user;
|
|
987
|
+
this.store.isLoggedIn = true;
|
|
988
|
+
|
|
989
|
+
// 保存到本地存储
|
|
990
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
991
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
992
|
+
// if (refreshToken) {
|
|
993
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
994
|
+
// }
|
|
995
|
+
}
|
|
996
|
+
_context14.next = 13;
|
|
997
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
|
|
998
|
+
case 13:
|
|
999
|
+
_context14.next = 18;
|
|
1000
|
+
break;
|
|
1001
|
+
case 15:
|
|
1002
|
+
this.store.error = response.message || '注册失败';
|
|
1003
|
+
_context14.next = 18;
|
|
1004
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
1005
|
+
error: this.store.error,
|
|
1006
|
+
params: params
|
|
1007
|
+
});
|
|
1008
|
+
case 18:
|
|
1009
|
+
return _context14.abrupt("return", response);
|
|
1010
|
+
case 21:
|
|
1011
|
+
_context14.prev = 21;
|
|
1012
|
+
_context14.t0 = _context14["catch"](0);
|
|
1013
|
+
this.store.error = '注册失败';
|
|
1014
|
+
_context14.next = 26;
|
|
1015
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
|
|
1016
|
+
error: this.store.error,
|
|
1017
|
+
params: params
|
|
1018
|
+
});
|
|
1019
|
+
case 26:
|
|
1020
|
+
throw _context14.t0;
|
|
1021
|
+
case 27:
|
|
1022
|
+
_context14.prev = 27;
|
|
1023
|
+
this.store.isLoading = false;
|
|
1024
|
+
return _context14.finish(27);
|
|
1025
|
+
case 30:
|
|
1026
|
+
case "end":
|
|
1027
|
+
return _context14.stop();
|
|
1028
|
+
}
|
|
1029
|
+
}, _callee14, this, [[0, 21, 27, 30]]);
|
|
1030
|
+
}));
|
|
1031
|
+
function register(_x13) {
|
|
1032
|
+
return _register.apply(this, arguments);
|
|
1033
|
+
}
|
|
1034
|
+
return register;
|
|
1035
|
+
}()
|
|
1036
|
+
/**
|
|
1037
|
+
* 用户登录
|
|
1038
|
+
*/
|
|
1039
|
+
)
|
|
1040
|
+
}, {
|
|
1041
|
+
key: "login",
|
|
1042
|
+
value: (function () {
|
|
1043
|
+
var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
|
|
1044
|
+
var response, _response$data5, user, token, refreshToken;
|
|
1045
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1046
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1047
|
+
case 0:
|
|
1048
|
+
_context15.prev = 0;
|
|
1049
|
+
this.store.isLoading = true;
|
|
1050
|
+
this.store.error = null;
|
|
1051
|
+
_context15.next = 5;
|
|
1052
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, params);
|
|
1053
|
+
case 5:
|
|
1054
|
+
_context15.next = 7;
|
|
1055
|
+
return this.apiCaller.call('login', params);
|
|
1056
|
+
case 7:
|
|
1057
|
+
response = _context15.sent;
|
|
1058
|
+
if (!(response.status && response.data)) {
|
|
1059
|
+
_context15.next = 16;
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
_response$data5 = response.data, user = _response$data5.user, token = _response$data5.token, refreshToken = _response$data5.refreshToken;
|
|
1063
|
+
this.store.currentUser = user;
|
|
1064
|
+
this.store.isLoggedIn = true;
|
|
1065
|
+
|
|
1066
|
+
// 保存到本地存储
|
|
1067
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
1068
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1069
|
+
// if (refreshToken) {
|
|
1070
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
1071
|
+
// }
|
|
1072
|
+
_context15.next = 14;
|
|
1073
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, response.data);
|
|
1074
|
+
case 14:
|
|
1075
|
+
_context15.next = 19;
|
|
1076
|
+
break;
|
|
1077
|
+
case 16:
|
|
1078
|
+
this.store.error = response.message || '登录失败';
|
|
1079
|
+
_context15.next = 19;
|
|
1080
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1081
|
+
error: this.store.error,
|
|
1082
|
+
params: params
|
|
1083
|
+
});
|
|
1084
|
+
case 19:
|
|
1085
|
+
return _context15.abrupt("return", response);
|
|
1086
|
+
case 22:
|
|
1087
|
+
_context15.prev = 22;
|
|
1088
|
+
_context15.t0 = _context15["catch"](0);
|
|
1089
|
+
this.store.error = '登录失败';
|
|
1090
|
+
_context15.next = 27;
|
|
1091
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1092
|
+
error: this.store.error,
|
|
1093
|
+
params: params
|
|
1094
|
+
});
|
|
1095
|
+
case 27:
|
|
1096
|
+
throw _context15.t0;
|
|
1097
|
+
case 28:
|
|
1098
|
+
_context15.prev = 28;
|
|
1099
|
+
this.store.isLoading = false;
|
|
1100
|
+
return _context15.finish(28);
|
|
1101
|
+
case 31:
|
|
1102
|
+
case "end":
|
|
1103
|
+
return _context15.stop();
|
|
1104
|
+
}
|
|
1105
|
+
}, _callee15, this, [[0, 22, 28, 31]]);
|
|
1106
|
+
}));
|
|
1107
|
+
function login(_x14) {
|
|
1108
|
+
return _login.apply(this, arguments);
|
|
1109
|
+
}
|
|
1110
|
+
return login;
|
|
1111
|
+
}()
|
|
1112
|
+
/**
|
|
1113
|
+
* OAuth 登录
|
|
1114
|
+
*/
|
|
1115
|
+
)
|
|
1116
|
+
}, {
|
|
1117
|
+
key: "oauthLogin",
|
|
1118
|
+
value: (function () {
|
|
1119
|
+
var _oauthLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
|
|
1120
|
+
var response, _response$data6, user, token, refreshToken;
|
|
1121
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1122
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1123
|
+
case 0:
|
|
1124
|
+
_context16.prev = 0;
|
|
1125
|
+
this.store.isLoading = true;
|
|
1126
|
+
this.store.error = null;
|
|
1127
|
+
_context16.next = 5;
|
|
1128
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginStarted, params);
|
|
1129
|
+
case 5:
|
|
1130
|
+
_context16.next = 7;
|
|
1131
|
+
return this.apiCaller.call('oauthLogin', params);
|
|
1132
|
+
case 7:
|
|
1133
|
+
response = _context16.sent;
|
|
1134
|
+
if (!(response.status && response.data)) {
|
|
1135
|
+
_context16.next = 16;
|
|
1136
|
+
break;
|
|
1137
|
+
}
|
|
1138
|
+
_response$data6 = response.data, user = _response$data6.user, token = _response$data6.token, refreshToken = _response$data6.refreshToken;
|
|
1139
|
+
this.store.currentUser = user;
|
|
1140
|
+
this.store.isLoggedIn = true;
|
|
1141
|
+
|
|
1142
|
+
// 保存到本地存储
|
|
1143
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
1144
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1145
|
+
// if (refreshToken) {
|
|
1146
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
1147
|
+
// }
|
|
1148
|
+
_context16.next = 14;
|
|
1149
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginSuccess, response.data);
|
|
1150
|
+
case 14:
|
|
1151
|
+
_context16.next = 19;
|
|
1152
|
+
break;
|
|
1153
|
+
case 16:
|
|
1154
|
+
this.store.error = response.message || 'OAuth 登录失败';
|
|
1155
|
+
_context16.next = 19;
|
|
1156
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
|
|
1157
|
+
error: this.store.error,
|
|
1158
|
+
params: params
|
|
1159
|
+
});
|
|
1160
|
+
case 19:
|
|
1161
|
+
return _context16.abrupt("return", response);
|
|
1162
|
+
case 22:
|
|
1163
|
+
_context16.prev = 22;
|
|
1164
|
+
_context16.t0 = _context16["catch"](0);
|
|
1165
|
+
this.store.error = 'OAuth 登录失败';
|
|
1166
|
+
_context16.next = 27;
|
|
1167
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
|
|
1168
|
+
error: this.store.error,
|
|
1169
|
+
params: params
|
|
1170
|
+
});
|
|
1171
|
+
case 27:
|
|
1172
|
+
throw _context16.t0;
|
|
1173
|
+
case 28:
|
|
1174
|
+
_context16.prev = 28;
|
|
1175
|
+
this.store.isLoading = false;
|
|
1176
|
+
return _context16.finish(28);
|
|
1177
|
+
case 31:
|
|
1178
|
+
case "end":
|
|
1179
|
+
return _context16.stop();
|
|
1180
|
+
}
|
|
1181
|
+
}, _callee16, this, [[0, 22, 28, 31]]);
|
|
1182
|
+
}));
|
|
1183
|
+
function oauthLogin(_x15) {
|
|
1184
|
+
return _oauthLogin.apply(this, arguments);
|
|
1185
|
+
}
|
|
1186
|
+
return oauthLogin;
|
|
1187
|
+
}()
|
|
1188
|
+
/**
|
|
1189
|
+
* 用户登出
|
|
1190
|
+
*/
|
|
1191
|
+
)
|
|
1192
|
+
}, {
|
|
1193
|
+
key: "logout",
|
|
1194
|
+
value: (function () {
|
|
1195
|
+
var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1196
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1197
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1198
|
+
case 0:
|
|
1199
|
+
_context17.prev = 0;
|
|
1200
|
+
_context17.next = 3;
|
|
1201
|
+
return this.apiCaller.call('logout');
|
|
1202
|
+
case 3:
|
|
1203
|
+
_context17.next = 8;
|
|
1204
|
+
break;
|
|
1205
|
+
case 5:
|
|
1206
|
+
_context17.prev = 5;
|
|
1207
|
+
_context17.t0 = _context17["catch"](0);
|
|
1208
|
+
console.warn('[RegisterAndLogin] 登出接口调用失败:', _context17.t0);
|
|
1209
|
+
case 8:
|
|
1210
|
+
_context17.prev = 8;
|
|
1211
|
+
// 无论后端接口是否成功,都清除本地状态
|
|
1212
|
+
this.clearLoginState();
|
|
1213
|
+
return _context17.finish(8);
|
|
1214
|
+
case 11:
|
|
1215
|
+
case "end":
|
|
1216
|
+
return _context17.stop();
|
|
1217
|
+
}
|
|
1218
|
+
}, _callee17, this, [[0, 5, 8, 11]]);
|
|
1219
|
+
}));
|
|
1220
|
+
function logout() {
|
|
1221
|
+
return _logout.apply(this, arguments);
|
|
1222
|
+
}
|
|
1223
|
+
return logout;
|
|
1224
|
+
}() /** 发送重置密码邮箱链接 */)
|
|
1225
|
+
}, {
|
|
1226
|
+
key: "sendResetPasswordLink",
|
|
1227
|
+
value: (function () {
|
|
1228
|
+
var _sendResetPasswordLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
|
|
1229
|
+
var response;
|
|
1230
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1231
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1232
|
+
case 0:
|
|
1233
|
+
_context18.prev = 0;
|
|
1234
|
+
this.store.isLoading = true;
|
|
1235
|
+
this.store.error = null;
|
|
1236
|
+
_context18.next = 5;
|
|
1237
|
+
return this.apiCaller.call('sendResetPasswordLink', params);
|
|
1238
|
+
case 5:
|
|
1239
|
+
response = _context18.sent;
|
|
1240
|
+
if (response.status) {
|
|
1241
|
+
this.store.verificationCodeSent[params.email] = {
|
|
1242
|
+
sent: true,
|
|
1243
|
+
sentAt: Date.now(),
|
|
1244
|
+
expiresAt: Date.now() + 5 * 60 * 1000 // 5分钟后过期
|
|
1245
|
+
};
|
|
1246
|
+
this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
1247
|
+
email: params.email,
|
|
1248
|
+
purpose: 'reset-password-link'
|
|
1249
|
+
});
|
|
1250
|
+
} else {
|
|
1251
|
+
this.store.error = response.message || '发送重置密码链接失败';
|
|
1252
|
+
}
|
|
1253
|
+
return _context18.abrupt("return", response);
|
|
1254
|
+
case 10:
|
|
1255
|
+
_context18.prev = 10;
|
|
1256
|
+
_context18.t0 = _context18["catch"](0);
|
|
1257
|
+
this.store.error = '发送重置密码链接失败';
|
|
1258
|
+
return _context18.abrupt("return", _context18.t0);
|
|
1259
|
+
case 14:
|
|
1260
|
+
_context18.prev = 14;
|
|
1261
|
+
this.store.isLoading = false;
|
|
1262
|
+
return _context18.finish(14);
|
|
1263
|
+
case 17:
|
|
1264
|
+
case "end":
|
|
1265
|
+
return _context18.stop();
|
|
1266
|
+
}
|
|
1267
|
+
}, _callee18, this, [[0, 10, 14, 17]]);
|
|
1268
|
+
}));
|
|
1269
|
+
function sendResetPasswordLink(_x16) {
|
|
1270
|
+
return _sendResetPasswordLink.apply(this, arguments);
|
|
1271
|
+
}
|
|
1272
|
+
return sendResetPasswordLink;
|
|
1273
|
+
}() /** 检测重置密码链接code有效性 */)
|
|
1274
|
+
}, {
|
|
1275
|
+
key: "checkResetPasswordCode",
|
|
1276
|
+
value: (function () {
|
|
1277
|
+
var _checkResetPasswordCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
|
|
1278
|
+
var response;
|
|
1279
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1280
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1281
|
+
case 0:
|
|
1282
|
+
_context19.prev = 0;
|
|
1283
|
+
this.store.isLoading = true;
|
|
1284
|
+
this.store.error = null;
|
|
1285
|
+
_context19.next = 5;
|
|
1286
|
+
return this.apiCaller.call('checkResetPasswordCode', params);
|
|
1287
|
+
case 5:
|
|
1288
|
+
response = _context19.sent;
|
|
1289
|
+
if (!response.status) {
|
|
1290
|
+
this.store.error = response.message || '验证码无效';
|
|
1291
|
+
}
|
|
1292
|
+
return _context19.abrupt("return", response);
|
|
1293
|
+
case 10:
|
|
1294
|
+
_context19.prev = 10;
|
|
1295
|
+
_context19.t0 = _context19["catch"](0);
|
|
1296
|
+
this.store.error = '验证码验证失败';
|
|
1297
|
+
return _context19.abrupt("return", _context19.t0);
|
|
1298
|
+
case 14:
|
|
1299
|
+
_context19.prev = 14;
|
|
1300
|
+
this.store.isLoading = false;
|
|
1301
|
+
return _context19.finish(14);
|
|
1302
|
+
case 17:
|
|
1303
|
+
case "end":
|
|
1304
|
+
return _context19.stop();
|
|
1305
|
+
}
|
|
1306
|
+
}, _callee19, this, [[0, 10, 14, 17]]);
|
|
1307
|
+
}));
|
|
1308
|
+
function checkResetPasswordCode(_x17) {
|
|
1309
|
+
return _checkResetPasswordCode.apply(this, arguments);
|
|
1310
|
+
}
|
|
1311
|
+
return checkResetPasswordCode;
|
|
1312
|
+
}() /** 校验邮件链接 code 有效性 */)
|
|
1313
|
+
}, {
|
|
1314
|
+
key: "checkEmailLinkCode",
|
|
1315
|
+
value: (function () {
|
|
1316
|
+
var _checkEmailLinkCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
|
|
1317
|
+
var response;
|
|
1318
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1319
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1320
|
+
case 0:
|
|
1321
|
+
_context20.prev = 0;
|
|
1322
|
+
this.store.isLoading = true;
|
|
1323
|
+
this.store.error = null;
|
|
1324
|
+
_context20.next = 5;
|
|
1325
|
+
return this.apiCaller.call('checkEmailLinkCode', params);
|
|
1326
|
+
case 5:
|
|
1327
|
+
response = _context20.sent;
|
|
1328
|
+
if (!response.status) {
|
|
1329
|
+
this.store.error = response.message || '邮件链接验证码无效';
|
|
1330
|
+
}
|
|
1331
|
+
return _context20.abrupt("return", response);
|
|
1332
|
+
case 10:
|
|
1333
|
+
_context20.prev = 10;
|
|
1334
|
+
_context20.t0 = _context20["catch"](0);
|
|
1335
|
+
this.store.error = '邮件链接验证码验证失败';
|
|
1336
|
+
return _context20.abrupt("return", _context20.t0);
|
|
1337
|
+
case 14:
|
|
1338
|
+
_context20.prev = 14;
|
|
1339
|
+
this.store.isLoading = false;
|
|
1340
|
+
return _context20.finish(14);
|
|
1341
|
+
case 17:
|
|
1342
|
+
case "end":
|
|
1343
|
+
return _context20.stop();
|
|
1344
|
+
}
|
|
1345
|
+
}, _callee20, this, [[0, 10, 14, 17]]);
|
|
1346
|
+
}));
|
|
1347
|
+
function checkEmailLinkCode(_x18) {
|
|
1348
|
+
return _checkEmailLinkCode.apply(this, arguments);
|
|
1349
|
+
}
|
|
1350
|
+
return checkEmailLinkCode;
|
|
1351
|
+
}() /** 通过code重置密码 */)
|
|
1352
|
+
}, {
|
|
1353
|
+
key: "resetPasswordByCode",
|
|
1354
|
+
value: (function () {
|
|
1355
|
+
var _resetPasswordByCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
|
|
1356
|
+
var response;
|
|
1357
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1358
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1359
|
+
case 0:
|
|
1360
|
+
_context21.prev = 0;
|
|
1361
|
+
this.store.isLoading = true;
|
|
1362
|
+
this.store.error = null;
|
|
1363
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
|
|
1364
|
+
code: params.code
|
|
1365
|
+
});
|
|
1366
|
+
_context21.next = 6;
|
|
1367
|
+
return this.apiCaller.call('resetPasswordByCode', params);
|
|
1368
|
+
case 6:
|
|
1369
|
+
response = _context21.sent;
|
|
1370
|
+
if (response.status) {
|
|
1371
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
|
|
1372
|
+
code: params.code
|
|
1373
|
+
});
|
|
1374
|
+
} else {
|
|
1375
|
+
this.store.error = response.message || '密码重置失败';
|
|
1376
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1377
|
+
code: params.code,
|
|
1378
|
+
error: this.store.error
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
return _context21.abrupt("return", response);
|
|
1382
|
+
case 11:
|
|
1383
|
+
_context21.prev = 11;
|
|
1384
|
+
_context21.t0 = _context21["catch"](0);
|
|
1385
|
+
this.store.error = '密码重置失败';
|
|
1386
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1387
|
+
code: params.code,
|
|
1388
|
+
error: this.store.error
|
|
1389
|
+
});
|
|
1390
|
+
return _context21.abrupt("return", _context21.t0);
|
|
1391
|
+
case 16:
|
|
1392
|
+
_context21.prev = 16;
|
|
1393
|
+
this.store.isLoading = false;
|
|
1394
|
+
return _context21.finish(16);
|
|
1395
|
+
case 19:
|
|
1396
|
+
case "end":
|
|
1397
|
+
return _context21.stop();
|
|
1398
|
+
}
|
|
1399
|
+
}, _callee21, this, [[0, 11, 16, 19]]);
|
|
1400
|
+
}));
|
|
1401
|
+
function resetPasswordByCode(_x19) {
|
|
1402
|
+
return _resetPasswordByCode.apply(this, arguments);
|
|
1403
|
+
}
|
|
1404
|
+
return resetPasswordByCode;
|
|
1405
|
+
}()
|
|
1406
|
+
/**
|
|
1407
|
+
* 重置密码
|
|
1408
|
+
*/
|
|
1409
|
+
)
|
|
1410
|
+
}, {
|
|
1411
|
+
key: "resetPassword",
|
|
1412
|
+
value: (function () {
|
|
1413
|
+
var _resetPassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
|
|
1414
|
+
var response, key;
|
|
1415
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1416
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1417
|
+
case 0:
|
|
1418
|
+
_context22.prev = 0;
|
|
1419
|
+
this.store.isLoading = true;
|
|
1420
|
+
this.store.error = null;
|
|
1421
|
+
|
|
1422
|
+
// 根据类型触发不同的事件
|
|
1423
|
+
if (params.type === 'email') {
|
|
1424
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
|
|
1425
|
+
email: params.target.email
|
|
1426
|
+
});
|
|
1427
|
+
} else {
|
|
1428
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
|
|
1429
|
+
phone: params.target.phone
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
if (!(params.type === 'email')) {
|
|
1433
|
+
_context22.next = 12;
|
|
1434
|
+
break;
|
|
1435
|
+
}
|
|
1436
|
+
if (params.target.email) {
|
|
1437
|
+
_context22.next = 7;
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
throw new Error('邮箱地址不能为空');
|
|
1441
|
+
case 7:
|
|
1442
|
+
_context22.next = 9;
|
|
1443
|
+
return this.apiCaller.call('resetPasswordByEmail', {
|
|
1444
|
+
email: params.target.email,
|
|
1445
|
+
password: params.password,
|
|
1446
|
+
code: params.code
|
|
1447
|
+
});
|
|
1448
|
+
case 9:
|
|
1449
|
+
response = _context22.sent;
|
|
1450
|
+
_context22.next = 17;
|
|
1451
|
+
break;
|
|
1452
|
+
case 12:
|
|
1453
|
+
if (!(!params.target.phone || !params.target.country_calling_code)) {
|
|
1454
|
+
_context22.next = 14;
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
throw new Error('手机号和国家区号不能为空');
|
|
1458
|
+
case 14:
|
|
1459
|
+
_context22.next = 16;
|
|
1460
|
+
return this.apiCaller.call('resetPasswordByPhone', {
|
|
1461
|
+
phone: params.target.phone,
|
|
1462
|
+
password: params.password,
|
|
1463
|
+
code: params.code,
|
|
1464
|
+
country_calling_code: params.target.country_calling_code
|
|
1465
|
+
});
|
|
1466
|
+
case 16:
|
|
1467
|
+
response = _context22.sent;
|
|
1468
|
+
case 17:
|
|
1469
|
+
if (response.status) {
|
|
1470
|
+
// 清除验证码发送状态
|
|
1471
|
+
key = params.type === 'email' ? params.target.email : params.target.phone;
|
|
1472
|
+
if (this.store.verificationCodeSent[key]) {
|
|
1473
|
+
delete this.store.verificationCodeSent[key];
|
|
1474
|
+
}
|
|
1475
|
+
if (params.type === 'email') {
|
|
1476
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
|
|
1477
|
+
email: params.target.email
|
|
1478
|
+
});
|
|
1479
|
+
} else {
|
|
1480
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
|
|
1481
|
+
phone: params.target.phone
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
} else {
|
|
1485
|
+
this.store.error = response.message || '密码重置失败';
|
|
1486
|
+
if (params.type === 'email') {
|
|
1487
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1488
|
+
email: params.target.email,
|
|
1489
|
+
error: this.store.error
|
|
1490
|
+
});
|
|
1491
|
+
} else {
|
|
1492
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1493
|
+
phone: params.target.phone,
|
|
1494
|
+
error: this.store.error
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return _context22.abrupt("return", response);
|
|
1499
|
+
case 21:
|
|
1500
|
+
_context22.prev = 21;
|
|
1501
|
+
_context22.t0 = _context22["catch"](0);
|
|
1502
|
+
this.store.error = '密码重置失败';
|
|
1503
|
+
if (params.type === 'email') {
|
|
1504
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1505
|
+
email: params.target.email,
|
|
1506
|
+
error: this.store.error
|
|
1507
|
+
});
|
|
1508
|
+
} else {
|
|
1509
|
+
this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
|
|
1510
|
+
phone: params.target.phone,
|
|
1511
|
+
error: this.store.error
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
return _context22.abrupt("return", _context22.t0);
|
|
1515
|
+
case 26:
|
|
1516
|
+
_context22.prev = 26;
|
|
1517
|
+
this.store.isLoading = false;
|
|
1518
|
+
return _context22.finish(26);
|
|
1519
|
+
case 29:
|
|
1520
|
+
case "end":
|
|
1521
|
+
return _context22.stop();
|
|
1522
|
+
}
|
|
1523
|
+
}, _callee22, this, [[0, 21, 26, 29]]);
|
|
1524
|
+
}));
|
|
1525
|
+
function resetPassword(_x20) {
|
|
1526
|
+
return _resetPassword.apply(this, arguments);
|
|
1527
|
+
}
|
|
1528
|
+
return resetPassword;
|
|
1529
|
+
}() /** 发送手机登录验证码 */)
|
|
1530
|
+
}, {
|
|
1531
|
+
key: "sendSmsLoginCode",
|
|
1532
|
+
value: (function () {
|
|
1533
|
+
var _sendSmsLoginCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
|
|
1534
|
+
var response, now;
|
|
1535
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1536
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1537
|
+
case 0:
|
|
1538
|
+
_context23.prev = 0;
|
|
1539
|
+
this.store.isLoading = true;
|
|
1540
|
+
this.store.error = null;
|
|
1541
|
+
_context23.next = 5;
|
|
1542
|
+
return this.apiCaller.call('sendSmsLoginCode', params);
|
|
1543
|
+
case 5:
|
|
1544
|
+
response = _context23.sent;
|
|
1545
|
+
if (!response.status) {
|
|
1546
|
+
_context23.next = 13;
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
// 记录验证码发送状态
|
|
1550
|
+
now = Date.now();
|
|
1551
|
+
this.store.verificationCodeSent[params.phone] = {
|
|
1552
|
+
sent: true,
|
|
1553
|
+
sentAt: now,
|
|
1554
|
+
expiresAt: now + 5 * 60 * 1000 // 5分钟过期
|
|
1555
|
+
};
|
|
1556
|
+
_context23.next = 11;
|
|
1557
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationSent, {
|
|
1558
|
+
target: params.phone,
|
|
1559
|
+
purpose: VerificationPurpose.LOGIN
|
|
1560
|
+
});
|
|
1561
|
+
case 11:
|
|
1562
|
+
_context23.next = 16;
|
|
1563
|
+
break;
|
|
1564
|
+
case 13:
|
|
1565
|
+
this.store.error = response.message || '发送登录验证码失败';
|
|
1566
|
+
_context23.next = 16;
|
|
1567
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
|
|
1568
|
+
target: params.phone,
|
|
1569
|
+
error: this.store.error
|
|
1570
|
+
});
|
|
1571
|
+
case 16:
|
|
1572
|
+
return _context23.abrupt("return", response);
|
|
1573
|
+
case 19:
|
|
1574
|
+
_context23.prev = 19;
|
|
1575
|
+
_context23.t0 = _context23["catch"](0);
|
|
1576
|
+
this.store.error = '发送登录验证码失败';
|
|
1577
|
+
_context23.next = 24;
|
|
1578
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
|
|
1579
|
+
target: params.phone,
|
|
1580
|
+
error: this.store.error
|
|
1581
|
+
});
|
|
1582
|
+
case 24:
|
|
1583
|
+
return _context23.abrupt("return", _context23.t0);
|
|
1584
|
+
case 25:
|
|
1585
|
+
_context23.prev = 25;
|
|
1586
|
+
this.store.isLoading = false;
|
|
1587
|
+
return _context23.finish(25);
|
|
1588
|
+
case 28:
|
|
1589
|
+
case "end":
|
|
1590
|
+
return _context23.stop();
|
|
1591
|
+
}
|
|
1592
|
+
}, _callee23, this, [[0, 19, 25, 28]]);
|
|
1593
|
+
}));
|
|
1594
|
+
function sendSmsLoginCode(_x21) {
|
|
1595
|
+
return _sendSmsLoginCode.apply(this, arguments);
|
|
1596
|
+
}
|
|
1597
|
+
return sendSmsLoginCode;
|
|
1598
|
+
}() /** 手机号+短信验证码登录 */)
|
|
1599
|
+
}, {
|
|
1600
|
+
key: "phoneCodeLogin",
|
|
1601
|
+
value: (function () {
|
|
1602
|
+
var _phoneCodeLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
|
|
1603
|
+
var response;
|
|
1604
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1605
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1606
|
+
case 0:
|
|
1607
|
+
_context24.prev = 0;
|
|
1608
|
+
this.store.isLoading = true;
|
|
1609
|
+
this.store.error = null;
|
|
1610
|
+
_context24.next = 5;
|
|
1611
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
|
|
1612
|
+
type: 'phone-code',
|
|
1613
|
+
phone: params.phone
|
|
1614
|
+
});
|
|
1615
|
+
case 5:
|
|
1616
|
+
_context24.next = 7;
|
|
1617
|
+
return this.apiCaller.call('phoneCodeLogin', params);
|
|
1618
|
+
case 7:
|
|
1619
|
+
response = _context24.sent;
|
|
1620
|
+
if (!(response.status && response.data)) {
|
|
1621
|
+
_context24.next = 17;
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
// 保存用户信息和 token
|
|
1625
|
+
this.store.isLoggedIn = true;
|
|
1626
|
+
this.store.userInfo = response.data.user;
|
|
1627
|
+
this.store.token = response.data.token;
|
|
1628
|
+
|
|
1629
|
+
// 如果有 refreshToken,也保存
|
|
1630
|
+
if (response.data.refreshToken) {
|
|
1631
|
+
this.store.refreshToken = response.data.refreshToken;
|
|
1632
|
+
}
|
|
1633
|
+
_context24.next = 15;
|
|
1634
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
|
|
1635
|
+
user: response.data.user,
|
|
1636
|
+
token: response.data.token,
|
|
1637
|
+
loginType: 'phone-code'
|
|
1638
|
+
});
|
|
1639
|
+
case 15:
|
|
1640
|
+
_context24.next = 20;
|
|
1641
|
+
break;
|
|
1642
|
+
case 17:
|
|
1643
|
+
this.store.error = response.message || '手机号验证码登录失败';
|
|
1644
|
+
_context24.next = 20;
|
|
1645
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1646
|
+
error: this.store.error,
|
|
1647
|
+
loginType: 'phone-code'
|
|
1648
|
+
});
|
|
1649
|
+
case 20:
|
|
1650
|
+
return _context24.abrupt("return", response);
|
|
1651
|
+
case 23:
|
|
1652
|
+
_context24.prev = 23;
|
|
1653
|
+
_context24.t0 = _context24["catch"](0);
|
|
1654
|
+
this.store.error = '手机号验证码登录失败';
|
|
1655
|
+
_context24.next = 28;
|
|
1656
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1657
|
+
error: this.store.error,
|
|
1658
|
+
loginType: 'phone-code'
|
|
1659
|
+
});
|
|
1660
|
+
case 28:
|
|
1661
|
+
return _context24.abrupt("return", _context24.t0);
|
|
1662
|
+
case 29:
|
|
1663
|
+
_context24.prev = 29;
|
|
1664
|
+
this.store.isLoading = false;
|
|
1665
|
+
return _context24.finish(29);
|
|
1666
|
+
case 32:
|
|
1667
|
+
case "end":
|
|
1668
|
+
return _context24.stop();
|
|
1669
|
+
}
|
|
1670
|
+
}, _callee24, this, [[0, 23, 29, 32]]);
|
|
1671
|
+
}));
|
|
1672
|
+
function phoneCodeLogin(_x22) {
|
|
1673
|
+
return _phoneCodeLogin.apply(this, arguments);
|
|
1674
|
+
}
|
|
1675
|
+
return phoneCodeLogin;
|
|
1676
|
+
}())
|
|
1677
|
+
}, {
|
|
1678
|
+
key: "formatLoginParams",
|
|
1679
|
+
value: function formatLoginParams(params) {
|
|
1680
|
+
// 获取当前浏览器窗口的 URL
|
|
1681
|
+
var currentUrl = this.window.location.href;
|
|
1682
|
+
// 使用 URL 对象解析 URL
|
|
1683
|
+
var urlObj = new URL(currentUrl || '');
|
|
1684
|
+
// 获取 customer 参数的值
|
|
1685
|
+
var source_customer_id = urlObj.searchParams.get('customer');
|
|
1686
|
+
if (source_customer_id) {
|
|
1687
|
+
params.source_customer_id = parseInt(source_customer_id);
|
|
1688
|
+
}
|
|
1689
|
+
return params;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
/** Guest 登录 */
|
|
1693
|
+
}, {
|
|
1694
|
+
key: "guestLogin",
|
|
1695
|
+
value: (function () {
|
|
1696
|
+
var _guestLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1697
|
+
var guestCode, param, response, _response$data7;
|
|
1698
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1699
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1700
|
+
case 0:
|
|
1701
|
+
_context25.prev = 0;
|
|
1702
|
+
this.store.isLoading = true;
|
|
1703
|
+
this.store.error = null;
|
|
1704
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
|
|
1705
|
+
type: 'guest'
|
|
1706
|
+
});
|
|
1707
|
+
// 匿名登录 code
|
|
1708
|
+
guestCode = this.window.localStorage.getItem('guest_code') || '';
|
|
1709
|
+
param = {
|
|
1710
|
+
login_channel: this.channel
|
|
1711
|
+
};
|
|
1712
|
+
if (guestCode) {
|
|
1713
|
+
param.guest_code = guestCode;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
// 获取邀请id
|
|
1717
|
+
param = this.formatLoginParams(param);
|
|
1718
|
+
_context25.next = 10;
|
|
1719
|
+
return this.apiCaller.call('guestLogin', param);
|
|
1720
|
+
case 10:
|
|
1721
|
+
response = _context25.sent;
|
|
1722
|
+
if (response.status && response.data) {
|
|
1723
|
+
// 保存用户信息和 token
|
|
1724
|
+
this.store.isLoggedIn = true;
|
|
1725
|
+
this.store.userInfo = response.data.user;
|
|
1726
|
+
this.store.token = response.data.token;
|
|
1727
|
+
|
|
1728
|
+
// 如果有 refreshToken,也保存
|
|
1729
|
+
if (response.data.refreshToken) {
|
|
1730
|
+
this.store.refreshToken = response.data.refreshToken;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// 设置匿名登录code
|
|
1734
|
+
if ((_response$data7 = response.data) !== null && _response$data7 !== void 0 && (_response$data7 = _response$data7.customer) !== null && _response$data7 !== void 0 && _response$data7.guest_code) {
|
|
1735
|
+
this.window.localStorage.setItem('guest_code', response.data.customer.guest_code);
|
|
1736
|
+
}
|
|
1737
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
|
|
1738
|
+
user: response.data.user,
|
|
1739
|
+
token: response.data.token,
|
|
1740
|
+
loginType: 'guest'
|
|
1741
|
+
});
|
|
1742
|
+
} else {
|
|
1743
|
+
this.store.error = response.message || 'Guest 登录失败';
|
|
1744
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1745
|
+
error: this.store.error,
|
|
1746
|
+
loginType: 'guest'
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
return _context25.abrupt("return", response);
|
|
1750
|
+
case 15:
|
|
1751
|
+
_context25.prev = 15;
|
|
1752
|
+
_context25.t0 = _context25["catch"](0);
|
|
1753
|
+
this.store.error = 'Guest 登录失败';
|
|
1754
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1755
|
+
error: this.store.error,
|
|
1756
|
+
loginType: 'guest'
|
|
1757
|
+
});
|
|
1758
|
+
return _context25.abrupt("return", _context25.t0);
|
|
1759
|
+
case 20:
|
|
1760
|
+
_context25.prev = 20;
|
|
1761
|
+
this.store.isLoading = false;
|
|
1762
|
+
return _context25.finish(20);
|
|
1763
|
+
case 23:
|
|
1764
|
+
case "end":
|
|
1765
|
+
return _context25.stop();
|
|
1766
|
+
}
|
|
1767
|
+
}, _callee25, this, [[0, 15, 20, 23]]);
|
|
1768
|
+
}));
|
|
1769
|
+
function guestLogin() {
|
|
1770
|
+
return _guestLogin.apply(this, arguments);
|
|
1771
|
+
}
|
|
1772
|
+
return guestLogin;
|
|
1773
|
+
}() /** 检查邮箱是否已注册 */)
|
|
1774
|
+
}, {
|
|
1775
|
+
key: "checkEmailExists",
|
|
1776
|
+
value: (function () {
|
|
1777
|
+
var _checkEmailExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
|
|
1778
|
+
var response;
|
|
1779
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1780
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1781
|
+
case 0:
|
|
1782
|
+
_context26.prev = 0;
|
|
1783
|
+
this.store.isLoading = true;
|
|
1784
|
+
this.store.error = null;
|
|
1785
|
+
_context26.next = 5;
|
|
1786
|
+
return this.apiCaller.call('checkEmailExists', params);
|
|
1787
|
+
case 5:
|
|
1788
|
+
response = _context26.sent;
|
|
1789
|
+
if (!response.status) {
|
|
1790
|
+
this.store.error = response.message || '检查邮箱失败';
|
|
1791
|
+
}
|
|
1792
|
+
return _context26.abrupt("return", response);
|
|
1793
|
+
case 10:
|
|
1794
|
+
_context26.prev = 10;
|
|
1795
|
+
_context26.t0 = _context26["catch"](0);
|
|
1796
|
+
this.store.error = '检查邮箱失败';
|
|
1797
|
+
return _context26.abrupt("return", _context26.t0);
|
|
1798
|
+
case 14:
|
|
1799
|
+
_context26.prev = 14;
|
|
1800
|
+
this.store.isLoading = false;
|
|
1801
|
+
return _context26.finish(14);
|
|
1802
|
+
case 17:
|
|
1803
|
+
case "end":
|
|
1804
|
+
return _context26.stop();
|
|
1805
|
+
}
|
|
1806
|
+
}, _callee26, this, [[0, 10, 14, 17]]);
|
|
1807
|
+
}));
|
|
1808
|
+
function checkEmailExists(_x23) {
|
|
1809
|
+
return _checkEmailExists.apply(this, arguments);
|
|
1810
|
+
}
|
|
1811
|
+
return checkEmailExists;
|
|
1812
|
+
}() /** 检查邮箱验证码是否有效 */)
|
|
1813
|
+
}, {
|
|
1814
|
+
key: "checkEmailCode",
|
|
1815
|
+
value: (function () {
|
|
1816
|
+
var _checkEmailCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
|
|
1817
|
+
var response;
|
|
1818
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1819
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1820
|
+
case 0:
|
|
1821
|
+
_context27.prev = 0;
|
|
1822
|
+
this.store.isLoading = true;
|
|
1823
|
+
this.store.error = null;
|
|
1824
|
+
_context27.next = 5;
|
|
1825
|
+
return this.apiCaller.call('checkEmailCode', params);
|
|
1826
|
+
case 5:
|
|
1827
|
+
response = _context27.sent;
|
|
1828
|
+
if (!response.status) {
|
|
1829
|
+
this.store.error = response.message || '检查邮箱验证码失败';
|
|
1830
|
+
}
|
|
1831
|
+
return _context27.abrupt("return", response);
|
|
1832
|
+
case 10:
|
|
1833
|
+
_context27.prev = 10;
|
|
1834
|
+
_context27.t0 = _context27["catch"](0);
|
|
1835
|
+
this.store.error = '检查邮箱验证码失败';
|
|
1836
|
+
return _context27.abrupt("return", _context27.t0);
|
|
1837
|
+
case 14:
|
|
1838
|
+
_context27.prev = 14;
|
|
1839
|
+
this.store.isLoading = false;
|
|
1840
|
+
return _context27.finish(14);
|
|
1841
|
+
case 17:
|
|
1842
|
+
case "end":
|
|
1843
|
+
return _context27.stop();
|
|
1844
|
+
}
|
|
1845
|
+
}, _callee27, this, [[0, 10, 14, 17]]);
|
|
1846
|
+
}));
|
|
1847
|
+
function checkEmailCode(_x24) {
|
|
1848
|
+
return _checkEmailCode.apply(this, arguments);
|
|
1849
|
+
}
|
|
1850
|
+
return checkEmailCode;
|
|
1851
|
+
}() /** 检查手机验证码是否有效 */)
|
|
1852
|
+
}, {
|
|
1853
|
+
key: "checkMobileCode",
|
|
1854
|
+
value: (function () {
|
|
1855
|
+
var _checkMobileCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
|
|
1856
|
+
var response;
|
|
1857
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1858
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1859
|
+
case 0:
|
|
1860
|
+
_context28.prev = 0;
|
|
1861
|
+
this.store.isLoading = true;
|
|
1862
|
+
this.store.error = null;
|
|
1863
|
+
_context28.next = 5;
|
|
1864
|
+
return this.apiCaller.call('checkMobileCode', params);
|
|
1865
|
+
case 5:
|
|
1866
|
+
response = _context28.sent;
|
|
1867
|
+
if (!response.status) {
|
|
1868
|
+
this.store.error = response.message || '检查手机验证码失败';
|
|
1869
|
+
}
|
|
1870
|
+
return _context28.abrupt("return", response);
|
|
1871
|
+
case 10:
|
|
1872
|
+
_context28.prev = 10;
|
|
1873
|
+
_context28.t0 = _context28["catch"](0);
|
|
1874
|
+
this.store.error = '检查手机验证码失败';
|
|
1875
|
+
return _context28.abrupt("return", _context28.t0);
|
|
1876
|
+
case 14:
|
|
1877
|
+
_context28.prev = 14;
|
|
1878
|
+
this.store.isLoading = false;
|
|
1879
|
+
return _context28.finish(14);
|
|
1880
|
+
case 17:
|
|
1881
|
+
case "end":
|
|
1882
|
+
return _context28.stop();
|
|
1883
|
+
}
|
|
1884
|
+
}, _callee28, this, [[0, 10, 14, 17]]);
|
|
1885
|
+
}));
|
|
1886
|
+
function checkMobileCode(_x25) {
|
|
1887
|
+
return _checkMobileCode.apply(this, arguments);
|
|
1888
|
+
}
|
|
1889
|
+
return checkMobileCode;
|
|
1890
|
+
}() /** 手机号密码登录 */)
|
|
1891
|
+
}, {
|
|
1892
|
+
key: "phonePasswordLogin",
|
|
1893
|
+
value: (function () {
|
|
1894
|
+
var _phonePasswordLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
|
|
1895
|
+
var response;
|
|
1896
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1897
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1898
|
+
case 0:
|
|
1899
|
+
_context29.prev = 0;
|
|
1900
|
+
this.store.isLoading = true;
|
|
1901
|
+
this.store.error = null;
|
|
1902
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
|
|
1903
|
+
type: 'phone-password',
|
|
1904
|
+
phone: params.phone
|
|
1905
|
+
});
|
|
1906
|
+
_context29.next = 6;
|
|
1907
|
+
return this.apiCaller.call('phonePasswordLogin', params);
|
|
1908
|
+
case 6:
|
|
1909
|
+
response = _context29.sent;
|
|
1910
|
+
if (response.status && response.data) {
|
|
1911
|
+
// 保存用户信息和 token
|
|
1912
|
+
this.store.isLoggedIn = true;
|
|
1913
|
+
this.store.userInfo = response.data.user;
|
|
1914
|
+
this.store.token = response.data.token;
|
|
1915
|
+
|
|
1916
|
+
// 如果有 refreshToken,也保存
|
|
1917
|
+
if (response.data.refreshToken) {
|
|
1918
|
+
this.store.refreshToken = response.data.refreshToken;
|
|
1919
|
+
}
|
|
1920
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
|
|
1921
|
+
user: response.data.user,
|
|
1922
|
+
token: response.data.token,
|
|
1923
|
+
loginType: 'phone-password'
|
|
1924
|
+
});
|
|
1925
|
+
} else {
|
|
1926
|
+
this.store.error = response.message || '手机号密码登录失败';
|
|
1927
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1928
|
+
error: this.store.error,
|
|
1929
|
+
loginType: 'phone-password'
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
return _context29.abrupt("return", response);
|
|
1933
|
+
case 11:
|
|
1934
|
+
_context29.prev = 11;
|
|
1935
|
+
_context29.t0 = _context29["catch"](0);
|
|
1936
|
+
this.store.error = '手机号密码登录失败';
|
|
1937
|
+
this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1938
|
+
error: this.store.error,
|
|
1939
|
+
loginType: 'phone-password'
|
|
1940
|
+
});
|
|
1941
|
+
return _context29.abrupt("return", _context29.t0);
|
|
1942
|
+
case 16:
|
|
1943
|
+
_context29.prev = 16;
|
|
1944
|
+
this.store.isLoading = false;
|
|
1945
|
+
return _context29.finish(16);
|
|
1946
|
+
case 19:
|
|
1947
|
+
case "end":
|
|
1948
|
+
return _context29.stop();
|
|
1949
|
+
}
|
|
1950
|
+
}, _callee29, this, [[0, 11, 16, 19]]);
|
|
1951
|
+
}));
|
|
1952
|
+
function phonePasswordLogin(_x26) {
|
|
1953
|
+
return _phonePasswordLogin.apply(this, arguments);
|
|
1954
|
+
}
|
|
1955
|
+
return phonePasswordLogin;
|
|
1956
|
+
}() /** 发送密码重置邮箱验证码 */)
|
|
1957
|
+
}, {
|
|
1958
|
+
key: "sendPasswordResetEmail",
|
|
1959
|
+
value: (function () {
|
|
1960
|
+
var _sendPasswordResetEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
|
|
1961
|
+
var response, now;
|
|
1962
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
1963
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
1964
|
+
case 0:
|
|
1965
|
+
_context30.prev = 0;
|
|
1966
|
+
this.store.isLoading = true;
|
|
1967
|
+
this.store.error = null;
|
|
1968
|
+
_context30.next = 5;
|
|
1969
|
+
return this.apiCaller.call('sendPasswordResetEmail', params);
|
|
1970
|
+
case 5:
|
|
1971
|
+
response = _context30.sent;
|
|
1972
|
+
if (response.status) {
|
|
1973
|
+
// 记录验证码发送状态
|
|
1974
|
+
now = Date.now();
|
|
1975
|
+
this.store.verificationCodeSent[params.email] = {
|
|
1976
|
+
sent: true,
|
|
1977
|
+
sentAt: now,
|
|
1978
|
+
expiresAt: now + 10 * 60 * 1000 // 10分钟过期
|
|
1979
|
+
};
|
|
1980
|
+
this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
|
|
1981
|
+
target: params.email,
|
|
1982
|
+
purpose: VerificationPurpose.PASSWORD_RESET
|
|
1983
|
+
});
|
|
1984
|
+
} else {
|
|
1985
|
+
this.store.error = response.message || '发送密码重置验证码失败';
|
|
1986
|
+
this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
1987
|
+
target: params.email,
|
|
1988
|
+
error: this.store.error
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
return _context30.abrupt("return", response);
|
|
1992
|
+
case 10:
|
|
1993
|
+
_context30.prev = 10;
|
|
1994
|
+
_context30.t0 = _context30["catch"](0);
|
|
1995
|
+
this.store.error = '发送密码重置验证码失败';
|
|
1996
|
+
this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
|
|
1997
|
+
target: params.email,
|
|
1998
|
+
error: this.store.error
|
|
1999
|
+
});
|
|
2000
|
+
return _context30.abrupt("return", _context30.t0);
|
|
2001
|
+
case 15:
|
|
2002
|
+
_context30.prev = 15;
|
|
2003
|
+
this.store.isLoading = false;
|
|
2004
|
+
return _context30.finish(15);
|
|
2005
|
+
case 18:
|
|
2006
|
+
case "end":
|
|
2007
|
+
return _context30.stop();
|
|
2008
|
+
}
|
|
2009
|
+
}, _callee30, this, [[0, 10, 15, 18]]);
|
|
2010
|
+
}));
|
|
2011
|
+
function sendPasswordResetEmail(_x27) {
|
|
2012
|
+
return _sendPasswordResetEmail.apply(this, arguments);
|
|
2013
|
+
}
|
|
2014
|
+
return sendPasswordResetEmail;
|
|
2015
|
+
}() /** 发送手机号验证码重置密码 */)
|
|
2016
|
+
}, {
|
|
2017
|
+
key: "sendPasswordResetSms",
|
|
2018
|
+
value: (function () {
|
|
2019
|
+
var _sendPasswordResetSms = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
|
|
2020
|
+
var response;
|
|
2021
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
2022
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
2023
|
+
case 0:
|
|
2024
|
+
_context31.prev = 0;
|
|
2025
|
+
this.store.isLoading = true;
|
|
2026
|
+
this.store.error = null;
|
|
2027
|
+
_context31.next = 5;
|
|
2028
|
+
return this.apiCaller.call('sendPasswordResetSms', params);
|
|
2029
|
+
case 5:
|
|
2030
|
+
response = _context31.sent;
|
|
2031
|
+
if (!response.status) {
|
|
2032
|
+
_context31.next = 10;
|
|
2033
|
+
break;
|
|
2034
|
+
}
|
|
2035
|
+
return _context31.abrupt("return", response);
|
|
2036
|
+
case 10:
|
|
2037
|
+
this.store.error = response.message || '发送手机号验证码重置密码失败';
|
|
2038
|
+
case 11:
|
|
2039
|
+
return _context31.abrupt("return", response);
|
|
2040
|
+
case 14:
|
|
2041
|
+
_context31.prev = 14;
|
|
2042
|
+
_context31.t0 = _context31["catch"](0);
|
|
2043
|
+
this.store.error = '发送手机号验证码重置密码失败';
|
|
2044
|
+
return _context31.abrupt("return", _context31.t0);
|
|
2045
|
+
case 18:
|
|
2046
|
+
_context31.prev = 18;
|
|
2047
|
+
this.store.isLoading = false;
|
|
2048
|
+
return _context31.finish(18);
|
|
2049
|
+
case 21:
|
|
2050
|
+
case "end":
|
|
2051
|
+
return _context31.stop();
|
|
2052
|
+
}
|
|
2053
|
+
}, _callee31, this, [[0, 14, 18, 21]]);
|
|
2054
|
+
}));
|
|
2055
|
+
function sendPasswordResetSms(_x28) {
|
|
2056
|
+
return _sendPasswordResetSms.apply(this, arguments);
|
|
2057
|
+
}
|
|
2058
|
+
return sendPasswordResetSms;
|
|
2059
|
+
}()
|
|
2060
|
+
/**
|
|
2061
|
+
* 获取当前用户信息
|
|
2062
|
+
*/
|
|
2063
|
+
)
|
|
2064
|
+
}, {
|
|
2065
|
+
key: "getCurrentUser",
|
|
2066
|
+
value: function getCurrentUser() {
|
|
2067
|
+
return this.store.currentUser;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* 检查是否已登录
|
|
2072
|
+
*/
|
|
2073
|
+
}, {
|
|
2074
|
+
key: "isLoggedIn",
|
|
2075
|
+
value: function isLoggedIn() {
|
|
2076
|
+
return this.store.isLoggedIn;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
/**
|
|
2080
|
+
* 获取加载状态
|
|
2081
|
+
*/
|
|
2082
|
+
}, {
|
|
2083
|
+
key: "isLoading",
|
|
2084
|
+
value: function isLoading() {
|
|
2085
|
+
return this.store.isLoading;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* 获取错误信息
|
|
2090
|
+
*/
|
|
2091
|
+
}, {
|
|
2092
|
+
key: "getError",
|
|
2093
|
+
value: function getError() {
|
|
2094
|
+
return this.store.error;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
/**
|
|
2098
|
+
* 清除错误信息
|
|
2099
|
+
*/
|
|
2100
|
+
}, {
|
|
2101
|
+
key: "clearError",
|
|
2102
|
+
value: function clearError() {
|
|
2103
|
+
this.store.error = null;
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
/**
|
|
2107
|
+
* 检查验证码是否已发送且未过期
|
|
2108
|
+
*/
|
|
2109
|
+
}, {
|
|
2110
|
+
key: "isVerificationCodeSent",
|
|
2111
|
+
value: function isVerificationCodeSent(target) {
|
|
2112
|
+
var codeInfo = this.store.verificationCodeSent[target];
|
|
2113
|
+
if (!codeInfo || !codeInfo.sent) {
|
|
2114
|
+
return false;
|
|
2115
|
+
}
|
|
2116
|
+
return Date.now() < codeInfo.expiresAt;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
/**
|
|
2120
|
+
* 获取验证码剩余时间(秒)
|
|
2121
|
+
*/
|
|
2122
|
+
}, {
|
|
2123
|
+
key: "getVerificationCodeRemainingTime",
|
|
2124
|
+
value: function getVerificationCodeRemainingTime(target) {
|
|
2125
|
+
var codeInfo = this.store.verificationCodeSent[target];
|
|
2126
|
+
if (!codeInfo || !codeInfo.sent) {
|
|
2127
|
+
return 0;
|
|
2128
|
+
}
|
|
2129
|
+
var remaining = Math.max(0, codeInfo.expiresAt - Date.now());
|
|
2130
|
+
return Math.ceil(remaining / 1000);
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* 初始化 Facebook SDK
|
|
2135
|
+
*/
|
|
2136
|
+
}, {
|
|
2137
|
+
key: "initFacebookSDK",
|
|
2138
|
+
value: (function () {
|
|
2139
|
+
var _initFacebookSDK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(token) {
|
|
2140
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
2141
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
2142
|
+
case 0:
|
|
2143
|
+
return _context32.abrupt("return", new Promise(function (resolve, reject) {
|
|
2144
|
+
if (typeof window === 'undefined') {
|
|
2145
|
+
reject(new Error('Facebook SDK 只能在浏览器环境中使用'));
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// 检查是否已经加载
|
|
2150
|
+
if (window.FB) {
|
|
2151
|
+
resolve();
|
|
2152
|
+
return;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// 动态加载 Facebook SDK
|
|
2156
|
+
var script = document.createElement('script');
|
|
2157
|
+
script.src = 'https://connect.facebook.net/en_US/sdk.js';
|
|
2158
|
+
script.async = true;
|
|
2159
|
+
script.defer = true;
|
|
2160
|
+
script.crossOrigin = 'anonymous';
|
|
2161
|
+
script.onload = function () {
|
|
2162
|
+
window.FB.init({
|
|
2163
|
+
appId: token,
|
|
2164
|
+
cookie: true,
|
|
2165
|
+
xfbml: true,
|
|
2166
|
+
version: 'v18.0'
|
|
2167
|
+
});
|
|
2168
|
+
resolve();
|
|
2169
|
+
};
|
|
2170
|
+
script.onerror = function () {
|
|
2171
|
+
reject(new Error('Facebook SDK 加载失败'));
|
|
2172
|
+
};
|
|
2173
|
+
document.head.appendChild(script);
|
|
2174
|
+
}));
|
|
2175
|
+
case 1:
|
|
2176
|
+
case "end":
|
|
2177
|
+
return _context32.stop();
|
|
2178
|
+
}
|
|
2179
|
+
}, _callee32);
|
|
2180
|
+
}));
|
|
2181
|
+
function initFacebookSDK(_x29) {
|
|
2182
|
+
return _initFacebookSDK.apply(this, arguments);
|
|
2183
|
+
}
|
|
2184
|
+
return initFacebookSDK;
|
|
2185
|
+
}()
|
|
2186
|
+
/**
|
|
2187
|
+
* 初始化 Apple SDK
|
|
2188
|
+
*/
|
|
2189
|
+
)
|
|
2190
|
+
}, {
|
|
2191
|
+
key: "initAppleSDK",
|
|
2192
|
+
value: (function () {
|
|
2193
|
+
var _initAppleSDK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
2194
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
2195
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
2196
|
+
case 0:
|
|
2197
|
+
return _context33.abrupt("return", new Promise(function (resolve, reject) {
|
|
2198
|
+
if (typeof window === 'undefined') {
|
|
2199
|
+
reject(new Error('Apple SDK 只能在浏览器环境中使用'));
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
// 检查是否已经加载
|
|
2204
|
+
if (window.AppleID) {
|
|
2205
|
+
resolve();
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// 动态加载 Apple SDK
|
|
2210
|
+
var script = document.createElement('script');
|
|
2211
|
+
script.src = 'https://file.mypisell-dev.com/static/apple.js';
|
|
2212
|
+
script.async = true;
|
|
2213
|
+
script.defer = true;
|
|
2214
|
+
script.crossOrigin = 'anonymous';
|
|
2215
|
+
script.onload = function () {
|
|
2216
|
+
// Apple SDK 加载完成后,需要等待一下确保 AppleID 对象可用
|
|
2217
|
+
setTimeout(function () {
|
|
2218
|
+
if (window.AppleID) {
|
|
2219
|
+
resolve();
|
|
2220
|
+
} else {
|
|
2221
|
+
reject(new Error('Apple SDK 加载失败:AppleID 对象不可用'));
|
|
2222
|
+
}
|
|
2223
|
+
}, 100);
|
|
2224
|
+
};
|
|
2225
|
+
script.onerror = function () {
|
|
2226
|
+
reject(new Error('Apple SDK 加载失败'));
|
|
2227
|
+
};
|
|
2228
|
+
document.head.appendChild(script);
|
|
2229
|
+
}));
|
|
2230
|
+
case 1:
|
|
2231
|
+
case "end":
|
|
2232
|
+
return _context33.stop();
|
|
2233
|
+
}
|
|
2234
|
+
}, _callee33);
|
|
2235
|
+
}));
|
|
2236
|
+
function initAppleSDK() {
|
|
2237
|
+
return _initAppleSDK.apply(this, arguments);
|
|
2238
|
+
}
|
|
2239
|
+
return initAppleSDK;
|
|
2240
|
+
}()
|
|
2241
|
+
/**
|
|
2242
|
+
* Facebook 登录
|
|
2243
|
+
*/
|
|
2244
|
+
)
|
|
2245
|
+
}, {
|
|
2246
|
+
key: "loginWithFacebook",
|
|
2247
|
+
value: (function () {
|
|
2248
|
+
var _loginWithFacebook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(token) {
|
|
2249
|
+
var _this2 = this;
|
|
2250
|
+
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
2251
|
+
while (1) switch (_context35.prev = _context35.next) {
|
|
2252
|
+
case 0:
|
|
2253
|
+
console.log('[RegisterAndLogin] Facebook 登录开始', {
|
|
2254
|
+
tokenLength: (token === null || token === void 0 ? void 0 : token.length) || 0,
|
|
2255
|
+
timestamp: Date.now()
|
|
2256
|
+
});
|
|
2257
|
+
_context35.next = 3;
|
|
2258
|
+
return this.initFacebookSDK(token);
|
|
2259
|
+
case 3:
|
|
2260
|
+
console.log('[RegisterAndLogin] Facebook SDK 初始化完成,准备调用 FB.login');
|
|
2261
|
+
return _context35.abrupt("return", new Promise(function (resolve, reject) {
|
|
2262
|
+
console.log('[RegisterAndLogin] 调用 FB.login', {
|
|
2263
|
+
scope: 'email,public_profile'
|
|
2264
|
+
});
|
|
2265
|
+
window.FB.login( /*#__PURE__*/function () {
|
|
2266
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(response) {
|
|
2267
|
+
var result;
|
|
2268
|
+
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
2269
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
2270
|
+
case 0:
|
|
2271
|
+
console.log('[RegisterAndLogin] FB.login 回调触发', {
|
|
2272
|
+
hasAuthResponse: Boolean(response === null || response === void 0 ? void 0 : response.authResponse),
|
|
2273
|
+
status: response === null || response === void 0 ? void 0 : response.status
|
|
2274
|
+
});
|
|
2275
|
+
if (!response.authResponse) {
|
|
2276
|
+
_context34.next = 17;
|
|
2277
|
+
break;
|
|
2278
|
+
}
|
|
2279
|
+
_context34.prev = 2;
|
|
2280
|
+
// 直接调用 /auth/facebook/login 接口
|
|
2281
|
+
console.log('[RegisterAndLogin] 调用后端 facebookLogin 接口');
|
|
2282
|
+
_context34.next = 6;
|
|
2283
|
+
return _this2.apiCaller.call('facebookLogin', {
|
|
2284
|
+
token: response.authResponse.accessToken
|
|
2285
|
+
});
|
|
2286
|
+
case 6:
|
|
2287
|
+
result = _context34.sent;
|
|
2288
|
+
console.log('[RegisterAndLogin] facebookLogin 接口返回成功', {
|
|
2289
|
+
hasResult: Boolean(result)
|
|
2290
|
+
});
|
|
2291
|
+
resolve(result);
|
|
2292
|
+
_context34.next = 15;
|
|
2293
|
+
break;
|
|
2294
|
+
case 11:
|
|
2295
|
+
_context34.prev = 11;
|
|
2296
|
+
_context34.t0 = _context34["catch"](2);
|
|
2297
|
+
console.error('[RegisterAndLogin] facebookLogin 接口调用失败', _context34.t0);
|
|
2298
|
+
reject(_context34.t0);
|
|
2299
|
+
case 15:
|
|
2300
|
+
_context34.next = 19;
|
|
2301
|
+
break;
|
|
2302
|
+
case 17:
|
|
2303
|
+
console.warn('[RegisterAndLogin] FB.login 用户取消授权或无 authResponse', response);
|
|
2304
|
+
reject(new Error('facebook_login_cancel'));
|
|
2305
|
+
case 19:
|
|
2306
|
+
case "end":
|
|
2307
|
+
return _context34.stop();
|
|
2308
|
+
}
|
|
2309
|
+
}, _callee34, null, [[2, 11]]);
|
|
2310
|
+
}));
|
|
2311
|
+
return function (_x31) {
|
|
2312
|
+
return _ref.apply(this, arguments);
|
|
2313
|
+
};
|
|
2314
|
+
}(), {
|
|
2315
|
+
scope: 'email,public_profile'
|
|
2316
|
+
});
|
|
2317
|
+
}));
|
|
2318
|
+
case 5:
|
|
2319
|
+
case "end":
|
|
2320
|
+
return _context35.stop();
|
|
2321
|
+
}
|
|
2322
|
+
}, _callee35, this);
|
|
2323
|
+
}));
|
|
2324
|
+
function loginWithFacebook(_x30) {
|
|
2325
|
+
return _loginWithFacebook.apply(this, arguments);
|
|
2326
|
+
}
|
|
2327
|
+
return loginWithFacebook;
|
|
2328
|
+
}()
|
|
2329
|
+
/**
|
|
2330
|
+
* Apple 登录(需要在支持的环境中使用)
|
|
2331
|
+
*/
|
|
2332
|
+
)
|
|
2333
|
+
}, {
|
|
2334
|
+
key: "loginWithApple",
|
|
2335
|
+
value: (function () {
|
|
2336
|
+
var _loginWithApple = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(token) {
|
|
2337
|
+
var _this3 = this;
|
|
2338
|
+
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
2339
|
+
while (1) switch (_context37.prev = _context37.next) {
|
|
2340
|
+
case 0:
|
|
2341
|
+
// 先加载 Apple SDK
|
|
2342
|
+
console.log('[RegisterAndLogin] Apple 登录开始', {
|
|
2343
|
+
tokenLength: (token === null || token === void 0 ? void 0 : token.length) || 0,
|
|
2344
|
+
timestamp: Date.now()
|
|
2345
|
+
});
|
|
2346
|
+
_context37.next = 3;
|
|
2347
|
+
return this.initAppleSDK();
|
|
2348
|
+
case 3:
|
|
2349
|
+
console.log('[RegisterAndLogin] Apple SDK 初始化完成');
|
|
2350
|
+
return _context37.abrupt("return", new Promise(function (resolve, reject) {
|
|
2351
|
+
try {
|
|
2352
|
+
var _AppleID, _AppleID2;
|
|
2353
|
+
// 动态创建 Apple 登录按钮元素
|
|
2354
|
+
console.log('[RegisterAndLogin] 创建临时 Apple SignIn 按钮节点');
|
|
2355
|
+
var appleSignInDiv = document.createElement('div');
|
|
2356
|
+
appleSignInDiv.id = 'appleid-signin-temp';
|
|
2357
|
+
appleSignInDiv.setAttribute('data-color', 'black');
|
|
2358
|
+
appleSignInDiv.setAttribute('data-border', 'false');
|
|
2359
|
+
appleSignInDiv.setAttribute('data-type', 'sign-in');
|
|
2360
|
+
appleSignInDiv.setAttribute('data-mode', 'logo-only');
|
|
2361
|
+
appleSignInDiv.setAttribute('data-logo-size', 'small');
|
|
2362
|
+
appleSignInDiv.style.opacity = '0';
|
|
2363
|
+
appleSignInDiv.style.position = 'absolute';
|
|
2364
|
+
appleSignInDiv.style.left = '-9999px';
|
|
2365
|
+
appleSignInDiv.style.top = '-9999px';
|
|
2366
|
+
appleSignInDiv.style.width = '1px';
|
|
2367
|
+
appleSignInDiv.style.height = '1px';
|
|
2368
|
+
|
|
2369
|
+
// 将元素添加到 body 中
|
|
2370
|
+
document.body.appendChild(appleSignInDiv);
|
|
2371
|
+
console.log('[RegisterAndLogin] Apple SignIn 按钮已添加到文档');
|
|
2372
|
+
|
|
2373
|
+
// 初始化 Apple ID 按钮
|
|
2374
|
+
if ((_AppleID = window.AppleID) !== null && _AppleID !== void 0 && (_AppleID = _AppleID.auth) !== null && _AppleID !== void 0 && _AppleID.init) {
|
|
2375
|
+
console.log('[RegisterAndLogin] 调用 AppleID.auth.init');
|
|
2376
|
+
window.AppleID.auth.init({
|
|
2377
|
+
clientId: token,
|
|
2378
|
+
// 使用传入的 token 作为 clientId
|
|
2379
|
+
scope: 'name email',
|
|
2380
|
+
redirectURI: window.location.origin,
|
|
2381
|
+
state: 'signin',
|
|
2382
|
+
usePopup: true
|
|
2383
|
+
});
|
|
2384
|
+
} else {
|
|
2385
|
+
console.warn('[RegisterAndLogin] AppleID.auth.init 方法不可用');
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
// 直接调用 Apple ID 登录,并处理 Promise
|
|
2389
|
+
if ((_AppleID2 = window.AppleID) !== null && _AppleID2 !== void 0 && (_AppleID2 = _AppleID2.auth) !== null && _AppleID2 !== void 0 && _AppleID2.signIn) {
|
|
2390
|
+
console.log('[RegisterAndLogin] 调用 AppleID.auth.signIn');
|
|
2391
|
+
window.AppleID.auth.signIn().then( /*#__PURE__*/function () {
|
|
2392
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(authResult) {
|
|
2393
|
+
var _authResult$authoriza, _authResult$authoriza2, authorizationCode, identityToken, result;
|
|
2394
|
+
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
2395
|
+
while (1) switch (_context36.prev = _context36.next) {
|
|
2396
|
+
case 0:
|
|
2397
|
+
_context36.prev = 0;
|
|
2398
|
+
// 清理临时元素
|
|
2399
|
+
if (document.body.contains(appleSignInDiv)) {
|
|
2400
|
+
document.body.removeChild(appleSignInDiv);
|
|
2401
|
+
}
|
|
2402
|
+
console.log('[RegisterAndLogin] Apple SignIn 成功,临时节点已移除', {
|
|
2403
|
+
hasAuthorization: Boolean(authResult === null || authResult === void 0 ? void 0 : authResult.authorization),
|
|
2404
|
+
hasUser: Boolean(authResult === null || authResult === void 0 ? void 0 : authResult.user)
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
// 获取授权码或令牌
|
|
2408
|
+
authorizationCode = (_authResult$authoriza = authResult.authorization) === null || _authResult$authoriza === void 0 ? void 0 : _authResult$authoriza.code;
|
|
2409
|
+
identityToken = (_authResult$authoriza2 = authResult.authorization) === null || _authResult$authoriza2 === void 0 ? void 0 : _authResult$authoriza2.id_token;
|
|
2410
|
+
console.log('[RegisterAndLogin] Apple 授权结果解析', {
|
|
2411
|
+
hasAuthorizationCode: Boolean(authorizationCode),
|
|
2412
|
+
hasIdentityToken: Boolean(identityToken)
|
|
2413
|
+
});
|
|
2414
|
+
|
|
2415
|
+
// 使用授权码或身份令牌调用后端接口
|
|
2416
|
+
console.log('[RegisterAndLogin] 调用后端 appleLogin 接口');
|
|
2417
|
+
_context36.next = 9;
|
|
2418
|
+
return _this3.apiCaller.call('appleLogin', {
|
|
2419
|
+
code: identityToken || authorizationCode,
|
|
2420
|
+
login_channel: _this3.channel
|
|
2421
|
+
});
|
|
2422
|
+
case 9:
|
|
2423
|
+
result = _context36.sent;
|
|
2424
|
+
console.log('[RegisterAndLogin] appleLogin 接口返回成功', {
|
|
2425
|
+
hasResult: Boolean(result)
|
|
2426
|
+
});
|
|
2427
|
+
resolve(result);
|
|
2428
|
+
_context36.next = 18;
|
|
2429
|
+
break;
|
|
2430
|
+
case 14:
|
|
2431
|
+
_context36.prev = 14;
|
|
2432
|
+
_context36.t0 = _context36["catch"](0);
|
|
2433
|
+
console.error('[RegisterAndLogin] 处理 Apple 登录结果失败', _context36.t0);
|
|
2434
|
+
reject(_context36.t0);
|
|
2435
|
+
case 18:
|
|
2436
|
+
case "end":
|
|
2437
|
+
return _context36.stop();
|
|
2438
|
+
}
|
|
2439
|
+
}, _callee36, null, [[0, 14]]);
|
|
2440
|
+
}));
|
|
2441
|
+
return function (_x33) {
|
|
2442
|
+
return _ref2.apply(this, arguments);
|
|
2443
|
+
};
|
|
2444
|
+
}()).catch(function (error) {
|
|
2445
|
+
// 清理临时元素
|
|
2446
|
+
if (document.body.contains(appleSignInDiv)) {
|
|
2447
|
+
document.body.removeChild(appleSignInDiv);
|
|
2448
|
+
}
|
|
2449
|
+
console.error('[RegisterAndLogin] Apple SignIn Promise 拒绝', error);
|
|
2450
|
+
reject(new Error('Apple 登录失败: ' + ((error === null || error === void 0 ? void 0 : error.error) || (error === null || error === void 0 ? void 0 : error.message) || '未知错误')));
|
|
2451
|
+
});
|
|
2452
|
+
} else {
|
|
2453
|
+
console.error('[RegisterAndLogin] AppleID.auth.signIn 方法不可用');
|
|
2454
|
+
reject(new Error('Apple SDK 未正确加载'));
|
|
2455
|
+
}
|
|
2456
|
+
} catch (error) {
|
|
2457
|
+
console.error('[RegisterAndLogin] Apple 登录流程异常', error);
|
|
2458
|
+
reject(error);
|
|
2459
|
+
}
|
|
2460
|
+
}));
|
|
2461
|
+
case 5:
|
|
2462
|
+
case "end":
|
|
2463
|
+
return _context37.stop();
|
|
2464
|
+
}
|
|
2465
|
+
}, _callee37, this);
|
|
2466
|
+
}));
|
|
2467
|
+
function loginWithApple(_x32) {
|
|
2468
|
+
return _loginWithApple.apply(this, arguments);
|
|
2469
|
+
}
|
|
2470
|
+
return loginWithApple;
|
|
2471
|
+
}()
|
|
2472
|
+
/**
|
|
2473
|
+
* 更新 OAuth 配置
|
|
2474
|
+
*/
|
|
2475
|
+
)
|
|
2476
|
+
}, {
|
|
2477
|
+
key: "updateOAuthConfig",
|
|
2478
|
+
value: function updateOAuthConfig(config) {
|
|
2479
|
+
this.store.oauthConfig = _objectSpread(_objectSpread({}, this.store.oauthConfig), config);
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
/**
|
|
2483
|
+
* 获取当前渠道
|
|
2484
|
+
*/
|
|
2485
|
+
}, {
|
|
2486
|
+
key: "getCurrentChannel",
|
|
2487
|
+
value: function getCurrentChannel() {
|
|
2488
|
+
return this.channel;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* 获取 API 调用器(用于高级用法)
|
|
2493
|
+
*/
|
|
2494
|
+
}, {
|
|
2495
|
+
key: "getApiCaller",
|
|
2496
|
+
value: function getApiCaller() {
|
|
2497
|
+
return this.apiCaller;
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* 获取国家区号列表
|
|
2502
|
+
*/
|
|
2503
|
+
}, {
|
|
2504
|
+
key: "getCountries",
|
|
2505
|
+
value: (function () {
|
|
2506
|
+
var _getCountries = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
|
|
2507
|
+
var CACHE_KEY, cachedData, cached, response, countries;
|
|
2508
|
+
return _regeneratorRuntime().wrap(function _callee38$(_context38) {
|
|
2509
|
+
while (1) switch (_context38.prev = _context38.next) {
|
|
2510
|
+
case 0:
|
|
2511
|
+
CACHE_KEY = 'pisell_countries_cache';
|
|
2512
|
+
_context38.prev = 1;
|
|
2513
|
+
this.store.isLoading = true;
|
|
2514
|
+
this.store.error = null;
|
|
2515
|
+
|
|
2516
|
+
// 1. 检查内存缓存
|
|
2517
|
+
if (!this.countriesCache) {
|
|
2518
|
+
_context38.next = 7;
|
|
2519
|
+
break;
|
|
2520
|
+
}
|
|
2521
|
+
this.store.isLoading = false;
|
|
2522
|
+
return _context38.abrupt("return", this.countriesCache);
|
|
2523
|
+
case 7:
|
|
2524
|
+
// 2. 检查 localStorage 缓存
|
|
2525
|
+
cachedData = null;
|
|
2526
|
+
try {
|
|
2527
|
+
cached = this.window.localStorage.getItem(CACHE_KEY);
|
|
2528
|
+
if (cached) {
|
|
2529
|
+
cachedData = JSON.parse(cached);
|
|
2530
|
+
}
|
|
2531
|
+
} catch (error) {
|
|
2532
|
+
console.warn('[RegisterAndLogin] localStorage 缓存解析失败:', error);
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// 3. 如果有 localStorage 缓存,先返回缓存数据
|
|
2536
|
+
if (!(cachedData && Array.isArray(cachedData) && cachedData.length > 0)) {
|
|
2537
|
+
_context38.next = 14;
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2540
|
+
// 设置内存缓存
|
|
2541
|
+
this.countriesCache = cachedData;
|
|
2542
|
+
|
|
2543
|
+
// 异步请求后端数据进行对比和更新
|
|
2544
|
+
this.updateCountriesCache(CACHE_KEY, cachedData);
|
|
2545
|
+
this.store.isLoading = false;
|
|
2546
|
+
return _context38.abrupt("return", cachedData);
|
|
2547
|
+
case 14:
|
|
2548
|
+
_context38.next = 16;
|
|
2549
|
+
return this.apiCaller.call('getCountries');
|
|
2550
|
+
case 16:
|
|
2551
|
+
response = _context38.sent;
|
|
2552
|
+
if (!(response.status && response.data)) {
|
|
2553
|
+
_context38.next = 24;
|
|
2554
|
+
break;
|
|
2555
|
+
}
|
|
2556
|
+
countries = response.data; // 更新内存缓存
|
|
2557
|
+
this.countriesCache = countries;
|
|
2558
|
+
|
|
2559
|
+
// 更新 localStorage 缓存
|
|
2560
|
+
try {
|
|
2561
|
+
localStorage.setItem(CACHE_KEY, JSON.stringify(countries));
|
|
2562
|
+
} catch (error) {
|
|
2563
|
+
console.warn('[RegisterAndLogin] localStorage 存储失败:', error);
|
|
2564
|
+
}
|
|
2565
|
+
return _context38.abrupt("return", countries);
|
|
2566
|
+
case 24:
|
|
2567
|
+
this.store.error = response.message || '获取国家区号失败';
|
|
2568
|
+
throw new Error(this.store.error);
|
|
2569
|
+
case 26:
|
|
2570
|
+
_context38.next = 33;
|
|
2571
|
+
break;
|
|
2572
|
+
case 28:
|
|
2573
|
+
_context38.prev = 28;
|
|
2574
|
+
_context38.t0 = _context38["catch"](1);
|
|
2575
|
+
this.store.error = '获取国家区号失败';
|
|
2576
|
+
console.error('[RegisterAndLogin] 获取国家区号失败:', _context38.t0);
|
|
2577
|
+
throw _context38.t0;
|
|
2578
|
+
case 33:
|
|
2579
|
+
_context38.prev = 33;
|
|
2580
|
+
this.store.isLoading = false;
|
|
2581
|
+
return _context38.finish(33);
|
|
2582
|
+
case 36:
|
|
2583
|
+
case "end":
|
|
2584
|
+
return _context38.stop();
|
|
2585
|
+
}
|
|
2586
|
+
}, _callee38, this, [[1, 28, 33, 36]]);
|
|
2587
|
+
}));
|
|
2588
|
+
function getCountries() {
|
|
2589
|
+
return _getCountries.apply(this, arguments);
|
|
2590
|
+
}
|
|
2591
|
+
return getCountries;
|
|
2592
|
+
}()
|
|
2593
|
+
/**
|
|
2594
|
+
* 异步更新国家缓存数据
|
|
2595
|
+
*/
|
|
2596
|
+
)
|
|
2597
|
+
}, {
|
|
2598
|
+
key: "updateCountriesCache",
|
|
2599
|
+
value: (function () {
|
|
2600
|
+
var _updateCountriesCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(cacheKey, cachedData) {
|
|
2601
|
+
var response, newData, hasChanged;
|
|
2602
|
+
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
2603
|
+
while (1) switch (_context39.prev = _context39.next) {
|
|
2604
|
+
case 0:
|
|
2605
|
+
_context39.prev = 0;
|
|
2606
|
+
_context39.next = 3;
|
|
2607
|
+
return this.apiCaller.call('getCountries');
|
|
2608
|
+
case 3:
|
|
2609
|
+
response = _context39.sent;
|
|
2610
|
+
if (response.status && response.data) {
|
|
2611
|
+
newData = response.data; // 比较数据是否有变化(简单的长度和内容对比)
|
|
2612
|
+
hasChanged = newData.length !== cachedData.length || JSON.stringify(newData) !== JSON.stringify(cachedData);
|
|
2613
|
+
if (hasChanged) {
|
|
2614
|
+
// 更新内存缓存
|
|
2615
|
+
this.countriesCache = newData;
|
|
2616
|
+
|
|
2617
|
+
// 更新 localStorage 缓存
|
|
2618
|
+
try {
|
|
2619
|
+
localStorage.setItem(cacheKey, JSON.stringify(newData));
|
|
2620
|
+
} catch (error) {
|
|
2621
|
+
console.warn('[RegisterAndLogin] localStorage 更新失败:', error);
|
|
2622
|
+
}
|
|
2623
|
+
console.log('[RegisterAndLogin] 国家数据已更新');
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
_context39.next = 10;
|
|
2627
|
+
break;
|
|
2628
|
+
case 7:
|
|
2629
|
+
_context39.prev = 7;
|
|
2630
|
+
_context39.t0 = _context39["catch"](0);
|
|
2631
|
+
console.warn('[RegisterAndLogin] 后台更新国家数据失败:', _context39.t0);
|
|
2632
|
+
case 10:
|
|
2633
|
+
case "end":
|
|
2634
|
+
return _context39.stop();
|
|
2635
|
+
}
|
|
2636
|
+
}, _callee39, this, [[0, 7]]);
|
|
2637
|
+
}));
|
|
2638
|
+
function updateCountriesCache(_x34, _x35) {
|
|
2639
|
+
return _updateCountriesCache.apply(this, arguments);
|
|
2640
|
+
}
|
|
2641
|
+
return updateCountriesCache;
|
|
2642
|
+
}())
|
|
2643
|
+
}, {
|
|
2644
|
+
key: "destroy",
|
|
2645
|
+
value: function () {
|
|
2646
|
+
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
|
|
2647
|
+
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
2648
|
+
while (1) switch (_context40.prev = _context40.next) {
|
|
2649
|
+
case 0:
|
|
2650
|
+
_context40.next = 2;
|
|
2651
|
+
return this.core.effects.emit(RegisterAndLoginHooks.onDestroy, {});
|
|
2652
|
+
case 2:
|
|
2653
|
+
console.log('[RegisterAndLogin] 已销毁');
|
|
2654
|
+
case 3:
|
|
2655
|
+
case "end":
|
|
2656
|
+
return _context40.stop();
|
|
2657
|
+
}
|
|
2658
|
+
}, _callee40, this);
|
|
2659
|
+
}));
|
|
2660
|
+
function destroy() {
|
|
2661
|
+
return _destroy.apply(this, arguments);
|
|
2662
|
+
}
|
|
2663
|
+
return destroy;
|
|
2664
|
+
}()
|
|
2665
|
+
}]);
|
|
2666
|
+
return RegisterAndLoginImpl;
|
|
2667
|
+
}(BaseModule);
|