@doreamonjs/plugin-authorization 0.3.12 → 0.3.13
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 +11 -0
- package/lib/model.js +122 -20
- package/lib/types.d.ts +1 -23
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.13](https://github.com/zcorky/zodash/compare/v0.3.12...v0.3.13) (2022-08-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* plugin-authorization model + types ([7c4058c](https://github.com/zcorky/zodash/commit/7c4058c47429eda26de6af08ce6b2d2a423f83c9))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.3.12](https://github.com/zcorky/zodash/compare/v0.3.11...v0.3.12) (2022-08-31)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @doreamonjs/plugin-authorization
|
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:
|
|
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
|
-
*
|
|
27
|
-
|
|
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
|
-
|
|
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 (
|
|
33
|
-
|
|
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
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
yield
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doreamonjs/plugin-authorization",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"description": "authorization plugin for doreamonjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"doreamonjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@doreamonjs/plugin-request": "^0.3.2",
|
|
69
|
-
"@doreamonjs/plugin-shared": "^0.3.
|
|
69
|
+
"@doreamonjs/plugin-shared": "^0.3.13",
|
|
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": "
|
|
80
|
+
"gitHead": "1b28761e66cad9a1e9e3f35b39258a0e3c3caf6c"
|
|
81
81
|
}
|