@waline/vercel 1.35.0 → 1.36.0
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 +1 -1
- package/src/controller/oauth.js +25 -35
- package/src/controller/token.js +0 -2
- package/src/controller/user/password.js +1 -1
- package/src/controller/user.js +15 -1
- package/src/logic/base.js +4 -6
- package/src/logic/token.js +0 -1
- package/src/logic/user.js +8 -0
- package/src/service/notify.js +12 -12
package/package.json
CHANGED
package/src/controller/oauth.js
CHANGED
|
@@ -59,8 +59,10 @@ module.exports = class extends think.Controller {
|
|
|
59
59
|
|
|
60
60
|
const userBySocial = await this.modelInstance.select({ [type]: user.id });
|
|
61
61
|
|
|
62
|
+
// when the social account has been linked, then redirect to this linked account profile page. It may be current account or another.
|
|
63
|
+
// If it's another account, user should unlink the social type in that account and then link it.
|
|
62
64
|
if (!think.isEmpty(userBySocial)) {
|
|
63
|
-
const token = jwt.sign(userBySocial[0].
|
|
65
|
+
const token = jwt.sign(userBySocial[0].objectId, this.config('jwtKey'));
|
|
64
66
|
|
|
65
67
|
if (redirect) {
|
|
66
68
|
return this.redirect(think.buildUrl(redirect, { token }));
|
|
@@ -69,12 +71,9 @@ module.exports = class extends think.Controller {
|
|
|
69
71
|
return this.success();
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
if (!user.email) {
|
|
73
|
-
user.email = `${user.id}@mail.${type}`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
74
|
const current = this.ctx.state.userInfo;
|
|
77
75
|
|
|
76
|
+
// when login user link social type, then update data
|
|
78
77
|
if (!think.isEmpty(current)) {
|
|
79
78
|
const updateData = { [type]: user.id };
|
|
80
79
|
|
|
@@ -89,38 +88,29 @@ module.exports = class extends think.Controller {
|
|
|
89
88
|
return this.redirect('/ui/profile');
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const updateData = { [type]: user.id };
|
|
109
|
-
|
|
110
|
-
if (!userByEmail.avatar && user.avatar) {
|
|
111
|
-
updateData.avatar = user.avatar;
|
|
112
|
-
}
|
|
113
|
-
await this.modelInstance.update(updateData, { email: user.email });
|
|
91
|
+
// when user has not login, then we create account by the social type!
|
|
92
|
+
const count = await this.modelInstance.count();
|
|
93
|
+
const data = {
|
|
94
|
+
display_name: user.name,
|
|
95
|
+
email: user.email,
|
|
96
|
+
url: user.url,
|
|
97
|
+
avatar: user.avatar,
|
|
98
|
+
[type]: user.id,
|
|
99
|
+
passowrd: this.hashPassword(Math.random()),
|
|
100
|
+
type: this.isEmpty(count) ? 'administrator' : 'guest',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
await this.modelInstance.add(data);
|
|
104
|
+
|
|
105
|
+
if (!redirect) {
|
|
106
|
+
return this.success();
|
|
114
107
|
}
|
|
115
108
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (redirect) {
|
|
119
|
-
return this.redirect(
|
|
120
|
-
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
109
|
+
// and then generate token!
|
|
110
|
+
const token = jwt.sign(user.objectId, this.config('jwtKey'));
|
|
123
111
|
|
|
124
|
-
return this.
|
|
112
|
+
return this.redirect(
|
|
113
|
+
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token,
|
|
114
|
+
);
|
|
125
115
|
}
|
|
126
116
|
};
|
package/src/controller/token.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const jwt = require('jsonwebtoken');
|
|
2
2
|
const speakeasy = require('speakeasy');
|
|
3
|
-
const helper = require('think-helper');
|
|
4
3
|
|
|
5
4
|
const BaseRest = require('./rest.js');
|
|
6
5
|
|
|
@@ -60,7 +59,6 @@ module.exports = class extends BaseRest {
|
|
|
60
59
|
return this.success({
|
|
61
60
|
...user[0],
|
|
62
61
|
password: null,
|
|
63
|
-
mailMd5: helper.md5(user[0].email.toLowerCase()),
|
|
64
62
|
token: jwt.sign(user[0].email, this.config('jwtKey')),
|
|
65
63
|
});
|
|
66
64
|
}
|
|
@@ -27,7 +27,7 @@ module.exports = class extends BaseRest {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const notify = this.service('notify', this);
|
|
30
|
-
const token = jwt.sign(user[0].
|
|
30
|
+
const token = jwt.sign(user[0].objectId, this.config('jwtKey'));
|
|
31
31
|
const profileUrl = `${this.ctx.serverURL}/ui/profile?token=${token}`;
|
|
32
32
|
|
|
33
33
|
await notify.transporter.sendMail({
|
package/src/controller/user.js
CHANGED
|
@@ -125,7 +125,8 @@ module.exports = class extends BaseRest {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
async putAction() {
|
|
128
|
-
const { display_name, url, avatar, password, type, label } =
|
|
128
|
+
const { display_name, url, avatar, password, type, label, email } =
|
|
129
|
+
this.post();
|
|
129
130
|
const { objectId } = this.ctx.state.userInfo;
|
|
130
131
|
const twoFactorAuth = this.post('2fa');
|
|
131
132
|
|
|
@@ -139,6 +140,19 @@ module.exports = class extends BaseRest {
|
|
|
139
140
|
updateData.label = label;
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
if (email) {
|
|
144
|
+
const user = await this.modelInstance.select({
|
|
145
|
+
email,
|
|
146
|
+
objectId: ['!=', objectId],
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (!think.isEmpty(user)) {
|
|
150
|
+
return this.fail();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
updateData.email = email;
|
|
154
|
+
}
|
|
155
|
+
|
|
142
156
|
if (display_name) {
|
|
143
157
|
updateData.display_name = display_name;
|
|
144
158
|
}
|
package/src/logic/base.js
CHANGED
|
@@ -2,7 +2,6 @@ const path = require('node:path');
|
|
|
2
2
|
const qs = require('node:querystring');
|
|
3
3
|
|
|
4
4
|
const jwt = require('jsonwebtoken');
|
|
5
|
-
const helper = require('think-helper');
|
|
6
5
|
|
|
7
6
|
module.exports = class extends think.Logic {
|
|
8
7
|
constructor(...args) {
|
|
@@ -93,20 +92,20 @@ module.exports = class extends think.Logic {
|
|
|
93
92
|
return;
|
|
94
93
|
}
|
|
95
94
|
const token = state || authorization.replace(/^Bearer /, '');
|
|
96
|
-
let
|
|
95
|
+
let userId = '';
|
|
97
96
|
|
|
98
97
|
try {
|
|
99
|
-
|
|
98
|
+
userId = jwt.verify(token, think.config('jwtKey'));
|
|
100
99
|
} catch (e) {
|
|
101
100
|
think.logger.debug(e);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
if (think.isEmpty(
|
|
103
|
+
if (think.isEmpty(userId) || !think.isString(userId)) {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
const user = await this.modelInstance.select(
|
|
109
|
-
{
|
|
108
|
+
{ objectId: userId },
|
|
110
109
|
{
|
|
111
110
|
field: [
|
|
112
111
|
'id',
|
|
@@ -141,7 +140,6 @@ module.exports = class extends think.Logic {
|
|
|
141
140
|
avatarUrl = avatarProxy + '?url=' + encodeURIComponent(avatarUrl);
|
|
142
141
|
}
|
|
143
142
|
userInfo.avatar = avatarUrl;
|
|
144
|
-
userInfo.mailMd5 = helper.md5(userInfo.email);
|
|
145
143
|
this.ctx.state.userInfo = userInfo;
|
|
146
144
|
this.ctx.state.token = token;
|
|
147
145
|
}
|
package/src/logic/token.js
CHANGED
|
@@ -16,7 +16,6 @@ module.exports = class extends Base {
|
|
|
16
16
|
* @apiSuccess (200) {String} data.display_name user nick name
|
|
17
17
|
* @apiSuccess (200) {String} data.email user email address
|
|
18
18
|
* @apiSuccess (200) {String} data.github user github account name
|
|
19
|
-
* @apiSuccess (200) {String} data.mailMd5 user mail md5
|
|
20
19
|
* @apiSuccess (200) {String} data.objectId user id
|
|
21
20
|
* @apiSuccess (200) {String} data.type user type, administrator or guest
|
|
22
21
|
* @apiSuccess (200) {String} data.url user link
|
package/src/logic/user.js
CHANGED
|
@@ -93,6 +93,7 @@ module.exports = class extends Base {
|
|
|
93
93
|
* @apiVersion 0.0.1
|
|
94
94
|
*
|
|
95
95
|
* @apiParam {String} [display_name] user new nick name
|
|
96
|
+
* @apiParam {String} [email] user email
|
|
96
97
|
* @apiParam {String} [url] user new link
|
|
97
98
|
* @apiParam {String} [password] user new password
|
|
98
99
|
* @apiParam {String} [github] user github account name
|
|
@@ -113,5 +114,12 @@ module.exports = class extends Base {
|
|
|
113
114
|
if (this.id && userInfo.type !== 'administrator') {
|
|
114
115
|
return this.fail();
|
|
115
116
|
}
|
|
117
|
+
|
|
118
|
+
this.rules = {
|
|
119
|
+
email: {
|
|
120
|
+
require: false,
|
|
121
|
+
email: true,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
116
124
|
}
|
|
117
125
|
};
|
package/src/service/notify.js
CHANGED
|
@@ -244,7 +244,7 @@ module.exports = class extends think.Service {
|
|
|
244
244
|
|
|
245
245
|
return fetch(`${qmsgHost}/send/${QMSG_KEY}`, {
|
|
246
246
|
method: 'POST',
|
|
247
|
-
|
|
247
|
+
headers: form.getHeaders(),
|
|
248
248
|
body: form,
|
|
249
249
|
}).then((resp) => resp.json());
|
|
250
250
|
}
|
|
@@ -288,7 +288,7 @@ module.exports = class extends think.Service {
|
|
|
288
288
|
\`\`\`
|
|
289
289
|
{{-self.commentLink}}
|
|
290
290
|
*邮箱:*\`{{self.mail}}\`
|
|
291
|
-
*审核:*{{self.status}}
|
|
291
|
+
*审核:*{{self.status}}
|
|
292
292
|
|
|
293
293
|
仅供评论预览,点击[查看完整內容]({{site.postUrl}})`;
|
|
294
294
|
|
|
@@ -306,18 +306,18 @@ module.exports = class extends think.Service {
|
|
|
306
306
|
},
|
|
307
307
|
};
|
|
308
308
|
|
|
309
|
-
const form = new FormData();
|
|
310
|
-
|
|
311
|
-
form.append('text', this.controller.locale(contentTG, data));
|
|
312
|
-
form.append('chat_id', TG_CHAT_ID);
|
|
313
|
-
form.append('parse_mode', 'MarkdownV2');
|
|
314
|
-
|
|
315
309
|
const resp = await fetch(
|
|
316
310
|
`https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`,
|
|
317
311
|
{
|
|
318
312
|
method: 'POST',
|
|
319
|
-
|
|
320
|
-
|
|
313
|
+
headers: {
|
|
314
|
+
'Content-Type': 'application/json',
|
|
315
|
+
},
|
|
316
|
+
body: JSON.stringify({
|
|
317
|
+
chat_id: TG_CHAT_ID,
|
|
318
|
+
text: this.controller.locale(contentTG, data),
|
|
319
|
+
parse_mode: 'MarkdownV2',
|
|
320
|
+
}),
|
|
321
321
|
},
|
|
322
322
|
).then((resp) => resp.json());
|
|
323
323
|
|
|
@@ -367,7 +367,7 @@ module.exports = class extends think.Service {
|
|
|
367
367
|
|
|
368
368
|
return fetch(`http://www.pushplus.plus/send/${PUSH_PLUS_KEY}`, {
|
|
369
369
|
method: 'POST',
|
|
370
|
-
|
|
370
|
+
headers: form.getHeaders(),
|
|
371
371
|
body: form,
|
|
372
372
|
}).then((resp) => resp.json());
|
|
373
373
|
}
|
|
@@ -406,7 +406,7 @@ module.exports = class extends think.Service {
|
|
|
406
406
|
|
|
407
407
|
return fetch(DISCORD_WEBHOOK, {
|
|
408
408
|
method: 'POST',
|
|
409
|
-
|
|
409
|
+
headers: form.getHeaders(),
|
|
410
410
|
body: form,
|
|
411
411
|
}).then((resp) => resp.statusText);
|
|
412
412
|
// Expected return value: No Content
|