@doreamonjs/plugin-authorization 0.3.12 → 0.3.15

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/CHANGELOG.md CHANGED
@@ -3,36 +3,49 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [0.3.12](https://github.com/zcorky/zodash/compare/v0.3.11...v0.3.12) (2022-08-31)
6
+ ## [0.3.15](https://github.com/doreamonjs/doreamon/compare/v0.3.14...v0.3.15) (2022-08-31)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * merge confict and clean changelog ([b5b0428](https://github.com/doreamonjs/doreamon/commit/b5b042803ef660e6c8faf214bd24fc27934deb91))
12
+
7
13
 
8
- **Note:** Version bump only for package @doreamonjs/plugin-authorization
9
14
 
10
15
 
11
16
 
17
+ ## [0.3.13](https://github.com/zcorky/zodash/compare/v0.3.12...v0.3.13) (2022-08-31)
12
18
 
19
+ ### Bug Fixes
20
+
21
+ - plugin-authorization model + types ([7c4058c](https://github.com/doreamonjs/doreamon/commit/7c4058c47429eda26de6af08ce6b2d2a423f83c9))
22
+
23
+ ## [0.3.12](https://github.com/doreamonjs/doreamon/compare/v0.3.11...v0.3.12) (2022-08-31)
24
+
25
+ **Note:** Version bump only for package @doreamonjs/plugin-authorization
13
26
 
14
- ## [0.3.3](https://github.com/zcorky/zodash/compare/v0.3.2...v0.3.3) (2022-08-30)
27
+ ## [0.3.3](https://github.com/doreamonjs/doreamon/compare/v0.3.2...v0.3.3) (2022-08-30)
15
28
 
16
29
  **Note:** Version bump only for package @doreamonjs/plugin-authorization
17
30
 
18
- ## [0.3.2](https://github.com/zcorky/zodash/compare/v0.3.1...v0.3.2) (2022-08-30)
31
+ ## [0.3.2](https://github.com/doreamonjs/doreamon/compare/v0.3.1...v0.3.2) (2022-08-30)
19
32
 
20
33
  ### Bug Fixes
21
34
 
22
- - dependencies ([60d97c5](https://github.com/zcorky/zodash/commit/60d97c5f857228f91bdbda6e833438559b3ea7d6))
23
- - package.json main and typings ([5a23e68](https://github.com/zcorky/zodash/commit/5a23e689ce467ddba1deeec674a8639fef3ba5a8))
35
+ - dependencies ([60d97c5](https://github.com/doreamonjs/doreamon/commit/60d97c5f857228f91bdbda6e833438559b3ea7d6))
36
+ - package.json main and typings ([5a23e68](https://github.com/doreamonjs/doreamon/commit/5a23e689ce467ddba1deeec674a8639fef3ba5a8))
24
37
 
25
38
  # 0.3.0 (2022-08-30)
26
39
 
27
40
  ### Bug Fixes
28
41
 
29
- - test ([ab09558](https://github.com/zcorky/zodash/commit/ab0955886a268210cef6cbfe2a6b2362f6d826d6))
42
+ - test ([ab09558](https://github.com/doreamonjs/doreamon/commit/ab0955886a268210cef6cbfe2a6b2362f6d826d6))
30
43
 
31
44
  ### Features
32
45
 
33
- - add plugin-request/forms/authorizations ([7901413](https://github.com/zcorky/zodash/commit/79014135cbae3337e5bf4c8372627f784ffe476e))
46
+ - add plugin-request/forms/authorizations ([7901413](https://github.com/doreamonjs/doreamon/commit/79014135cbae3337e5bf4c8372627f784ffe476e))
34
47
 
35
- ## [1.1.8](https://github.com/zcorky/zodash/compare/@zodash/get@1.1.7...@zodash/get@1.1.8) (2021-04-05)
48
+ ## [1.1.8](https://github.com/doreamonjs/doreamon/compare/@zodash/get@1.1.7...@zodash/get@1.1.8) (2021-04-05)
36
49
 
37
50
  **Note:** Version bump only for package @zodash/get
38
51
 
package/README.md CHANGED
@@ -1,11 +1,3 @@
1
- # `@zodash/get`
1
+ # `@doreamonjs/plugin-authorization`
2
2
 
3
3
  > TODO: description
4
-
5
- ## Usage
6
-
7
- ```
8
- const get = require('@zodash/get');
9
-
10
- // TODO: DEMONSTRATE API
11
- ```
package/lib/model.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Model = void 0;
4
4
  const doreamon_1 = require("@zodash/doreamon");
5
+ const service = require("@doreamonjs/plugin-service");
5
6
  const constants_1 = require("./constants");
6
7
  class Model {
7
8
  constructor(options) {
@@ -13,36 +14,121 @@ class Model {
13
14
  build() {
14
15
  return {
15
16
  namespace: constants_1.NAMESPACE,
16
- state: {},
17
+ state: {
18
+ captcha: `/captcha?_t=${Date.now()}`,
19
+ },
17
20
  reducers: {
18
- save(state, { payload: config }) {
19
- return {
20
- ...state,
21
- config,
22
- };
21
+ 'captcha/save'(state, { payload: captcha }) {
22
+ return { ...state, captcha };
23
23
  },
24
24
  },
25
25
  effects: {
26
- *setup({ payload: config }, { put }) {
27
- var _a, _b;
28
- yield put({ type: 'save', payload: config });
26
+ *login({ payload: { username, password, captcha }, done }, { race, call, put }) {
27
+ yield call(doreamon_1.default.delay, 1000);
29
28
  try {
30
- (_b = (_a = this.service.authorization) === null || _a === void 0 ? void 0 : _a.setup) === null || _b === void 0 ? void 0 : _b.call(_a, config);
29
+ const { timeout } = yield race({
30
+ data: call(login, username, password, captcha),
31
+ timeout: call(doreamon_1.default.delay, 10000),
32
+ });
33
+ if (timeout) {
34
+ yield put({
35
+ type: 'message/tip/error',
36
+ payload: '服务器开小差啦',
37
+ });
38
+ done();
39
+ return false;
40
+ }
31
41
  }
32
- catch (error) {
33
- doreamon_1.default.logger.error('[model] authorization setup error', error);
42
+ catch (err) {
43
+ yield put({ type: 'refresh/captcha' });
44
+ setTimeout(() => {
45
+ // @TODO hack clear captcha
46
+ const node = document.querySelector('input#captcha');
47
+ if (node) {
48
+ node.value = '';
49
+ }
50
+ }, 0);
51
+ done();
52
+ throw err;
34
53
  }
54
+ yield call(doreamon_1.default.delay, 1000);
55
+ // router change
56
+ // @TODO should support redirect
57
+ const query = doreamon_1.default.qs.parse(window.location.search);
58
+ const redirect = query.redirect || '/';
59
+ window.location.href = redirect;
35
60
  },
36
- *track({ payload: { event, attributes } }, { select }) {
37
- var _a, _b;
38
- // @fix This generator function does not have 'yield' require-yield
39
- yield select((state) => state[constants_1.NAMESPACE]);
40
- try {
41
- (_b = (_a = this.service.authorization) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.call(_a, event, attributes);
61
+ *logout(action, { select, race, call, put }) {
62
+ // @TODO request call backend api
63
+ const { username } = yield select((state) => state.user.values);
64
+ const { timeout } = yield race({
65
+ data: call(logout, username),
66
+ timeout: call(doreamon_1.default.delay, 10000),
67
+ });
68
+ if (timeout) {
69
+ yield put({
70
+ type: 'message/tip/error',
71
+ payload: '服务器开小差啦',
72
+ });
73
+ return false;
74
+ }
75
+ // solution @2
76
+ // const currentPath = window.location.pathname;
77
+ // window.location.href = `/login?redirect=${encodeURIComponent(currentPath)}`;
78
+ const currentPath = window.location.pathname;
79
+ window.location.href = `/logout?from=${encodeURIComponent(currentPath)}`;
80
+ },
81
+ *register({ payload }, { race, call, put }) {
82
+ const { username, password, confirmPassword, captcha } = payload;
83
+ const { data, timeout } = yield race({
84
+ data: call(register, username, password, confirmPassword, captcha),
85
+ timeout: call(doreamon_1.default.delay, 10000),
86
+ });
87
+ if (timeout) {
88
+ yield put({
89
+ type: 'message/tip/error',
90
+ payload: '服务器开小差啦',
91
+ });
92
+ return false;
93
+ }
94
+ yield put({
95
+ type: 'message/tip/success',
96
+ payload: '注册成功, 正在跳转登陆界面...',
97
+ });
98
+ yield call(doreamon_1.default.delay, 1000);
99
+ window.location.href = '/';
100
+ },
101
+ // login
102
+ *'refresh/captcha'(action, { race, call, put }) {
103
+ const { data, timeout } = yield race({
104
+ data: call(captcha),
105
+ timeout: call(doreamon_1.default.delay, 10000),
106
+ });
107
+ if (timeout) {
108
+ yield put({
109
+ type: 'message/tip/error',
110
+ payload: '服务器开小差啦',
111
+ });
112
+ return false;
42
113
  }
43
- catch (error) {
44
- doreamon_1.default.logger.error('[model] authorization track error', error);
114
+ yield put({ type: 'captcha/save', payload: data.url });
115
+ },
116
+ *'send/captcha/to/email_or_other'({ payload: { username } }, { race, call, put }) {
117
+ const { timeout } = yield race({
118
+ data: call(sendCaptchaToEmailOrOther, username),
119
+ timeout: call(doreamon_1.default.delay, 10000),
120
+ });
121
+ if (timeout) {
122
+ yield put({
123
+ type: 'message/tip/error',
124
+ payload: '服务器开小差啦',
125
+ });
126
+ return false;
45
127
  }
128
+ yield put({
129
+ type: 'message/tip/success',
130
+ payload: '验证码发送成功,请查看邮箱',
131
+ });
46
132
  },
47
133
  },
48
134
  };
@@ -52,3 +138,19 @@ class Model {
52
138
  }
53
139
  }
54
140
  exports.Model = Model;
141
+ //
142
+ function login(username, password, captcha) {
143
+ return service.authorization.login(username, password, captcha);
144
+ }
145
+ function logout(username) {
146
+ return service.authorization.logout(username);
147
+ }
148
+ function register(username, password, confirmPassword, captcha) {
149
+ return service.authorization.register(username, password, confirmPassword, captcha);
150
+ }
151
+ function captcha() {
152
+ return service.authorization.captcha();
153
+ }
154
+ function sendCaptchaToEmailOrOther(username) {
155
+ return service.authorization.sendCaptchaToEmailOrOther(username);
156
+ }
package/lib/types.d.ts CHANGED
@@ -1,25 +1,3 @@
1
1
  export interface State {
2
- visible: boolean;
3
- attributes: Attributes;
4
- datasets: Datasets;
5
- queue: State[];
6
- callback?: (err: Error | null, type: 'open' | 'close' | 'cancel' | 'ok', vallues?: any) => void;
2
+ captcha?: string;
7
3
  }
8
- export interface Attributes {
9
- type?: 'modal' | 'drawer';
10
- title: string;
11
- description?: string;
12
- cancelText?: string;
13
- authorizationText?: string;
14
- target: AttributeTarget;
15
- }
16
- export interface Datasets {
17
- origin: object;
18
- values: object;
19
- }
20
- export interface AttributeTarget {
21
- namespace: string;
22
- effect: string;
23
- props: any;
24
- }
25
- export declare type Type = 'modal' | 'drawer';
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@doreamonjs/plugin-authorization",
3
- "version": "0.3.12",
3
+ "version": "0.3.15",
4
4
  "description": "authorization plugin for doreamonjs",
5
5
  "keywords": [
6
6
  "doreamonjs",
7
7
  "plugin"
8
8
  ],
9
- "author": "zero <tobewhatwewant@gmail.com>",
10
- "homepage": "https://github.com/zcorky/zodash#readme",
9
+ "author": "whatwewant <tobewhatwewant@gmail.com>",
10
+ "homepage": "https://github.com/doreamonjs/doreamon#readme",
11
11
  "license": "MIT",
12
12
  "main": "lib/index.js",
13
13
  "typings": "lib/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "repository": {
56
56
  "type": "git",
57
- "url": "git+https://github.com/zcorky/zodash.git"
57
+ "url": "git+https://github.com/doreamonjs/doreamon.git"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsc",
@@ -62,11 +62,11 @@
62
62
  "coverage": "codecov"
63
63
  },
64
64
  "bugs": {
65
- "url": "https://github.com/zcorky/zodash/issues"
65
+ "url": "https://github.com/doreamonjs/doreamon/issues"
66
66
  },
67
67
  "dependencies": {
68
- "@doreamonjs/plugin-request": "^0.3.2",
69
- "@doreamonjs/plugin-shared": "^0.3.12",
68
+ "@doreamonjs/plugin-request": "^0.3.15",
69
+ "@doreamonjs/plugin-shared": "^0.3.15",
70
70
  "@sentry/browser": "^7.11.1",
71
71
  "@sentry/tracing": "^7.11.1",
72
72
  "@zcorky/delay": "^1.0.1",
@@ -77,5 +77,5 @@
77
77
  "mixpanel-browser": "^2.45.0",
78
78
  "thinkingdata-browser": "^1.6.0"
79
79
  },
80
- "gitHead": "efeb8d0d8b1e496c165164fbb4f9508c65ee21d9"
80
+ "gitHead": "1c8a50e361f15a083ca5edd02dafa22dffca196a"
81
81
  }