mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix oauth login redirect url (#1172)
This commit is contained in:
1 parent
8d76be8f0b
commit
01771a43e5
3 files changed
+14
-8
No files matched your search
@@ -46,9 +46,11 @@ async function successfulAuth(this: Handler, udoc: User) {
|
|||||||
class UserLoginHandler extends Handler {
|
class UserLoginHandler extends Handler {
|
||||||
noCheckPermView = true;
|
noCheckPermView = true;
|
||||||
|
|
||||||
async get() {
|
@param('redirect', Types.String, true)
|
||||||
|
async get(domainId: string, redirect: string = '') {
|
||||||
this.response.template = 'user_login.html';
|
this.response.template = 'user_login.html';
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
|
redirect,
|
||||||
builtInLogin: system.get('server.login'),
|
builtInLogin: system.get('server.login'),
|
||||||
loginMethods: this.loginMethods,
|
loginMethods: this.loginMethods,
|
||||||
};
|
};
|
||||||
@@ -458,7 +460,9 @@ class OauthHandler extends Handler {
|
|||||||
noCheckPermView = true;
|
noCheckPermView = true;
|
||||||
|
|
||||||
@param('type', Types.Key)
|
@param('type', Types.Key)
|
||||||
async get(domainId: string, type: string) {
|
@param('redirect', Types.String, true)
|
||||||
|
async get(domainId: string, type: string, redirect = '') {
|
||||||
|
this.session.oauthRedirect = redirect;
|
||||||
await this.ctx.oauth.providers[type]?.get.call(this);
|
await this.ctx.oauth.providers[type]?.get.call(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,22 +482,24 @@ class OauthCallbackHandler extends Handler {
|
|||||||
if (existing.some((id) => id && id !== this.user._id)) {
|
if (existing.some((id) => id && id !== this.user._id)) {
|
||||||
throw new BadRequestError('Already binded to another account');
|
throw new BadRequestError('Already binded to another account');
|
||||||
}
|
}
|
||||||
this.response.redirect = '/home/security';
|
this.response.redirect = this.session.oauthRedirect || this.url('home_security');
|
||||||
|
delete this.session.oauthRedirect;
|
||||||
await Promise.all(ids.map((i) => this.ctx.oauth.set(args.type, i, this.user._id)));
|
await Promise.all(ids.map((i) => this.ctx.oauth.set(args.type, i, this.user._id)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const effective = existing.find((i) => i);
|
const effective = existing.find((i) => i);
|
||||||
|
|
||||||
if (effective) {
|
if (effective) {
|
||||||
await successfulAuth.call(this, await user.getById('system', effective));
|
await successfulAuth.call(this, await user.getById('system', effective));
|
||||||
this.response.redirect = '/';
|
this.response.redirect = this.session.oauthRedirect || this.url('homepage');
|
||||||
|
delete this.session.oauthRedirect;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const udoc = await user.getByEmail('system', r.email);
|
const udoc = await user.getByEmail('system', r.email);
|
||||||
if (udoc) {
|
if (udoc) {
|
||||||
await Promise.all(ids.map((i) => this.ctx.oauth.set(args.type, i, udoc._id)));
|
await Promise.all(ids.map((i) => this.ctx.oauth.set(args.type, i, udoc._id)));
|
||||||
await successfulAuth.call(this, udoc);
|
await successfulAuth.call(this, udoc);
|
||||||
this.response.redirect = '/';
|
this.response.redirect = this.session.oauthRedirect || this.url('homepage');
|
||||||
|
delete this.session.oauthRedirect;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!provider.canRegister) throw new ForbiddenError('No binded account found');
|
if (!provider.canRegister) throw new ForbiddenError('No binded account found');
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{%- for v in loginMethods -%}
|
{%- for v in loginMethods -%}
|
||||||
<div class="row"><div class="columns">
|
<div class="row"><div class="columns">
|
||||||
<a href="{{ url('user_oauth', type=v.id) }}" class="expanded rounded button">{{ _(v.text) }}</a>
|
<a href="{{ url('user_oauth', type=v.id, query={redirect: handler.request.url}) }}" class="expanded rounded button">{{ _(v.text) }}</a>
|
||||||
</div></div>
|
</div></div>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
<div class="row"><div class="columns">
|
<div class="row"><div class="columns">
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{%- for v in loginMethods -%}
|
{%- for v in loginMethods -%}
|
||||||
<div class="row"><div class="columns">
|
<div class="row"><div class="columns">
|
||||||
<a href="{{ url('user_oauth', type=v.id) }}" class="expanded rounded button inverse">{{ _(v.text) }}</a>
|
<a href="{{ url('user_oauth', type=v.id, query={redirect: redirect}) }}" class="expanded rounded button inverse">{{ _(v.text) }}</a>
|
||||||
</div></div>
|
</div></div>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
<div class="row"><div class="columns">
|
<div class="row"><div class="columns">
|
||||||
|
|||||||
Reference in new issue
Block a user