some simple bug fix

This commit is contained in:
undefined committed 2020-06-23 12:36:47 +08:00
1 parent d2173eeb38
commit d7c9b695b0
6 files changed
+55 -28

No files matched your search

+12 -2
View File
@@ -13,6 +13,12 @@ const {
class UserLoginHandler extends Handler { class UserLoginHandler extends Handler {
async get() { async get() {
const [loginWithGithub, loginWithGoogle] = await system.getMany(
['oauth.githubappid', 'oauth.googleappid'],
);
this.response.body = {
loginWithGithub, loginWithGoogle,
};
this.response.template = 'user_login.html'; this.response.template = 'user_login.html';
} }
@@ -187,13 +193,15 @@ class OauthHandler extends Handler {
class OauthCallbackHandler extends Handler { class OauthCallbackHandler extends Handler {
async github({ state, code }) { async github({ state, code }) {
const [appid, secret, url, s] = await Promise.all([ const [appid, secret, url, proxy, s] = await Promise.all([
system.get('oauth.githubappid'), system.get('oauth.githubappid'),
system.get('oauth.githubsecret'), system.get('oauth.githubsecret'),
system.get('server.url'), system.get('server.url'),
system.get('proxy'),
token.get(state, token.TYPE_OAUTH), token.get(state, token.TYPE_OAUTH),
]); ]);
const res = await superagent.post('https://github.com/login/oauth/access_token') const res = await superagent.post('https://github.com/login/oauth/access_token')
.proxy(proxy)
.send({ .send({
client_id: appid, client_id: appid,
client_secret: secret, client_secret: secret,
@@ -209,9 +217,11 @@ class OauthCallbackHandler extends Handler {
} }
const t = res.body.access_token; const t = res.body.access_token;
const userInfo = await superagent.get('https://api.github.com/user') const userInfo = await superagent.get('https://api.github.com/user')
.proxy(proxy)
.set('User-Agent', 'Hydro-OAuth')
.set('Authorization', `token ${t}`); .set('Authorization', `token ${t}`);
const ret = { const ret = {
email: userInfo.body.mail, email: userInfo.body.email,
bio: userInfo.body.bio, bio: userInfo.body.bio,
uname: [userInfo.body.name, userInfo.body.login], uname: [userInfo.body.name, userInfo.body.login],
}; };
+1 -1
View File
@@ -78,7 +78,7 @@ AccountSetting(
Setting('setting_info', 'bio', null, Setting('setting_info', 'bio', null,
null, 'markdown', 'Bio'), null, 'markdown', 'Bio'),
Setting('setting_customize', 'backgroundImage', null, Setting('setting_customize', 'backgroundImage', null,
'/components/background/profile/backgrounds/1.jpg', 'text', 'Profile Background Image', '/components/profile/backgrounds/1.jpg', 'text', 'Profile Background Image',
'Choose the background image in your profile page.'), 'Choose the background image in your profile page.'),
); );
+19 -17
View File
@@ -210,23 +210,24 @@ class Handler {
this.response.disposition = `attachment; filename="${name}"`; this.response.disposition = `attachment; filename="${name}"`;
} }
url(name, kwargs = {}) { // eslint-disable-line class-methods-use-this url(name, kwargs = {}) {
let res = '#'; let res = '#';
const args = { ...kwargs };
try { try {
delete kwargs.__keywords; delete args.__keywords;
if (this.args.domainId !== 'system') { if (this.args.domainId !== 'system') {
name += '_with_domainId'; name += '_with_domainId';
kwargs.domainId = kwargs.domainId || this.args.domainId; args.domainId = args.domainId || this.args.domainId;
} }
const { anchor, query } = kwargs; const { anchor, query } = args;
delete kwargs.anchor; delete args.anchor;
delete kwargs.query; delete args.query;
if (query) res = router.url(name, kwargs, { query }); if (query) res = router.url(name, args, { query });
else res = router.url(name, kwargs); else res = router.url(name, args);
if (anchor) return `${res}#${anchor}`; if (anchor) return `${res}#${anchor}`;
} catch (e) { } catch (e) {
console.error(e.message); console.error(e.message);
console.log(name, kwargs); console.log(name, args);
} }
return res; return res;
} }
@@ -417,19 +418,20 @@ class ConnectionHandler {
for (const i in p) this.request.params[p[i][0]] = decodeURIComponent(p[i][1]); for (const i in p) this.request.params[p[i][0]] = decodeURIComponent(p[i][1]);
} }
url(name, kwargs = {}) { // eslint-disable-line class-methods-use-this url(name, kwargs = {}) {
let res = '#'; let res = '#';
const args = { ...kwargs };
try { try {
delete kwargs.__keywords; delete args.__keywords;
if (this.args.domainId !== 'system') { if (this.args.domainId !== 'system') {
name += '_with_domainId'; name += '_with_domainId';
kwargs.domainId = kwargs.domainId || this.args.domainId; args.domainId = args.domainId || this.args.domainId;
} }
const { anchor, query } = kwargs; const { anchor, query } = args;
delete kwargs.anchor; delete args.anchor;
delete kwargs.query; delete args.query;
if (query) res = router.url(name, kwargs, { query }); if (query) res = router.url(name, args, { query });
else res = router.url(name, kwargs); else res = router.url(name, args);
if (anchor) return `${res}#${anchor}`; if (anchor) return `${res}#${anchor}`;
} catch (e) { } catch (e) {
console.error(e.message); console.error(e.message);
+7 -2
View File
@@ -1,9 +1,8 @@
{# No Compression #}
<div class="dialog dialog--signin" style="display:none"> <div class="dialog dialog--signin" style="display:none">
<div class="dialog__content"> <div class="dialog__content">
<div class="dialog--signin__bg"> <div class="dialog--signin__bg">
<div class="dialog--signin__side"> <div class="dialog--signin__side">
<h1>{{ _("Don\'t have an account?") }}</h1> <h1>{{ _("Don't have an account?") }}</h1>
<p>{{ _('By signing up a Hydro universal account, you can submit code and join discussions in all online judging services provided by us.') }}</p> <p>{{ _('By signing up a Hydro universal account, you can submit code and join discussions in all online judging services provided by us.') }}</p>
<div><a href="{{ url('user_register') }}" class="inverse rounded button">{{ _('Sign Up Now') }}</a></div> <div><a href="{{ url('user_register') }}" class="inverse rounded button">{{ _('Sign Up Now') }}</a></div>
</div> </div>
@@ -32,6 +31,12 @@
<input type="checkbox" name="rememberme">{{ _('Remember me') }} <input type="checkbox" name="rememberme">{{ _('Remember me') }}
</label> </label>
</div></div> </div></div>
<div class="row"><div class="columns">
<a href="{{ url('user_oauth', type='github') }}" class="expanded rounded button">{{ _('Login with Github') }}</a>
</div></div>
<div class="row"><div class="columns">
<a href="{{ url('user_oauth', type='google') }}" class="expanded rounded button">{{ _('Login with Google') }}</a>
</div></div>
<div class="row"><div class="columns"> <div class="row"><div class="columns">
<input type="submit" value="{{ _('Sign In') }}" class="expanded rounded primary button"> <input type="submit" value="{{ _('Sign In') }}" class="expanded rounded primary button">
</div></div> </div></div>
+2 -2
View File
@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<style> <style>
.user-profile-bg { .user-profile-bg {
background-image : "{{ udoc.backgroundImage }}"; background-image : url("{{ udoc.backgroundImage }}");
} }
</style> </style>
<div class="row"> <div class="row">
@@ -31,7 +31,7 @@
</p> </p>
<p>{{ _('Solved {0} problems, RP: {1} (No. {2})').format(udoc.nAccept|default(0), udoc['rp']|default(0.0)|round(2), udoc['rank']|default('?')) }}</p> <p>{{ _('Solved {0} problems, RP: {1} (No. {2})').format(udoc.nAccept|default(0), udoc['rp']|default(0.0)|round(2), udoc['rank']|default('?')) }}</p>
<div class="profile-header__contact-bar"> <div class="profile-header__contact-bar">
{% if is_self_profile %} {% if isSelfProfile %}
<a class="profile-header__contact-item" href="{{ url('home_settings', category='account') }}" data-tooltip="{{ _('Edit Profile') }}"> <a class="profile-header__contact-item" href="{{ url('home_settings', category='account') }}" data-tooltip="{{ _('Edit Profile') }}">
<span class="icon icon-edit"></span> <span class="icon icon-edit"></span>
</a> </a>
+14 -4
View File
@@ -17,10 +17,20 @@
</label> </label>
</div></div> </div></div>
<div class="row"><div class="columns"> <div class="row"><div class="columns">
<label class="inverse material checkbox"> <label class="inverse material checkbox">
<input type="checkbox" name="rememberme">{{ _('Remember me') }} <input type="checkbox" name="rememberme">{{ _('Remember me') }}
</label> </label>
</div></div> </div></div>
{% if loginWithGithub %}
<div class="row"><div class="columns">
<a href="{{ url('user_oauth', type='github') }}" class="expanded rounded button inverse">{{ _('Login with Github') }}</a>
</div></div>
{% endif %}
{% if loginWithGoogle %}
<div class="row"><div class="columns">
<a href="{{ url('user_oauth', type='google') }}" class="expanded rounded button inverse">{{ _('Login with Google') }}</a>
</div></div>
{% endif %}
<div class="row"><div class="columns"> <div class="row"><div class="columns">
<div class="text-center"> <div class="text-center">
<input type="submit" value="{{ _('Login') }}" class="inverse expanded rounded primary button"> <input type="submit" value="{{ _('Login') }}" class="inverse expanded rounded primary button">