@springmicro/auth 0.5.2 → 0.5.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springmicro/auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"react-social-login-buttons": "^4.1.0",
|
|
55
55
|
"uuid": "^9.0.1"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "049eb0491834ffa64dd66a1d965ccd3e5751d085"
|
|
58
58
|
}
|
|
@@ -49,6 +49,8 @@ export type SignUpFormState = {
|
|
|
49
49
|
type SignUpFormProps = {
|
|
50
50
|
application: Application | null;
|
|
51
51
|
applicationName?: string;
|
|
52
|
+
CLIENT_ID: string;
|
|
53
|
+
CLIENT_SECRET: string;
|
|
52
54
|
|
|
53
55
|
// onUpdateAccount: (account: Account) => void;
|
|
54
56
|
onUpdateApplication: (application: Application | null) => void;
|
|
@@ -78,16 +80,19 @@ function SignUpForm(props: SignUpFormProps) {
|
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
ApplicationBackend.getApplication(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
ApplicationBackend.getApplication(
|
|
84
|
+
"admin",
|
|
85
|
+
applicationName,
|
|
86
|
+
props.CLIENT_ID,
|
|
87
|
+
props.CLIENT_SECRET
|
|
88
|
+
).then((res: any) => {
|
|
89
|
+
if (res.status === "error") {
|
|
90
|
+
Setting.showMessage("error", res.msg);
|
|
91
|
+
return;
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
|
|
94
|
+
onUpdateApplication(res.data);
|
|
95
|
+
});
|
|
91
96
|
};
|
|
92
97
|
const getApplicationLogin = (oAuthParams: any) => {
|
|
93
98
|
AuthBackend.getApplicationLogin(oAuthParams).then((res) => {
|
|
@@ -176,7 +181,15 @@ function SignUpForm(props: SignUpFormProps) {
|
|
|
176
181
|
return application.signupItems?.map((signupItem, idx) => {
|
|
177
182
|
return (
|
|
178
183
|
<div key={idx}>
|
|
179
|
-
{renderFormItem(
|
|
184
|
+
{renderFormItem(
|
|
185
|
+
application,
|
|
186
|
+
signupItem,
|
|
187
|
+
state,
|
|
188
|
+
setState,
|
|
189
|
+
t,
|
|
190
|
+
props.CLIENT_ID,
|
|
191
|
+
props.CLIENT_SECRET
|
|
192
|
+
)}
|
|
180
193
|
</div>
|
|
181
194
|
);
|
|
182
195
|
});
|
|
@@ -190,12 +203,16 @@ type SignUpProps = {
|
|
|
190
203
|
applicationName: string;
|
|
191
204
|
casdoorApiRoot: string;
|
|
192
205
|
springmicroApiRoot?: string;
|
|
206
|
+
CLIENT_ID: string;
|
|
207
|
+
CLIENT_SECRET: string;
|
|
193
208
|
};
|
|
194
209
|
|
|
195
210
|
export function SignUp({
|
|
196
211
|
applicationName,
|
|
197
212
|
casdoorApiRoot,
|
|
198
213
|
springmicroApiRoot,
|
|
214
|
+
CLIENT_ID,
|
|
215
|
+
CLIENT_SECRET,
|
|
199
216
|
}: SignUpProps) {
|
|
200
217
|
Setting.ROOT_URLS.casdoor = casdoorApiRoot;
|
|
201
218
|
if (springmicroApiRoot) {
|
|
@@ -204,19 +221,22 @@ export function SignUp({
|
|
|
204
221
|
const [state, setState] = React.useState<SignUpState>({ application: null });
|
|
205
222
|
|
|
206
223
|
const getApplication = () => {
|
|
207
|
-
ApplicationBackend.getApplication(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
});
|
|
224
|
+
ApplicationBackend.getApplication(
|
|
225
|
+
"admin",
|
|
226
|
+
applicationName,
|
|
227
|
+
CLIENT_ID,
|
|
228
|
+
CLIENT_SECRET
|
|
229
|
+
).then((res: any) => {
|
|
230
|
+
console.log(res);
|
|
231
|
+
if (res.status === "error") {
|
|
232
|
+
Setting.showMessage("error", res.msg);
|
|
233
|
+
return;
|
|
218
234
|
}
|
|
219
|
-
|
|
235
|
+
|
|
236
|
+
setState({
|
|
237
|
+
application: res.data,
|
|
238
|
+
});
|
|
239
|
+
});
|
|
220
240
|
};
|
|
221
241
|
|
|
222
242
|
React.useEffect(() => {
|
|
@@ -234,6 +254,8 @@ export function SignUp({
|
|
|
234
254
|
application: application,
|
|
235
255
|
});
|
|
236
256
|
}}
|
|
257
|
+
CLIENT_ID={CLIENT_ID}
|
|
258
|
+
CLIENT_SECRET={CLIENT_SECRET}
|
|
237
259
|
/>
|
|
238
260
|
</I18nextProvider>
|
|
239
261
|
);
|
|
@@ -265,6 +287,8 @@ export function SignUpProvider({
|
|
|
265
287
|
applicationName,
|
|
266
288
|
casdoorApiRoot,
|
|
267
289
|
springmicroApiRoot,
|
|
290
|
+
CLIENT_ID,
|
|
291
|
+
CLIENT_SECRET,
|
|
268
292
|
children,
|
|
269
293
|
}: React.PropsWithChildren<SignUpProps>) {
|
|
270
294
|
const { t, i18n } = useTranslation();
|
|
@@ -279,19 +303,22 @@ export function SignUpProvider({
|
|
|
279
303
|
React.useState<Record<string, boolean>>({});
|
|
280
304
|
|
|
281
305
|
const getApplication = () => {
|
|
282
|
-
ApplicationBackend.getApplication(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
});
|
|
306
|
+
ApplicationBackend.getApplication(
|
|
307
|
+
"admin",
|
|
308
|
+
applicationName,
|
|
309
|
+
CLIENT_ID,
|
|
310
|
+
CLIENT_SECRET
|
|
311
|
+
).then((res: any) => {
|
|
312
|
+
console.log(res);
|
|
313
|
+
if (res.status === "error") {
|
|
314
|
+
Setting.showMessage("error", res.msg);
|
|
315
|
+
return;
|
|
293
316
|
}
|
|
294
|
-
|
|
317
|
+
|
|
318
|
+
setState({
|
|
319
|
+
application: res.data,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
295
322
|
};
|
|
296
323
|
|
|
297
324
|
const onUpdateApplication = (application: Application) => {
|
|
@@ -1,149 +1,155 @@
|
|
|
1
|
-
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import React from "react";
|
|
16
|
-
import i18next from "i18next";
|
|
17
|
-
import * as UserBackend from "./util/user-api";
|
|
18
|
-
import { CaptchaModal } from "./CaptchaModal";
|
|
19
|
-
import type { Application } from "./util/provider";
|
|
20
|
-
import { useTranslation } from "react-i18next";
|
|
21
|
-
|
|
22
|
-
type ButtonClickArgsTuple = [
|
|
23
|
-
dest: any,
|
|
24
|
-
type: any,
|
|
25
|
-
applicationId: any,
|
|
26
|
-
checkUser?: string
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
export type SendCodeInputProps = {
|
|
30
|
-
value?: any;
|
|
31
|
-
disabled: boolean;
|
|
32
|
-
textBefore?: string;
|
|
33
|
-
onChange: Function;
|
|
34
|
-
onButtonClickArgs: ButtonClickArgsTuple;
|
|
35
|
-
application: Application;
|
|
36
|
-
method: string;
|
|
37
|
-
countryCode: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
1
|
+
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import React from "react";
|
|
16
|
+
import i18next from "i18next";
|
|
17
|
+
import * as UserBackend from "./util/user-api";
|
|
18
|
+
import { CaptchaModal } from "./CaptchaModal";
|
|
19
|
+
import type { Application } from "./util/provider";
|
|
20
|
+
import { useTranslation } from "react-i18next";
|
|
21
|
+
|
|
22
|
+
type ButtonClickArgsTuple = [
|
|
23
|
+
dest: any,
|
|
24
|
+
type: any,
|
|
25
|
+
applicationId: any,
|
|
26
|
+
checkUser?: string
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export type SendCodeInputProps = {
|
|
30
|
+
value?: any;
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
textBefore?: string;
|
|
33
|
+
onChange: Function;
|
|
34
|
+
onButtonClickArgs: ButtonClickArgsTuple;
|
|
35
|
+
application: Application;
|
|
36
|
+
method: string;
|
|
37
|
+
countryCode: string;
|
|
38
|
+
CLIENT_ID: string;
|
|
39
|
+
CLIENT_SECRET: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const SendCodeInput = ({
|
|
43
|
+
value,
|
|
44
|
+
disabled,
|
|
45
|
+
textBefore,
|
|
46
|
+
onChange,
|
|
47
|
+
onButtonClickArgs,
|
|
48
|
+
application,
|
|
49
|
+
method,
|
|
50
|
+
countryCode,
|
|
51
|
+
CLIENT_ID,
|
|
52
|
+
CLIENT_SECRET,
|
|
53
|
+
}: SendCodeInputProps) => {
|
|
54
|
+
const { t } = useTranslation();
|
|
55
|
+
const [visible, setVisible] = React.useState(false);
|
|
56
|
+
const [buttonLeftTime, setButtonLeftTime] = React.useState(0);
|
|
57
|
+
const [buttonLoading, setButtonLoading] = React.useState(false);
|
|
58
|
+
const dialogRef = React.useRef<HTMLElement | null>(null);
|
|
59
|
+
|
|
60
|
+
const handleCountDown = (leftTime = 60) => {
|
|
61
|
+
let leftTimeSecond = leftTime;
|
|
62
|
+
setButtonLeftTime(leftTimeSecond);
|
|
63
|
+
const countDown = () => {
|
|
64
|
+
leftTimeSecond--;
|
|
65
|
+
setButtonLeftTime(leftTimeSecond);
|
|
66
|
+
if (leftTimeSecond === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setTimeout(countDown, 1000);
|
|
70
|
+
};
|
|
71
|
+
setTimeout(countDown, 1000);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleOk = (
|
|
75
|
+
captchaType: string,
|
|
76
|
+
captchaToken: string,
|
|
77
|
+
clientSecret: string
|
|
78
|
+
) => {
|
|
79
|
+
setVisible(false);
|
|
80
|
+
setButtonLoading(true);
|
|
81
|
+
UserBackend.sendCode(
|
|
82
|
+
captchaType,
|
|
83
|
+
captchaToken,
|
|
84
|
+
clientSecret,
|
|
85
|
+
method,
|
|
86
|
+
countryCode,
|
|
87
|
+
...onButtonClickArgs,
|
|
88
|
+
CLIENT_ID,
|
|
89
|
+
CLIENT_SECRET
|
|
90
|
+
).then((res: any) => {
|
|
91
|
+
setButtonLoading(false);
|
|
92
|
+
if (res) {
|
|
93
|
+
handleCountDown(60);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleCancel = () => {
|
|
99
|
+
setVisible(false);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
dialogRef.current = document.getElementById("captcha-modal");
|
|
104
|
+
}, []);
|
|
105
|
+
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
if (dialogRef.current) {
|
|
108
|
+
if (visible) {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
dialogRef.current.showModal();
|
|
111
|
+
} else {
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
dialogRef.current.close();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, [visible]);
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<React.Fragment>
|
|
120
|
+
<div className="flex">
|
|
121
|
+
<input
|
|
122
|
+
className="input"
|
|
123
|
+
// addonBefore={textBefore}
|
|
124
|
+
disabled={disabled}
|
|
125
|
+
value={value}
|
|
126
|
+
// prefix={<SafetyOutlined />}
|
|
127
|
+
placeholder={"Enter your code"}
|
|
128
|
+
onChange={(e: any) => onChange(e.target.value)}
|
|
129
|
+
// onBlur={() => setVisible(true)}
|
|
130
|
+
autoComplete="one-time-code"
|
|
131
|
+
/>
|
|
132
|
+
<button
|
|
133
|
+
className="btn"
|
|
134
|
+
disabled={disabled || buttonLeftTime > 0}
|
|
135
|
+
// loading={buttonLoading}
|
|
136
|
+
onClick={() => setVisible(true)}
|
|
137
|
+
>
|
|
138
|
+
{buttonLeftTime > 0
|
|
139
|
+
? `${buttonLeftTime} s`
|
|
140
|
+
: buttonLoading
|
|
141
|
+
? t("code.sending")
|
|
142
|
+
: t("code.sendCode")}
|
|
143
|
+
</button>
|
|
144
|
+
</div>
|
|
145
|
+
<CaptchaModal
|
|
146
|
+
owner={application.owner}
|
|
147
|
+
name={application.name}
|
|
148
|
+
visible={visible}
|
|
149
|
+
onOk={handleOk}
|
|
150
|
+
onCancel={handleCancel}
|
|
151
|
+
isCurrentProvider={false}
|
|
152
|
+
/>
|
|
153
|
+
</React.Fragment>
|
|
154
|
+
);
|
|
155
|
+
};
|