Browse Source

Made user email case insensitive

development
Godwin 7 years ago
parent
commit
cb016915e4
  1. 10
      app/controllers/application_controller.rb
  2. 8
      app/controllers/conference_administration_controller.rb
  3. 2
      app/controllers/conferences_controller.rb
  4. 7
      app/controllers/oauths_controller.rb
  5. 4
      app/controllers/workshops_controller.rb
  6. 2
      app/helpers/application_helper.rb
  7. 7
      app/models/user.rb
  8. 2
      app/views/application/user_settings.html.haml
  9. 244
      app/views/conferences/registrations.html.haml
  10. 6
      features/step_definitions/interface_steps.rb

10
app/controllers/application_controller.rb

@ -248,7 +248,7 @@ class ApplicationController < LinguaFrancaApplicationController
def generate_confirmation(user, url, expiry = nil) def generate_confirmation(user, url, expiry = nil)
if user.is_a? String if user.is_a? String
user = User.find_by_email(user) user = User.find_user(user)
# if the user doesn't exist, just show them a 403 # if the user doesn't exist, just show them a 403
do_403 unless user.present? do_403 unless user.present?
@ -338,15 +338,11 @@ class ApplicationController < LinguaFrancaApplicationController
# see if we've already sent the confirmation email and are just confirming # see if we've already sent the confirmation email and are just confirming
# the email address # the email address
if params[:token] if params[:token]
user = User.find_by_email(params[:email]) user = User.find_user(params[:email])
confirm(user) confirm(user)
return return
end end
user = User.find_by_email(params[:email]) user = User.get(params[:email])
unless user.present?
user = User.create(:email => params[:email], locale: I18n.locale)
end
# generate the confirmation, send the email and show the 403 # generate the confirmation, send the email and show the 403
referrer = params[:dest] || (request.present? && request.referer.present? ? request.referer.gsub(/^.*?\/\/.*?\//, '/') : settings_path) referrer = params[:dest] || (request.present? && request.referer.present? ? request.referer.gsub(/^.*?\/\/.*?\//, '/') : settings_path)

8
app/controllers/conference_administration_controller.rb

@ -631,11 +631,11 @@ class ConferenceAdministrationController < ApplicationController
companions = data['companions'] || [] companions = data['companions'] || []
companions.each do | companion | companions.each do | companion |
user = User.find_by_email(companion) user = User.find_user(companion)
if user.present? if user.present?
reg = ConferenceRegistration.find_by( reg = ConferenceRegistration.find_by(
:user_id => user.id, user_id: user.id,
:conference_id => @this_conference.id conference_id: @this_conference.id
) )
if reg.present? && @guests[reg.id].present? if reg.present? && @guests[reg.id].present?
housing_data = reg.housing_data || {} housing_data = reg.housing_data || {}
@ -846,7 +846,7 @@ class ConferenceAdministrationController < ApplicationController
if params[:button] == 'save' if params[:button] == 'save'
return do_404 unless params[:email].present? && params[:name].present? return do_404 unless params[:email].present? && params[:name].present?
user = User.find_by_email(params[:email]) || User.create(email: params[:email]) user = User.get(params[:email])
user.firstname = params[:name] user.firstname = params[:name]
user.save! user.save!
registration = ConferenceRegistration.new( registration = ConferenceRegistration.new(

2
app/controllers/conferences_controller.rb

@ -172,7 +172,7 @@ class ConferencesController < ApplicationController
} }
when :questions when :questions
# create the companion's user account and send a registration link unless they have already registered # create the companion's user account and send a registration link unless they have already registered
generate_confirmation(User.create(email: params[:companion]), register_path(@this_conference.slug)) if params[:companion].present? && User.find_by_email(params[:companion]).nil? generate_confirmation(User.create(email: params[:companion]), register_path(@this_conference.slug)) if params[:companion].present? && User.find_user(params[:companion]).nil?
@registration.housing = params[:housing] @registration.housing = params[:housing]
@registration.arrival = params[:arrival] @registration.arrival = params[:arrival]

7
app/controllers/oauths_controller.rb

@ -23,14 +23,13 @@ class OauthsController < ApplicationController
# otherwise find the user by email # otherwise find the user by email
unless user.present? unless user.present?
# only look if the email address is present # only look if the email address is present
user = User.find_by_email(email) if email.present? user = User.find_user(email) if email.present?
end end
# create the user if the email is not recognized # create the user if the email is not recognized
if user.nil? if user.nil?
if email.present? if email.present?
user = User.new(email: email, firstname: user_info['name'], fb_id: fb_id) user = User.create(email: email, firstname: user_info['name'], fb_id: fb_id, locale: I18n.locale)
user.save!
else else
session[:oauth_update_user_info] = user_info session[:oauth_update_user_info] = user_info
return redirect_to oauth_update_path return redirect_to oauth_update_path
@ -62,7 +61,7 @@ class OauthsController < ApplicationController
return redirect_to oauth_update_path return redirect_to oauth_update_path
end end
user = User.find_by_email(params[:email]) user = User.find_user(params[:email])
if user.present? if user.present?
flash[:error] = :exists flash[:error] = :exists

4
app/controllers/workshops_controller.rb

@ -297,11 +297,11 @@ class WorkshopsController < ApplicationController
set_conference set_conference
set_conference_registration! set_conference_registration!
user = User.find_by_email(params[:email]) user = User.find_user(params[:email])
# create the user if they don't exist and send them a link to register # create the user if they don't exist and send them a link to register
unless user unless user
user = User.create(email: params[:email]) user = User.create(email: params[:email], locale: I18n.locale)
generate_confirmation(user, register_path(@this_conference.slug)) generate_confirmation(user, register_path(@this_conference.slug))
end end

2
app/helpers/application_helper.rb

@ -1799,7 +1799,7 @@ module ApplicationHelper
def companion(registration) def companion(registration)
if registration.housing_data.present? && registration.housing_data['companions'].present? && registration.housing_data['companions'].first.present? if registration.housing_data.present? && registration.housing_data['companions'].present? && registration.housing_data['companions'].first.present?
companion_user = User.find_by_email(registration.housing_data['companions'].first) companion_user = User.find_user(registration.housing_data['companions'].first)
if companion_user.present? if companion_user.present?
cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first

7
app/models/user.rb

@ -15,10 +15,12 @@ class User < ActiveRecord::Base
before_update do |user| before_update do |user|
user.locale ||= I18n.locale user.locale ||= I18n.locale
user.email.downcase!
end end
before_save do |user| before_save do |user|
user.locale ||= I18n.locale user.locale ||= I18n.locale
user.email.downcase!
end end
def can_translate?(to_locale = nil, from_locale = nil) def can_translate?(to_locale = nil, from_locale = nil)
@ -50,11 +52,10 @@ class User < ActiveRecord::Base
end end
def self.get(email) def self.get(email)
user = where(email: email).first user = find_user(email)
unless user unless user
user = new(email: email) user = create(email: email, locale: I18n.locale)
user.save!
end end
return user return user

2
app/views/application/user_settings.html.haml

@ -11,7 +11,7 @@
%h3=_'articles.user_settings.headings.Your_Conferences' %h3=_'articles.user_settings.headings.Your_Conferences'
.link-dump .link-dump
- @conferences.each do | conference | - @conferences.each do | conference |
= link_to (_!conference.title), administration_step_path(conference.slug, :edit), class: :button = link_to (_!conference.title), administrate_conference_path(conference.slug), class: :button
= form_tag update_settings_path do = form_tag update_settings_path do
= textfield :name, current_user.name, required: true, heading: 'articles.conference_registration.headings.name', big: true = textfield :name, current_user.name, required: true, heading: 'articles.conference_registration.headings.name', big: true

244
app/views/conferences/registrations.html.haml

@ -1,122 +1,122 @@
- location = @conference.organizations.first.locations.first - location = @conference.organizations.first.locations.first
- location_name = location.city + ', ' + (location.territory ? Carmen::Country.coded(location.country).subregions.coded(location.territory).name : location.country) - location_name = location.city + ', ' + (location.territory ? Carmen::Country.coded(location.country).subregions.coded(location.territory).name : location.country)
- title @conference.title - title @conference.title
- description "#{@conference.title} conference in #{location_name} for DIY bicycle collectives, co-ops, and advocacy groups" - description "#{@conference.title} conference in #{location_name} for DIY bicycle collectives, co-ops, and advocacy groups"
= render 'header' = render 'header'
- stats = {confirmed: 0, completed: 0, total: 0, paid: 0, collected: 0, housing_total: 0, housing_beds: 0, housing_couches: 0, housing_campers: 0, bikes: 0, small_bikes: 0, large_bikes: 0} - stats = {confirmed: 0, completed: 0, total: 0, paid: 0, collected: 0, housing_total: 0, housing_beds: 0, housing_couches: 0, housing_campers: 0, bikes: 0, small_bikes: 0, large_bikes: 0}
%article.row %article.row
.columns.large-10 .columns.large-10
%h2=_'conference.registrations.title','Registrations' %h2=_'conference.registrations.title','Registrations'
%table.registrations %table.registrations
%tr %tr
%th='Email' %th='Email'
%th='First Name' %th='First Name'
%th='Last Name' %th='Last Name'
%th='Preferred Name' %th='Preferred Name'
%th='Confirmed?' %th='Confirmed?'
%th='Completed?' %th='Completed?'
%th='Paid?' %th='Paid?'
%th='Housing' %th='Housing'
%th='Bike' %th='Bike'
- @registrations.each do |registration| - @registrations.each do |registration|
%tr %tr
- data = YAML.load(registration.data) - data = YAML.load(registration.data)
- user = User.find_by(:email => registration.email) - user = User.find_user(registration.email)
- stats[:total] += 1 - stats[:total] += 1
- stats[:confirmed] += (registration.is_confirmed ? 1 : 0) - stats[:confirmed] += (registration.is_confirmed ? 1 : 0)
- stats[:completed] += (registration.completed ? 1 : 0) - stats[:completed] += (registration.completed ? 1 : 0)
- stats[:paid] += (registration.registration_fees_paid ? 1 : 0) - stats[:paid] += (registration.registration_fees_paid ? 1 : 0)
- stats[:collected] += (registration.registration_fees_paid || 0) - stats[:collected] += (registration.registration_fees_paid || 0)
- stats[:housing_total] += (data[:questions][:housing] == 'none' ? 0 : 1) - stats[:housing_total] += (data[:questions][:housing] == 'none' ? 0 : 1)
- stats[:housing_beds] += (data[:questions][:housing] == 'bed' ? 1 : 0) - stats[:housing_beds] += (data[:questions][:housing] == 'bed' ? 1 : 0)
- stats[:housing_couches] += (data[:questions][:housing] == 'couch' ? 1 : 0) - stats[:housing_couches] += (data[:questions][:housing] == 'couch' ? 1 : 0)
- stats[:housing_campers] += (data[:questions][:housing] == 'camp' ? 1 : 0) - stats[:housing_campers] += (data[:questions][:housing] == 'camp' ? 1 : 0)
- stats[:bikes] += (data[:questions][:housing] == 'no' ? 0 : 1) - stats[:bikes] += (data[:questions][:housing] == 'no' ? 0 : 1)
- stats[:small_bikes] += (data[:questions][:housing] == 'small' ? 1 : 0) - stats[:small_bikes] += (data[:questions][:housing] == 'small' ? 1 : 0)
- stats[:large_bikes] += (data[:questions][:housing] == 'large' ? 1 : 0) - stats[:large_bikes] += (data[:questions][:housing] == 'large' ? 1 : 0)
- rows = 1 + (user.present? ? 1 : 0) + (data[:questions][:housing_extra].present? ? 1 :0) + (data[:questions][:other].present? ? 1 :0) - rows = 1 + (user.present? ? 1 : 0) + (data[:questions][:housing_extra].present? ? 1 :0) + (data[:questions][:other].present? ? 1 :0)
%td.user{rowspan: (rows > 1 ? rows : nil), id: user ? "user-#{user.id}" : nil}=registration.email %td.user{rowspan: (rows > 1 ? rows : nil), id: user ? "user-#{user.id}" : nil}=registration.email
%td=data[:user][:firstname] %td=data[:user][:firstname]
%td=data[:user][:lastname] %td=data[:user][:lastname]
%td=data[:user][:username] %td=data[:user][:username]
%td=registration.is_confirmed ? 'Yes' : 'No' %td=registration.is_confirmed ? 'Yes' : 'No'
%td=registration.completed ? 'Yes' : 'No' %td=registration.completed ? 'Yes' : 'No'
%td=registration.registration_fees_paid.nil? ? 'No' : 'Yes' %td=registration.registration_fees_paid.nil? ? 'No' : 'Yes'
%td=data[:questions][:housing] %td=data[:questions][:housing]
%td=data[:questions][:loaner_bike] %td=data[:questions][:loaner_bike]
- if user.present? - if user.present?
%tr %tr
%th='Organizations' %th='Organizations'
%td{colspan: 3} %td{colspan: 3}
- UserOrganizationRelationship.where(:user_id => user.id).each do |rel| - UserOrganizationRelationship.where(:user_id => user.id).each do |rel|
- org = Organization.find(rel.organization_id) - org = Organization.find(rel.organization_id)
- location_name = "#{org.locations[0].city}, #{org.locations[0].territory}" - location_name = "#{org.locations[0].city}, #{org.locations[0].territory}"
= link_to "#{org.name} (#{location_name})", org = link_to "#{org.name} (#{location_name})", org
%th='Workshops' %th='Workshops'
%td{colspan: 3} %td{colspan: 3}
- Workshop.where('workshop_facilitators.user_id' => user.id, :conference_id => @conference.id).joins(:workshop_facilitators).each do | workshop | - Workshop.where('workshop_facilitators.user_id' => user.id, :conference_id => @conference.id).joins(:workshop_facilitators).each do | workshop |
%a{href: "#workshop-#{workshop.slug}"}= workshop.title %a{href: "#workshop-#{workshop.slug}"}= workshop.title
- if data[:questions][:housing_extra].present? - if data[:questions][:housing_extra].present?
%tr %tr
%th='Housing Notes' %th='Housing Notes'
%td{colspan: 7}=data[:questions][:housing_extra] %td{colspan: 7}=data[:questions][:housing_extra]
- if data[:questions][:other].present? - if data[:questions][:other].present?
%tr %tr
%th='Other Notes' %th='Other Notes'
%td{colspan: 7}=data[:questions][:other] %td{colspan: 7}=data[:questions][:other]
%h3=_'conference.registrations.workshops.title','Workshops' %h3=_'conference.registrations.workshops.title','Workshops'
%ul %ul
- Workshop.where(:conference_id => @conference.id).each do |workshop| - Workshop.where(:conference_id => @conference.id).each do |workshop|
%li.workshop{id: "workshop-#{workshop.slug}"} %li.workshop{id: "workshop-#{workshop.slug}"}
.columns .columns
%h4=workshop.title %h4=workshop.title
.columns.medium-10.medium-offset-1.end .columns.medium-10.medium-offset-1.end
= workshop.info.html_safe = workshop.info.html_safe
.columns.medium-8.medium-offset-2.end .columns.medium-8.medium-offset-2.end
%h5='Facilitators' %h5='Facilitators'
- workshop.workshop_facilitators.each do |facilitator| - workshop.workshop_facilitators.each do |facilitator|
- user = User.find(facilitator.user_id) - user = User.find(facilitator.user_id)
%div %div
%a{href: "#user-#{user.id}"}="#{user.username} (#{user.email})" %a{href: "#user-#{user.id}"}="#{user.username} (#{user.email})"
- content_for :side_bar do - content_for :side_bar do
%h5='Stats' %h5='Stats'
%table %table
%tr %tr
%th='Confirmed Registrations:' %th='Confirmed Registrations:'
%td=stats[:confirmed] %td=stats[:confirmed]
%tr %tr
%th='Unconfirmed Registrations:' %th='Unconfirmed Registrations:'
%td=(stats[:total] - stats[:confirmed]) %td=(stats[:total] - stats[:confirmed])
%tr %tr
%th='Completed Registrations:' %th='Completed Registrations:'
%td=stats[:completed] %td=stats[:completed]
%tr %tr
%th='Incomplete Registrations:' %th='Incomplete Registrations:'
%td=(stats[:total] - stats[:completed]) %td=(stats[:total] - stats[:completed])
%tr %tr
%th='Fees Collected:' %th='Fees Collected:'
%td=number_to_currency(stats[:collected], :unit => '$') %td=number_to_currency(stats[:collected], :unit => '$')
%tr %tr
%th='Housing Total:' %th='Housing Total:'
%td=stats[:housing_total] %td=stats[:housing_total]
%tr %tr
%th='Beds:' %th='Beds:'
%td=stats[:housing_beds] %td=stats[:housing_beds]
%tr %tr
%th='Couch / Floorspace:' %th='Couch / Floorspace:'
%td=stats[:housing_couches] %td=stats[:housing_couches]
%tr %tr
%th='Campers:' %th='Campers:'
%td=stats[:housing_campers] %td=stats[:housing_campers]
%tr %tr
%th='Bikes Required:' %th='Bikes Required:'
%td=stats[:bikes] %td=stats[:bikes]
%tr %tr
%th='Small Bikes:' %th='Small Bikes:'
%td=stats[:small_bikes] %td=stats[:small_bikes]
%tr %tr
%th='Large Bikes:' %th='Large Bikes:'
%td=stats[:large_bikes] %td=stats[:large_bikes]

6
features/step_definitions/interface_steps.rb

@ -370,7 +370,7 @@ Then (/^in th(e|at) email I should see (.+)$/) do |a, value|
end end
Then(/^(I )?confirm my account$/) do | a | Then(/^(I )?confirm my account$/) do | a |
@my_account = User.find_by(:email => @last_email_entered) @my_account = User.find_user(@last_email_entered)
@confirmation = EmailConfirmation.where(["user_id = ?", @my_account.id]).order("created_at DESC").first @confirmation = EmailConfirmation.where(["user_id = ?", @my_account.id]).order("created_at DESC").first
visit "/confirm/#{@confirmation.token}" visit "/confirm/#{@confirmation.token}"
end end
@ -458,7 +458,7 @@ Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)
end end
Then (/^I am( not)? a user$/) do |state| Then (/^I am( not)? a user$/) do |state|
User.find_by(:email => @last_email_entered). User.find_user(@last_email_entered).
send(state =~ / not/ ? 'should_not' : 'should', be) send(state =~ / not/ ? 'should_not' : 'should', be)
end end
@ -481,7 +481,7 @@ Then (/^I am( not)? a member of (.+)$/) do |state, org_name|
end end
Then (/^My (.+) should(not )? be (.+)$/) do |field, state, value| Then (/^My (.+) should(not )? be (.+)$/) do |field, state, value|
User.find_by(:email => @last_email_entered). User.find_user(@last_email_entered).
send(field.gsub(/\s/, '_')). send(field.gsub(/\s/, '_')).
send(state =~ / not/ ? 'should_not' : 'should', eq(value)) send(state =~ / not/ ? 'should_not' : 'should', eq(value))
end end

Loading…
Cancel
Save