diff --git a/Gemfile b/Gemfile index 821e04512..67813dfd3 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,7 @@ gem 'bootsnap', '>= 1.1.0', require: false # Authentication gem 'devise', '~> 4.7' -gem 'omniauth-mlh', '~> 0.1' +gem 'omniauth-mlh', '~> 0.4.1' gem 'doorkeeper', '~> 5.0' gem 'devise-doorkeeper' gem 'omniauth-rails_csrf_protection' diff --git a/Gemfile.lock b/Gemfile.lock index 41447e43d..39b4a7e2b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -233,7 +233,7 @@ GEM minitest (>= 5.0) ruby-progressbar msgpack (1.3.3) - multi_json (1.14.1) + multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) mustache (1.1.1) @@ -254,7 +254,7 @@ GEM omniauth (1.9.1) hashie (>= 3.4.6) rack (>= 1.6.2, < 3) - omniauth-mlh (0.3.1) + omniauth-mlh (0.4.1) activesupport omniauth (~> 1.0) omniauth-oauth2 (~> 1.3.1) @@ -466,7 +466,7 @@ DEPENDENCIES minitest-reporters mustache (~> 1.0) mysql2 (>= 0.4.4, < 0.6.0) - omniauth-mlh (~> 0.1) + omniauth-mlh (~> 0.4.1) omniauth-rails_csrf_protection puma (~> 4.3) rails (~> 5.2.4.3) diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index b1e592452..e04bfb962 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -34,9 +34,6 @@ def new q.level_of_study = session["devise.provider_data"]["info"]["level_of_study"] q.major = session["devise.provider_data"]["info"]["major"] q.date_of_birth = session["devise.provider_data"]["info"]["date_of_birth"] - q.shirt_size = session["devise.provider_data"]["info"]["shirt_size"] - q.dietary_restrictions = session["devise.provider_data"]["info"]["dietary_restrictions"] - q.special_needs = session["devise.provider_data"]["info"]["special_needs"] q.gender = session["devise.provider_data"]["info"]["gender"] school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s| diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index bdc1eaf7c..51d7ecf9b 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -4,7 +4,7 @@ def mlh if @user.persisted? sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated session["devise.provider_data"] = request.env["omniauth.auth"] - set_flash_message(:notice, :success, kind: "My MLH") if is_navigational_format? + set_flash_message(:notice, :success, kind: "MyMLH") if is_navigational_format? else redirect_to new_user_registration_url end diff --git a/app/models/user.rb b/app/models/user.rb index 378df208d..939537de6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,11 +65,18 @@ def full_name def self.from_omniauth(auth) matching_provider = where(provider: auth.provider, uid: auth.uid) matching_email = where(email: auth.info.email) - matching_provider.or(matching_email).first_or_create do |user| + current_user = matching_provider.or(matching_email).first_or_create do |user| user.uid = auth.uid + user.provider = auth.provider user.email = auth.info.email user.password = Devise.friendly_token[0, 20] end + # Autofill MyMLH provider if provider info is missing + # (as we are executing this from OAuth) + if current_user.provider.blank? + current_user.provider = auth.provider + end + current_user end def self.non_admins diff --git a/app/views/application/_questionnaire_summary.html.haml b/app/views/application/_questionnaire_summary.html.haml index d4a55a5c8..5ebb7a008 100644 --- a/app/views/application/_questionnaire_summary.html.haml +++ b/app/views/application/_questionnaire_summary.html.haml @@ -17,10 +17,19 @@ %p %b Traveling from: = @questionnaire.travel_not_from_school ? "Somewhere else (#{@questionnaire.travel_location})" : "My school (#{@questionnaire.school.full_name})" +%p + %b Shirt size: + = @questionnaire.shirt_size +%p + %b Dietary restrictions + = @questionnaire.dietary_restrictions || "(none)".html_safe +%p + %b Special needs + = @questionnaire.special_needs || "(none)".html_safe %fieldset - if @questionnaire.user.provider == 'mlh' - %legend Provided by My MLH + %legend Provided by MyMLH %p %b First name: = @questionnaire.first_name @@ -48,12 +57,3 @@ %p %b Level of study: = @questionnaire.level_of_study - %p - %b Shirt size: - = @questionnaire.shirt_size - %p - %b Dietary restrictions - = @questionnaire.dietary_restrictions || "(none)".html_safe - %p - %b Special needs - = @questionnaire.special_needs || "(none)".html_safe diff --git a/app/views/manage/questionnaires/_overview.html.haml b/app/views/manage/questionnaires/_overview.html.haml index 09642fcd1..09e21b4ad 100644 --- a/app/views/manage/questionnaires/_overview.html.haml +++ b/app/views/manage/questionnaires/_overview.html.haml @@ -23,8 +23,6 @@ = @questionnaire.age_at_time_of_event / 1.year %dt.col-md-4 Gender %dd.col-md-8= @questionnaire.gender - %dt.col-md-4 Shirt size - %dd.col-md-8= @questionnaire.shirt_size = render 'checkin_compliance_card' @@ -33,6 +31,8 @@ .card-header Special notices .card-body .row + %dt.col-md-4 Shirt size + %dd.col-md-8= @questionnaire.shirt_size %dt.col-md-4 Dietary restrictions %dd.col-md-8 - if @questionnaire.dietary_restrictions.present? diff --git a/app/views/questionnaires/_form.html.haml b/app/views/questionnaires/_form.html.haml index fefc59e30..789caca6a 100644 --- a/app/views/questionnaires/_form.html.haml +++ b/app/views/questionnaires/_form.html.haml @@ -19,10 +19,6 @@ = f.input :level_of_study, collection: collection_or_text(@questionnaire.level_of_study, Questionnaire::POSSIBLE_LEVELS_OF_STUDY), include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } = f.input :major, input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } = f.input :gender, collection: collection_or_text(@questionnaire.gender, Questionnaire::POSSIBLE_GENDERS), include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } - = f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } - = f.input :dietary_restrictions, as: :text, label: "Health restrictions", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH - = f.input :special_needs, as: :text, label: "Special needs", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH - .right %button.button{ type: "button", "data-wizard" => "next" } Next @@ -46,6 +42,10 @@ = f.input :travel_not_from_school, as: :radio_buttons, collection: { " My school" => false, " Somewhere else" => true }, label: "I am traveling from..." = f.input :travel_location, input_html: { "data-validate" => "presence", disabled: !travel_state }, wrapper_html: { style: travel_state ? "" : "display: none" }, label: "Where are you traveling from?", placeholder: "New York City" + = f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" } + = f.input :dietary_restrictions, as: :text, label: "Health restrictions", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH + = f.input :special_needs, as: :text, label: "Special needs", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH + %hr .form-inputs