From 6de1f49a1f8e99f759ff177c8b9d529364f9a425 Mon Sep 17 00:00:00 2001 From: benmcmahon100 Date: Tue, 18 Aug 2015 19:21:34 +0100 Subject: [PATCH 1/3] Temp fix for buttons on modals and bonfires exec on load --- .../coursewaresJSFramework_0.0.6.js | 4 + public/js/main_0.0.3.js | 200 ++++++++++-------- server/views/partials/challenge-modals.jade | 2 +- 3 files changed, 117 insertions(+), 89 deletions(-) diff --git a/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js b/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js index 712811c9c1..ddeb9519f4 100644 --- a/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js +++ b/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js @@ -388,3 +388,7 @@ var resetEditor = function resetEditor() { editor.setValue(allSeeds); codeStorage.updateStorage(); }; + +$(document).ready(function(){ + bonfireExecute(); +}); diff --git a/public/js/main_0.0.3.js b/public/js/main_0.0.3.js index 3bafc6c8c9..c291cc196a 100644 --- a/public/js/main_0.0.3.js +++ b/public/js/main_0.0.3.js @@ -22,67 +22,6 @@ $(document).ready(function() { setCSRFToken($('meta[name="csrf-token"]').attr('content')); - $('#i-want-help').on('click', function() { - $('#help-modal').modal('hide'); - var editorValue = editor.getValue(); - var currentLocation = window.location.href; - $.post( - '/get-help', - { - payload: { - code: editorValue, - challenge: currentLocation - } - }, - function(res) { - if (res) { - window.open('https://gitter.im/FreeCodeCamp/Help', '_blank') - } - } - ); - }); - - $('#i-want-help-editorless').on('click', function() { - $('#help-editorless-modal').modal('hide'); - var currentLocation = window.location.href; - $.post( - '/get-help', - { - payload: { - challenge: currentLocation - } - }, - function(res) { - if (res) { - window.open('https://gitter.im/FreeCodeCamp/Help', '_blank') - } - } - ); - }); - - $('#report-issue').on('click', function() { - $('#issue-modal').modal('hide'); - window.open('https://github.com/freecodecamp/freecodecamp/issues/new?&body=Challenge '+ window.location.href +' has an issue. Please describe how to reproduce it, and include links to screenshots if possible.', '_blank') - }); - - $('#i-want-to-pair').on('click', function() { - $('#pair-modal').modal('hide'); - var currentLocation = window.location.href; - $.post( - '/get-pair', - { - payload: { - challenge: currentLocation - } - }, - function(res) { - if (res) { - window.open('https://gitter.im/FreeCodeCamp/LetsPair', '_blank') - } - } - ); - }); - $('.checklist-element').each(function() { var checklistElementId = $(this).attr('id'); if(!!localStorage[checklistElementId]) { @@ -118,41 +57,126 @@ $(document).ready(function() { $(this).unbind("error").attr("src", "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png"); }); - $('#completed-courseware').on('click', function() { - $('#complete-courseware-dialog').modal('show'); - }); + function reBindModals(){ - $('#completed-courseware-editorless').on('click', function() { - $('#complete-courseware-editorless-dialog').modal('show'); - }); + $('#i-want-help').unbind('click'); + $('#i-want-help').on('click', function() { + $('#help-modal').modal('hide'); + var editorValue = editor.getValue(); + var currentLocation = window.location.href; + $.post( + '/get-help', + { + payload: { + code: editorValue, + challenge: currentLocation + } + }, + function(res) { + if (res) { + window.open('https://gitter.im/FreeCodeCamp/Help', '_blank') + } + } + ); + }); - $('#trigger-pair-modal').on('click', function() { - $('#pair-modal').modal('show'); - }); + $('#i-want-help-editorless').unbind('click'); + $('#i-want-help-editorless').on('click', function() { + $('#help-editorless-modal').modal('hide'); + var currentLocation = window.location.href; + $.post( + '/get-help', + { + payload: { + challenge: currentLocation + } + }, + function(res) { + if (res) { + window.open('https://gitter.im/FreeCodeCamp/Help', '_blank') + } + } + ); + }); - $('#trigger-reset-modal').on('click', function() { - $('#reset-modal').modal('show'); - }); + $('#report-issue').unbind('click'); + $('#report-issue').on('click', function() { + $('#issue-modal').modal('hide'); + window.open('https://github.com/freecodecamp/freecodecamp/issues/new?&body=Challenge '+ window.location.href +' has an issue. Please describe how to reproduce it, and include links to screenshots if possible.', '_blank') + }); - $('#trigger-help-modal').on('click', function() { - $('#help-modal').modal('show'); - }); + $('#i-want-help').unbind('click'); + $('#i-want-to-pair').on('click', function() { + $('#pair-modal').modal('hide'); + var currentLocation = window.location.href; + $.post( + '/get-pair', + { + payload: { + challenge: currentLocation + } + }, + function(res) { + if (res) { + window.open('https://gitter.im/FreeCodeCamp/LetsPair', '_blank') + } + } + ); + }); - $('#trigger-issue-modal').on('click', function() { - $('#issue-modal').modal('show'); - }); + $('#completed-courseware').unbind('click'); + $('#completed-courseware').on('click', function() { + $('#complete-courseware-dialog').modal('show'); + }); - $('#completed-zipline-or-basejump').on('click', function() { - $('#complete-zipline-or-basejump-dialog').modal('show'); - }); + $('#completed-courseware-editorless').unbind('click'); + $('#completed-courseware-editorless').on('click', function() { + $('#complete-courseware-editorless-dialog').modal('show'); + }); - $('#complete-courseware-dialog').on('hidden.bs.modal', function() { - editor.focus(); - }); + $('#trigger-pair-modal').unbind('click'); + $('#trigger-pair-modal').on('click', function() { + $('#pair-modal').modal('show'); + }); - $('#complete-challenge-dialog').on('hidden.bs.modal', function() { - editor.focus(); - }); + $('#trigger-reset-modal').unbind('click'); + $('#trigger-reset-modal').on('click', function() { + $('#reset-modal').modal('show'); + }); + + $('#trigger-help-modal').unbind('click'); + $('#trigger-help-modal').on('click', function() { + $('#help-modal').modal('show'); + }); + + $('#trigger-issue-modal').unbind('click'); + $('#trigger-issue-modal').on('click', function() { + $('#issue-modal').modal('show'); + }); + + $('#completed-zipline-or-basejump').unbind('click'); + $('#completed-zipline-or-basejump').on('click', function() { + $('#complete-zipline-or-basejump-dialog').modal('show'); + }); + + $('#completed-courseware-dialog').unbind('click'); + $('#complete-courseware-dialog').on('hidden.bs.modal', function() { + editor.focus(); + }); + + $('#completed-zipline-or-basejump').unbind('click'); + $('#complete-zipline-or-basejump').on('hidden.bs.modal', function() { + editor.focus(); + }); + }; + + + + $(window).resize(function(){ + reBindModals(); + }); + + reBindModals(); var challengeTypes = { 'HTML_CSS_JQ': '0', diff --git a/server/views/partials/challenge-modals.jade b/server/views/partials/challenge-modals.jade index e3b657fec9..399cb4aab1 100644 --- a/server/views/partials/challenge-modals.jade +++ b/server/views/partials/challenge-modals.jade @@ -34,7 +34,7 @@ | . h3 If you've already read the errors and searched Google, you should ask for help. h3 This will take you to our help room. - a.btn.btn-lg.btn-primary.btn-block(href='https://gitter.im/FreeCodeCamp/LetsPair', data-dismiss='modal', aria-hidden='true' target='_blank') Take me to the help room + a.btn.btn-lg.btn-primary.btn-block(href='https://gitter.im/FreeCodeCamp/help', data-dismiss='modal', aria-hidden='true' target='_blank') Take me to the help room a.btn.btn-lg.btn-info.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel #reset-modal.modal(tabindex='-1') From d9d44ae509d771b34ebe2a18919c8720cd0254fb Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 18 Aug 2015 13:08:27 -0700 Subject: [PATCH 2/3] fix redirect link failures to /account --- server/passport-providers.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/passport-providers.js b/server/passport-providers.js index f15ebc89fa..f0d99c3c3e 100644 --- a/server/passport-providers.js +++ b/server/passport-providers.js @@ -1,5 +1,6 @@ var successRedirect = '/'; var failureRedirect = '/login'; +var linkFailureRedirect = '/account'; module.exports = { local: { provider: 'local', @@ -34,7 +35,7 @@ module.exports = { callbackURL: '/link/facebook/callback', callbackPath: '/link/facebook/callback', successRedirect: successRedirect, - failureRedirect: failureRedirect, + failureRedirect: linkFailureRedirect, scope: ['email', 'user_likes'], link: true, failureFlash: true @@ -63,7 +64,7 @@ module.exports = { callbackURL: '/link/google/callback', callbackPath: '/link/google/callback', successRedirect: successRedirect, - failureRedirect: failureRedirect, + failureRedirect: linkFailureRedirect, scope: ['email', 'profile'], link: true, failureFlash: true @@ -89,7 +90,7 @@ module.exports = { callbackURL: '/link/twitter/callback', callbackPath: '/link/twitter/callback', successRedirect: successRedirect, - failureRedirect: failureRedirect, + failureRedirect: linkFailureRedirect, consumerKey: process.env.TWITTER_KEY, consumerSecret: process.env.TWITTER_SECRET, link: true, @@ -120,7 +121,7 @@ module.exports = { callbackURL: '/link/linkedin/callback', callbackPath: '/link/linkedin/callback', successRedirect: successRedirect, - failureRedirect: failureRedirect, + failureRedirect: linkFailureRedirect, clientID: process.env.LINKEDIN_ID, clientSecret: process.env.LINKEDIN_SECRET, scope: ['r_basicprofile', 'r_emailaddress'], @@ -152,7 +153,7 @@ module.exports = { callbackURL: '/auth/github/callback/link', callbackPath: '/auth/github/callback/link', successRedirect: successRedirect, - failureRedirect: failureRedirect, + failureRedirect: linkFailureRedirect, clientID: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET, scope: ['email'], From b2f4e520cb2d2c4ca831627f65703b0a86613b1c Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 18 Aug 2015 14:48:22 -0700 Subject: [PATCH 3/3] fix account link failure now flashes --- package.json | 2 +- server/boot/a-extendUserIdent.js | 26 +++++++++++++++++++------- server/views/partials/flash.jade | 6 +++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index c4d4b81528..b14ee1e15f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "lodash": "^3.9.3", "loopback": "https://github.com/FreeCodeCamp/loopback.git#fix/no-password", "loopback-boot": "^2.8.0", - "loopback-component-passport": "^1.5.0", + "loopback-component-passport": "https://github.com/FreeCodeCamp/loopback-component-passport.git#feature/flashfailure", "loopback-connector-mongodb": "^1.10.0", "lusca": "~1.0.2", "method-override": "~2.3.0", diff --git a/server/boot/a-extendUserIdent.js b/server/boot/a-extendUserIdent.js index 1d504b5b4e..f5f5e9ebc7 100644 --- a/server/boot/a-extendUserIdent.js +++ b/server/boot/a-extendUserIdent.js @@ -1,5 +1,9 @@ +import{ Observable } from 'rx'; import { observeMethod, observeQuery } from '../utils/rx'; import { getSocialProvider } from '../utils/auth'; +import debugFactory from 'debug'; + +const debug = debugFactory('fcc:userIdent'); export default function({ models }) { const { User, UserIdentity, UserCredential } = models; @@ -20,15 +24,18 @@ export default function({ models }) { options = {}; } const user$ = findUserById(userId); - console.log('provider', provider); - console.log('id', profile.id); - findIdent({ - provider: getSocialProvider(provider), - externalId: profile.id - }) + const query = { + where: { + provider: getSocialProvider(provider), + externalId: profile.id + } + }; + + debug('link identity query', query); + findIdent(query) .flatMap(identity => { const modified = new Date(); - if (!identity || identity.externalId !== profile.id) { + if (!identity) { return observeQuery(UserIdentity, 'create', { provider: getSocialProvider(provider), externalId: profile.id, @@ -40,6 +47,11 @@ export default function({ models }) { modified }); } + if (identity.userId !== userId) { + return Observable.throw( + new Error('An account is already linked to that profile') + ); + } identity.credentials = credentials; return observeQuery(identity, 'updateAttributes', { profile: getSocialProvider(provider), diff --git a/server/views/partials/flash.jade b/server/views/partials/flash.jade index e69a6d69bc..512e7ae7a4 100644 --- a/server/views/partials/flash.jade +++ b/server/views/partials/flash.jade @@ -1,11 +1,11 @@ .row .col-xs-12 - if messages.errors + if (messages.errors || messages.error) .alert.alert-danger.fade.in button.close(type='button', data-dismiss='alert') span.ion-close-circled - for error in messages.errors - div!= error.msg + for error in (messages.errors || messages.error) + div!= error.msg || error if messages.info .alert.alert-info.fade.in button.close(type='button', data-dismiss='alert')