diff --git a/app/assets/stylesheets/forms.css.scss b/app/assets/stylesheets/forms.css.scss index 1775d75f..ae801b94 100644 --- a/app/assets/stylesheets/forms.css.scss +++ b/app/assets/stylesheets/forms.css.scss @@ -9,6 +9,13 @@ @extend %textOverflowEllipsis; } +.email_valid { + background-color: lighten($c-green, 30%); +} +.email_invalid { + background-color: lighten($c-red, 30%); +} + .menu-heading { height: 79px; margin: 28px 0 56px 0; diff --git a/app/controllers/persons_controller.rb b/app/controllers/persons_controller.rb index d4dd2df2..a1639730 100644 --- a/app/controllers/persons_controller.rb +++ b/app/controllers/persons_controller.rb @@ -3,4 +3,8 @@ class PersonsController < ApplicationController def export end + + def verify_email + render :json => { verified: Person.email_registered?(params[:email]) } + end end diff --git a/app/views/camps/_person_fields.haml b/app/views/camps/_person_fields.haml index 50017f07..d1f070f9 100644 --- a/app/views/camps/_person_fields.haml +++ b/app/views/camps/_person_fields.haml @@ -1,3 +1,32 @@ +:javascript + + function verify_person_email(event) { + const email_field = event.target; + if (email_field.value != '') { + verify_email(email_field.value, function (valid) { + console.log(`email is valid: ${valid}`); + if (!valid) { + email_field.classList.remove("email_valid"); + email_field.classList.add("email_invalid"); + } else { + email_field.classList.remove("email_invalid"); + email_field.classList.add("email_valid"); + } + }); + } + } + + function verify_email(email, callback) { + var request = new XMLHttpRequest(); + request.open("POST", '/verify_email', true); + request.setRequestHeader('Content-Type', 'application/json'); + request.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); + request.onload = function() { + callback(JSON.parse(request.response)['verified']); + }; + request.send(JSON.stringify({ "email": email })); + } + - dream_admin ||= false .nested-fields.panel.panel-default.col-md-7{ style: 'float:' + I18n.t('lang_direction')} @@ -13,7 +42,7 @@ = f.text_field :name, class: 'form-control', readonly: true = f.label :email - if (@can_edit) - = f.text_field :email, class: 'form-control' + = f.text_field :email, class: 'form-control person_email', onfocusout: 'verify_person_email(event)' - else = f.text_field :email, class: 'form-control', readonly: true = f.label :phone_number diff --git a/config/locales/en.yml b/config/locales/en.yml index ca5f99d4..19c5b23d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -590,7 +590,7 @@ en: modified_at: Modified at new_dream_is_disabled: Creating new dreams is disabled at the moment. If you think this is a mistake please contact bureau of dreams - email_not_in_spark: This email is not registered in Spark + email_not_in_spark: Sorry, but we couldn't find a Midburn profile associated with dont_miss_out: banner: Don't miss out! Only %{time} left to %{action} actions: diff --git a/config/locales/he.yml b/config/locales/he.yml index 993027ed..5ce33e79 100755 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -564,7 +564,7 @@ he: # Errors new_dream_is_disabled: "יצירת חלומות חדשים מנוטרלת כרגע. אם אתה חושב שזאת שגיאה אנא צור קשר עם לשכת החלומות" - email_not_in_spark: "האימייל לא רשום בספארק:" + email_not_in_spark: "אופס! לא מצאנו פרופיל מידברן מקושר למייל: " time: am: am diff --git a/config/routes.rb b/config/routes.rb index a27e7027..cb48f58b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,8 @@ get '/howcanihelp' => 'howcanihelp#index' get '/people/export' => 'people#export_csv' + + post '/verify_email' => 'persons#verify_email' get '*unmatched_route' => 'application#not_found' end diff --git a/spec/controllers/camps_controller_spec.rb b/spec/controllers/camps_controller_spec.rb index aa0cbb0b..8fe4ed41 100644 --- a/spec/controllers/camps_controller_spec.rb +++ b/spec/controllers/camps_controller_spec.rb @@ -27,7 +27,7 @@ recycling: 'recycling plan', budgetplan: 'budgetplan plan', cocreation: 'cocreation plan', - people_attributes: {'0' => {name: Faker::Name.name}} + people_attributes: {'0' => {name: Faker::Name.name, email: Faker::Internet.email}} } }