From b645253faad028ab7e7b607576dc279e5e382212 Mon Sep 17 00:00:00 2001 From: Paul <41552663+molecula451@users.noreply.github.com> Date: Tue, 15 Sep 2020 06:59:27 -0400 Subject: [PATCH 1/5] make sure it uses python3 (#7383) --- docs/RUNNING_LOCALLY_DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/RUNNING_LOCALLY_DOCKER.md b/docs/RUNNING_LOCALLY_DOCKER.md index 08b3c746c18..82c8aa47528 100644 --- a/docs/RUNNING_LOCALLY_DOCKER.md +++ b/docs/RUNNING_LOCALLY_DOCKER.md @@ -337,7 +337,7 @@ Add `import ipdb;ipdb.set_trace()` to the method you want to inspect, you then r `Q: How can I access the Django shell, similar to: python manage.py shell ?` -Simply run: `make get_django_shell` or `docker-compose exec web python app/manage.py shell` +Simply run: `make get_django_shell` or `docker-compose exec web python3 app/manage.py shell` #### Access BASH From 3762d374e0417093ba5ff1e70d490c206a917261 Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Fri, 11 Sep 2020 16:03:28 -0400 Subject: [PATCH 2/5] Add SMS Verification directly on the Trust Bonus tab * Updates the Trust Bonus tab such that SMS verification can be done directly on the page * Create a Vue component by extracting all relevant SMS code from the cart page * Tie the new component to the Trust Bonus tab and display it when the user clicks the verify button --- app/assets/v2/js/pages/profile-trust.js | 228 ++++++++++++++++++ app/dashboard/templates/profiles/profile.html | 1 + .../templates/profiles/tab_trust.html | 7 +- 3 files changed, 233 insertions(+), 3 deletions(-) diff --git a/app/assets/v2/js/pages/profile-trust.js b/app/assets/v2/js/pages/profile-trust.js index 8c603892c60..0eb747952ba 100644 --- a/app/assets/v2/js/pages/profile-trust.js +++ b/app/assets/v2/js/pages/profile-trust.js @@ -139,3 +139,231 @@ let show_brightid_verify_modal = function(brightid_uuid) { $(content).appendTo('body'); $('#verify_brightid_modal').bootstrapModal('show'); }; + +Vue.component('sms-verify-modal', { + delimiters: [ '[[', ']]' ], + data: function() { + return { + csrf: $("input[name='csrfmiddlewaretoken']").val(), + validationStep: 'intro', + showValidation: false, + phone: '', + validNumber: false, + errorMessage: '', + verified: document.verified, + code: '', + timePassed: 0, + timeInterval: 0, + display_email_option: false, + countDownActive: false + }; + }, + mounted: function() { + $(document).on('click', '#verify-sms-link', function(event) { + event.preventDefault(); + this.showValidation = true; + }.bind(this)); + }, + template: ` + + `, + methods: { + dismissVerification() { + localStorage.setItem('dismiss-sms-validation', true); + this.showValidation = false; + }, + // VALIDATE + validateCode() { + const vm = this; + + if (vm.code) { + const verificationRequest = fetchData('/sms/validate/', 'POST', { + code: vm.code, + phone: vm.phone + }, {'X-CSRFToken': vm.csrf}); + + $.when(verificationRequest).then(response => { + vm.verificationEnabled = false; + vm.verified = true; + vm.validationStep = 'verifyNumber'; + vm.showValidation = false; + _alert('You have been verified', 'success'); + }).catch((e) => { + vm.errorMessage = e.responseJSON.msg; + }); + } + }, + startVerification() { + this.phone = ''; + this.validationStep = 'requestVerification'; + this.validNumber = false; + this.errorMessage = ''; + this.code = ''; + this.timePassed = 0; + this.timeInterval = 0; + this.display_email_option = false; + }, + countdown() { + const vm = this; + + if (!vm.countDownActive) { + vm.countDownActive = true; + + setInterval(() => { + vm.timePassed += 1; + }, 1000); + } + }, + resendCode(delivery_method) { + const e164 = this.phone.replace(/\s/g, ''); + const vm = this; + + vm.errorMessage = ''; + + if (vm.validNumber) { + const verificationRequest = fetchData('/sms/request', 'POST', { + phone: e164, + delivery_method: delivery_method || 'sms' + }, {'X-CSRFToken': vm.csrf}); + + vm.errorMessage = ''; + + $.when(verificationRequest).then(response => { + // set the cooldown time to one minute + this.timePassed = 0; + this.timeInterval = 60; + this.countdown(); + this.display_email_option = response.allow_email; + }).catch((e) => { + vm.errorMessage = e.responseJSON.msg; + }); + } + }, + // REQUEST VERIFICATION + requestVerification(event) { + const e164 = this.phone.replace(/\s/g, ''); + const vm = this; + + if (vm.validNumber) { + const verificationRequest = fetchData('/sms/request', 'POST', { + phone: e164 + }, {'X-CSRFToken': vm.csrf}); + + vm.errorMessage = ''; + + $.when(verificationRequest).then(response => { + vm.validationStep = 'verifyNumber'; + this.timePassed = 0; + this.timeInterval = 60; + this.countdown(); + this.display_email_option = response.allow_email; + }).catch((e) => { + vm.errorMessage = e.responseJSON.msg; + }); + } + }, + isValidNumber(validation) { + console.log(validation); + this.validNumber = validation.isValid; + } + } +}); + +$(document).ready(function() { + $(document).on('keyup', 'input[name=telephone]', function(e) { + var number = $(this).val(); + + if (number[0] != '+') { + number = '+' + number; + $(this).val(number); + } + }); + + + $(document).on('click', '#verify_offline', function(e) { + $(this).remove(); + $('#verify_offline_target').css('display', 'block'); + }); +}); + +if (document.getElementById('gc-sms-modal')) { + + const app = new Vue({ + delimiters: [ '[[', ']]' ], + el: '#gc-sms-modal', + data: { } + }); +} \ No newline at end of file diff --git a/app/dashboard/templates/profiles/profile.html b/app/dashboard/templates/profiles/profile.html index 38123176b8c..ddba5142f04 100644 --- a/app/dashboard/templates/profiles/profile.html +++ b/app/dashboard/templates/profiles/profile.html @@ -115,6 +115,7 @@ + diff --git a/app/dashboard/templates/profiles/tab_trust.html b/app/dashboard/templates/profiles/tab_trust.html index 6205d7ebe96..f931ca0c33d 100644 --- a/app/dashboard/templates/profiles/tab_trust.html +++ b/app/dashboard/templates/profiles/tab_trust.html @@ -2,6 +2,9 @@ {% if not profile.is_org and is_my_profile %}
+
+ +

Trust Bonus

The higher the Trust Bonus of a user is, the more we can be confident that the user is real. Higher @@ -40,7 +43,7 @@
Active Now
{% if is_sms_verified %} Verified {% else %} - Verify + Verify {% endif %}
@@ -156,6 +159,4 @@
Coming Soon ™️
- - {% endif %} From fb665e5ea4c25e534749ce1429ae0f681e9fa048 Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Thu, 17 Sep 2020 14:42:45 -0400 Subject: [PATCH 3/5] Add link to refresh page after verification, so status can be seen on page --- app/assets/v2/js/pages/profile-trust.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/v2/js/pages/profile-trust.js b/app/assets/v2/js/pages/profile-trust.js index 0eb747952ba..6c3ed3f65ed 100644 --- a/app/assets/v2/js/pages/profile-trust.js +++ b/app/assets/v2/js/pages/profile-trust.js @@ -260,7 +260,7 @@ Vue.component('sms-verify-modal', { vm.verified = true; vm.validationStep = 'verifyNumber'; vm.showValidation = false; - _alert('You have been verified', 'success'); + _alert('You have been verified. Refresh Page.', 'success'); }).catch((e) => { vm.errorMessage = e.responseJSON.msg; }); From 4a0e4c09e518908828262204b729eac8b9924b49 Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Thu, 17 Sep 2020 14:51:11 -0400 Subject: [PATCH 4/5] Add TODO notes about refactoring SMS UI post grants round 7 --- app/assets/v2/js/cart.js | 2 ++ app/assets/v2/js/pages/profile-trust.js | 3 +++ app/grants/templates/grants/cart-vue.html | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/v2/js/cart.js b/app/assets/v2/js/cart.js index 116683a0b05..ec4e5203602 100644 --- a/app/assets/v2/js/cart.js +++ b/app/assets/v2/js/cart.js @@ -445,6 +445,8 @@ Vue.component('grants-cart', { }, methods: { + // TODO: SMS related methos and state should be removed and refactored into the component that + // should be shared between the cart and the Trust Bonus tab dismissVerification() { localStorage.setItem('dismiss-sms-validation', true); this.showValidation = false; diff --git a/app/assets/v2/js/pages/profile-trust.js b/app/assets/v2/js/pages/profile-trust.js index 6c3ed3f65ed..4682cc07e0e 100644 --- a/app/assets/v2/js/pages/profile-trust.js +++ b/app/assets/v2/js/pages/profile-trust.js @@ -140,6 +140,9 @@ let show_brightid_verify_modal = function(brightid_uuid) { $('#verify_brightid_modal').bootstrapModal('show'); }; +// TODO: This component consists primarily of code taken from the SMS verification flow in the cart. +// This approach is not DRY, and after Grants Round 7 completes, the cart should be refactored to include +// this as a shared component, rather than duplicating the code. Vue.component('sms-verify-modal', { delimiters: [ '[[', ']]' ], data: function() { diff --git a/app/grants/templates/grants/cart-vue.html b/app/grants/templates/grants/cart-vue.html index 922df61428f..83ab9a58966 100644 --- a/app/grants/templates/grants/cart-vue.html +++ b/app/grants/templates/grants/cart-vue.html @@ -448,8 +448,12 @@