mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: set password for oauth (#531)
This commit is contained in:
1 parent
5e87d2dcc3
commit
2731d4ba3a
2 files changed
+19
-21
No files matched your search
@@ -302,10 +302,11 @@ class UserRegisterWithCodeHandler extends Handler {
|
|||||||
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
|
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
|
||||||
await token.del(code, token.TYPE_REGISTRATION);
|
await token.del(code, token.TYPE_REGISTRATION);
|
||||||
const [id, mailDomain] = tdoc.mail.split('@');
|
const [id, mailDomain] = tdoc.mail.split('@');
|
||||||
const $set: any = {};
|
const $set: any = tdoc.set || {};
|
||||||
if (mailDomain === 'qq.com' && !Number.isNaN(+id)) $set.avatar = `qq:${id}`;
|
if (mailDomain === 'qq.com' && !Number.isNaN(+id)) $set.avatar = `qq:${id}`;
|
||||||
if (this.session.viewLang) $set.viewLang = this.session.viewLang;
|
if (this.session.viewLang) $set.viewLang = this.session.viewLang;
|
||||||
if (Object.keys($set).length) await user.setById(uid, $set);
|
if (Object.keys($set).length) await user.setById(uid, $set);
|
||||||
|
if (tdoc.oauth) await oauth.set(tdoc.oauth[1], uid);
|
||||||
this.session.viewLang = '';
|
this.session.viewLang = '';
|
||||||
this.session.uid = uid;
|
this.session.uid = uid;
|
||||||
this.session.scope = PERM.PERM_ALL.toString();
|
this.session.scope = PERM.PERM_ALL.toString();
|
||||||
@@ -454,6 +455,7 @@ class OauthCallbackHandler extends Handler {
|
|||||||
await user.setById(uid, { loginat: new Date(), loginip: this.request.ip });
|
await user.setById(uid, { loginat: new Date(), loginip: this.request.ip });
|
||||||
this.session.uid = uid;
|
this.session.uid = uid;
|
||||||
this.session.scope = PERM.PERM_ALL.toString();
|
this.session.scope = PERM.PERM_ALL.toString();
|
||||||
|
this.response.redirect = '/';
|
||||||
} else {
|
} else {
|
||||||
if (r.email) {
|
if (r.email) {
|
||||||
const udoc = await user.getByEmail('system', r.email);
|
const udoc = await user.getByEmail('system', r.email);
|
||||||
@@ -468,7 +470,6 @@ class OauthCallbackHandler extends Handler {
|
|||||||
this.checkPriv(PRIV.PRIV_REGISTER_USER);
|
this.checkPriv(PRIV.PRIV_REGISTER_USER);
|
||||||
let username = '';
|
let username = '';
|
||||||
r.uname ||= [];
|
r.uname ||= [];
|
||||||
r.uname.push(String.random(16));
|
|
||||||
const mailDomain = r.email.split('@')[1];
|
const mailDomain = r.email.split('@')[1];
|
||||||
if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain);
|
if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain);
|
||||||
for (const uname of r.uname) {
|
for (const uname of r.uname) {
|
||||||
@@ -479,26 +480,23 @@ class OauthCallbackHandler extends Handler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const _id = await user.create(
|
const set: Partial<Udoc> = { oauth: args.type };
|
||||||
r.email, username, String.random(32),
|
if (r.bio) set.bio = r.bio;
|
||||||
undefined, this.request.ip,
|
if (r.viewLang) set.viewLang = r.viewLang;
|
||||||
|
if (r.avatar) set.avatar = r.avatar;
|
||||||
|
const [t] = await token.add(
|
||||||
|
token.TYPE_REGISTRATION,
|
||||||
|
system.get('session.unsaved_expire_seconds'),
|
||||||
|
{
|
||||||
|
mail: r.email,
|
||||||
|
username,
|
||||||
|
redirect: this.domain.registerRedirect,
|
||||||
|
set,
|
||||||
|
oauth: [args.type, r.email],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
const $set: Partial<Udoc> = {
|
this.response.redirect = this.url('user_register_with_code', { code: t });
|
||||||
oauth: args.type,
|
|
||||||
loginat: new Date(),
|
|
||||||
loginip: this.request.ip,
|
|
||||||
};
|
|
||||||
if (r.bio) $set.bio = r.bio;
|
|
||||||
if (r.viewLang) $set.viewLang = r.viewLang;
|
|
||||||
if (r.avatar) $set.avatar = r.avatar;
|
|
||||||
await Promise.all([
|
|
||||||
user.setById(_id, $set),
|
|
||||||
oauth.set(r.email, _id),
|
|
||||||
]);
|
|
||||||
this.session.uid = _id;
|
|
||||||
this.session.scope = PERM.PERM_ALL.toString();
|
|
||||||
}
|
}
|
||||||
this.response.redirect = '/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<label class="inverse material textbox">
|
<label class="inverse material textbox">
|
||||||
{{ _('Username') }}
|
{{ _('Username') }}
|
||||||
<input name="uname" type="text" autofocus>
|
<input name="uname" value="{{ username or '' }}" type="text" autofocus>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in new issue
Block a user