From 5c3f3537ca5786e39c0897cfad821c677c5bf921 Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Tue, 14 Nov 2017 16:32:09 +0000 Subject: [PATCH] TEMP --- app.js | 36 +++++++++++++++++++++++++------ lib/github.js | 2 +- lib/users.js | 13 +++++++++++ templates/admin-integrations.html | 1 + 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 239b8f00..27013f6d 100644 --- a/app.js +++ b/app.js @@ -245,12 +245,7 @@ boot.executeInParallel([ // User login via GitHub. app.route(/^\/login\/github\/?$/, async (data, match, end, query) => { const { req: request, res: response } = query; - const { user } = request; - if (!user) { - // Don't allow signing in only with GitHub just yet. - routes.notFoundPage(request, response); - return; - } + let { user } = request; let accessToken = null; let refreshToken = null; @@ -262,6 +257,31 @@ boot.executeInParallel([ return; } + if (!user) { + let verifiedEmails = null; + try { + verifiedEmails = await github.getVerifiedEmails(accessToken); + } catch (error) { + log('[fail] could not get verified emails', error); + routes.notFoundPage(response, user); + return; + } + + const users = db.get('users'); + for (const verifiedEmail of verifiedEmails) { // FIXME multiple emails + if (users[verifiedEmail]) { + // TODO sign in, user = ; + } + } + + if (!user) { + // Don't allow unregistered users to sign in with GitHub just yet. + // TODO "We don't have a Janitor account associated with the GitHub user that you used to sign in." + routes.notFoundPage(response, user); + return; + } + } + try { await users.refreshGitHubAccount(user, accessToken, refreshToken); } catch (error) { @@ -543,3 +563,7 @@ boot.executeInParallel([ // Start regularly scheduling system events, once start-up is complete. events.startScheduling(); }); + +process.on('unhandledRejection', error => { + log('[fail] unhandled promise rejection', error); +}); diff --git a/lib/github.js b/lib/github.js index a3b0f6a5..360e8d80 100644 --- a/lib/github.js +++ b/lib/github.js @@ -55,7 +55,7 @@ exports.authenticate = async function (request) { const { state } = request.query; const expectedState = oauth2States[session.id]; - if (!state || String(state) !== String(expectedState)) { + if (!state /* || String(state) !== String(expectedState) */) { // FIXME hack throw new Error('Bad state: Got ' + state + ' but expected ' + expectedState); } diff --git a/lib/users.js b/lib/users.js index d83c3c54..e2d2dc13 100644 --- a/lib/users.js +++ b/lib/users.js @@ -136,6 +136,19 @@ exports.destroyCloud9Account = function (user) { db.save(); }; +// . +exports.destroy = function (user) { + // TODO delete all containers + // TODO delete user +}; + +// . +exports.merge = function (userToRemove, userToKeep) { + // TODO move containers + // TODO merge name + // TODO move email to secondary email +}; + // Send a single-use login link to the user's email address. exports.sendLoginEmail = function (email, request, callback) { sessions.get(request, (error, session, token) => { diff --git a/templates/admin-integrations.html b/templates/admin-integrations.html index 4887f270..bf672e33 100644 --- a/templates/admin-integrations.html +++ b/templates/admin-integrations.html @@ -41,6 +41,7 @@

Azure

GitHub

+ GitHub OAuth apps