diff --git a/hydro/handler/user.js b/hydro/handler/user.js index 24ea3862..34fc5917 100644 --- a/hydro/handler/user.js +++ b/hydro/handler/user.js @@ -13,6 +13,12 @@ const { class UserLoginHandler extends Handler { async get() { + const [loginWithGithub, loginWithGoogle] = await system.getMany( + ['oauth.githubappid', 'oauth.googleappid'], + ); + this.response.body = { + loginWithGithub, loginWithGoogle, + }; this.response.template = 'user_login.html'; } @@ -187,13 +193,15 @@ class OauthHandler extends Handler { class OauthCallbackHandler extends Handler { 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.githubsecret'), system.get('server.url'), + system.get('proxy'), token.get(state, token.TYPE_OAUTH), ]); const res = await superagent.post('https://github.com/login/oauth/access_token') + .proxy(proxy) .send({ client_id: appid, client_secret: secret, @@ -209,9 +217,11 @@ class OauthCallbackHandler extends Handler { } const t = res.body.access_token; const userInfo = await superagent.get('https://api.github.com/user') + .proxy(proxy) + .set('User-Agent', 'Hydro-OAuth') .set('Authorization', `token ${t}`); const ret = { - email: userInfo.body.mail, + email: userInfo.body.email, bio: userInfo.body.bio, uname: [userInfo.body.name, userInfo.body.login], }; diff --git a/hydro/model/setting.js b/hydro/model/setting.js index bc3d8d32..084bc357 100644 --- a/hydro/model/setting.js +++ b/hydro/model/setting.js @@ -78,7 +78,7 @@ AccountSetting( Setting('setting_info', 'bio', null, null, 'markdown', 'Bio'), 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.'), ); diff --git a/hydro/service/server.js b/hydro/service/server.js index f3a2cd78..97f43331 100644 --- a/hydro/service/server.js +++ b/hydro/service/server.js @@ -210,23 +210,24 @@ class Handler { this.response.disposition = `attachment; filename="${name}"`; } - url(name, kwargs = {}) { // eslint-disable-line class-methods-use-this + url(name, kwargs = {}) { let res = '#'; + const args = { ...kwargs }; try { - delete kwargs.__keywords; + delete args.__keywords; if (this.args.domainId !== 'system') { name += '_with_domainId'; - kwargs.domainId = kwargs.domainId || this.args.domainId; + args.domainId = args.domainId || this.args.domainId; } - const { anchor, query } = kwargs; - delete kwargs.anchor; - delete kwargs.query; - if (query) res = router.url(name, kwargs, { query }); - else res = router.url(name, kwargs); + const { anchor, query } = args; + delete args.anchor; + delete args.query; + if (query) res = router.url(name, args, { query }); + else res = router.url(name, args); if (anchor) return `${res}#${anchor}`; } catch (e) { console.error(e.message); - console.log(name, kwargs); + console.log(name, args); } return res; } @@ -417,19 +418,20 @@ class ConnectionHandler { 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 = '#'; + const args = { ...kwargs }; try { - delete kwargs.__keywords; + delete args.__keywords; if (this.args.domainId !== 'system') { name += '_with_domainId'; - kwargs.domainId = kwargs.domainId || this.args.domainId; + args.domainId = args.domainId || this.args.domainId; } - const { anchor, query } = kwargs; - delete kwargs.anchor; - delete kwargs.query; - if (query) res = router.url(name, kwargs, { query }); - else res = router.url(name, kwargs); + const { anchor, query } = args; + delete args.anchor; + delete args.query; + if (query) res = router.url(name, args, { query }); + else res = router.url(name, args); if (anchor) return `${res}#${anchor}`; } catch (e) { console.error(e.message); diff --git a/templates/partials/login_dialog.html b/templates/partials/login_dialog.html index 5d4bc18e..ceb104cc 100644 --- a/templates/partials/login_dialog.html +++ b/templates/partials/login_dialog.html @@ -1,9 +1,8 @@ -{# No Compression #} + {% if loginWithGithub %} +
+ {{ _('Login with Github') }} +
+ {% endif %} + {% if loginWithGoogle %} +
+ {{ _('Login with Google') }} +
+ {% endif %}