Browse Source

Made user email case insensitive

development
Godwin 8 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. 222
      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)
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
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
# the email address
if params[:token]
user = User.find_by_email(params[:email])
user = User.find_user(params[:email])
confirm(user)
return
end
user = User.find_by_email(params[:email])
unless user.present?
user = User.create(:email => params[:email], locale: I18n.locale)
end
user = User.get(params[:email])
# generate the confirmation, send the email and show the 403
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.each do | companion |
user = User.find_by_email(companion)
user = User.find_user(companion)
if user.present?
reg = ConferenceRegistration.find_by(
:user_id => user.id,
:conference_id => @this_conference.id
user_id: user.id,
conference_id: @this_conference.id
)
if reg.present? && @guests[reg.id].present?
housing_data = reg.housing_data || {}
@ -846,7 +846,7 @@ class ConferenceAdministrationController < ApplicationController
if params[:button] == 'save'
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.save!
registration = ConferenceRegistration.new(

2
app/controllers/conferences_controller.rb

@ -172,7 +172,7 @@ class ConferencesController < ApplicationController
}
when :questions
# 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.arrival = params[:arrival]

7
app/controllers/oauths_controller.rb

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

4
app/controllers/workshops_controller.rb

@ -297,11 +297,11 @@ class WorkshopsController < ApplicationController
set_conference
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
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))
end

2
app/helpers/application_helper.rb

@ -1799,7 +1799,7 @@ module ApplicationHelper
def companion(registration)
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?
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|
user.locale ||= I18n.locale
user.email.downcase!
end
before_save do |user|
user.locale ||= I18n.locale
user.email.downcase!
end
def can_translate?(to_locale = nil, from_locale = nil)
@ -50,11 +52,10 @@ class User < ActiveRecord::Base
end
def self.get(email)
user = where(email: email).first
user = find_user(email)
unless user
user = new(email: email)
user.save!
user = create(email: email, locale: I18n.locale)
end
return user

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

@ -11,7 +11,7 @@
%h3=_'articles.user_settings.headings.Your_Conferences'
.link-dump
- @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
= textfield :name, current_user.name, required: true, heading: 'articles.conference_registration.headings.name', big: true

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

@ -6,117 +6,117 @@
= 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}
%article.row
.columns.large-10
%h2=_'conference.registrations.title','Registrations'
%table.registrations
%tr
%th='Email'
%th='First Name'
%th='Last Name'
%th='Preferred Name'
%th='Confirmed?'
%th='Completed?'
%th='Paid?'
%th='Housing'
%th='Bike'
- @registrations.each do |registration|
%tr
- data = YAML.load(registration.data)
- user = User.find_by(:email => registration.email)
- stats[:total] += 1
- stats[:confirmed] += (registration.is_confirmed ? 1 : 0)
- stats[:completed] += (registration.completed ? 1 : 0)
- stats[:paid] += (registration.registration_fees_paid ? 1 : 0)
- stats[:collected] += (registration.registration_fees_paid || 0)
- stats[:housing_total] += (data[:questions][:housing] == 'none' ? 0 : 1)
- stats[:housing_beds] += (data[:questions][:housing] == 'bed' ? 1 : 0)
- stats[:housing_couches] += (data[:questions][:housing] == 'couch' ? 1 : 0)
- stats[:housing_campers] += (data[:questions][:housing] == 'camp' ? 1 : 0)
- stats[:bikes] += (data[:questions][:housing] == 'no' ? 0 : 1)
- stats[:small_bikes] += (data[:questions][:housing] == 'small' ? 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)
%td.user{rowspan: (rows > 1 ? rows : nil), id: user ? "user-#{user.id}" : nil}=registration.email
%td=data[:user][:firstname]
%td=data[:user][:lastname]
%td=data[:user][:username]
%td=registration.is_confirmed ? 'Yes' : 'No'
%td=registration.completed ? 'Yes' : 'No'
%td=registration.registration_fees_paid.nil? ? 'No' : 'Yes'
%td=data[:questions][:housing]
%td=data[:questions][:loaner_bike]
- if user.present?
%tr
%th='Organizations'
%td{colspan: 3}
- UserOrganizationRelationship.where(:user_id => user.id).each do |rel|
- org = Organization.find(rel.organization_id)
- location_name = "#{org.locations[0].city}, #{org.locations[0].territory}"
= link_to "#{org.name} (#{location_name})", org
%th='Workshops'
%td{colspan: 3}
- 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
- if data[:questions][:housing_extra].present?
%tr
%th='Housing Notes'
%td{colspan: 7}=data[:questions][:housing_extra]
- if data[:questions][:other].present?
%tr
%th='Other Notes'
%td{colspan: 7}=data[:questions][:other]
.columns.large-10
%h2=_'conference.registrations.title','Registrations'
%table.registrations
%tr
%th='Email'
%th='First Name'
%th='Last Name'
%th='Preferred Name'
%th='Confirmed?'
%th='Completed?'
%th='Paid?'
%th='Housing'
%th='Bike'
- @registrations.each do |registration|
%tr
- data = YAML.load(registration.data)
- user = User.find_user(registration.email)
- stats[:total] += 1
- stats[:confirmed] += (registration.is_confirmed ? 1 : 0)
- stats[:completed] += (registration.completed ? 1 : 0)
- stats[:paid] += (registration.registration_fees_paid ? 1 : 0)
- stats[:collected] += (registration.registration_fees_paid || 0)
- stats[:housing_total] += (data[:questions][:housing] == 'none' ? 0 : 1)
- stats[:housing_beds] += (data[:questions][:housing] == 'bed' ? 1 : 0)
- stats[:housing_couches] += (data[:questions][:housing] == 'couch' ? 1 : 0)
- stats[:housing_campers] += (data[:questions][:housing] == 'camp' ? 1 : 0)
- stats[:bikes] += (data[:questions][:housing] == 'no' ? 0 : 1)
- stats[:small_bikes] += (data[:questions][:housing] == 'small' ? 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)
%td.user{rowspan: (rows > 1 ? rows : nil), id: user ? "user-#{user.id}" : nil}=registration.email
%td=data[:user][:firstname]
%td=data[:user][:lastname]
%td=data[:user][:username]
%td=registration.is_confirmed ? 'Yes' : 'No'
%td=registration.completed ? 'Yes' : 'No'
%td=registration.registration_fees_paid.nil? ? 'No' : 'Yes'
%td=data[:questions][:housing]
%td=data[:questions][:loaner_bike]
- if user.present?
%tr
%th='Organizations'
%td{colspan: 3}
- UserOrganizationRelationship.where(:user_id => user.id).each do |rel|
- org = Organization.find(rel.organization_id)
- location_name = "#{org.locations[0].city}, #{org.locations[0].territory}"
= link_to "#{org.name} (#{location_name})", org
%th='Workshops'
%td{colspan: 3}
- 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
- if data[:questions][:housing_extra].present?
%tr
%th='Housing Notes'
%td{colspan: 7}=data[:questions][:housing_extra]
- if data[:questions][:other].present?
%tr
%th='Other Notes'
%td{colspan: 7}=data[:questions][:other]
%h3=_'conference.registrations.workshops.title','Workshops'
%ul
- Workshop.where(:conference_id => @conference.id).each do |workshop|
%li.workshop{id: "workshop-#{workshop.slug}"}
.columns
%h4=workshop.title
.columns.medium-10.medium-offset-1.end
= workshop.info.html_safe
.columns.medium-8.medium-offset-2.end
%h5='Facilitators'
- workshop.workshop_facilitators.each do |facilitator|
- user = User.find(facilitator.user_id)
%div
%a{href: "#user-#{user.id}"}="#{user.username} (#{user.email})"
%h3=_'conference.registrations.workshops.title','Workshops'
%ul
- Workshop.where(:conference_id => @conference.id).each do |workshop|
%li.workshop{id: "workshop-#{workshop.slug}"}
.columns
%h4=workshop.title
.columns.medium-10.medium-offset-1.end
= workshop.info.html_safe
.columns.medium-8.medium-offset-2.end
%h5='Facilitators'
- workshop.workshop_facilitators.each do |facilitator|
- user = User.find(facilitator.user_id)
%div
%a{href: "#user-#{user.id}"}="#{user.username} (#{user.email})"
- content_for :side_bar do
%h5='Stats'
%table
%tr
%th='Confirmed Registrations:'
%td=stats[:confirmed]
%tr
%th='Unconfirmed Registrations:'
%td=(stats[:total] - stats[:confirmed])
%tr
%th='Completed Registrations:'
%td=stats[:completed]
%tr
%th='Incomplete Registrations:'
%td=(stats[:total] - stats[:completed])
%tr
%th='Fees Collected:'
%td=number_to_currency(stats[:collected], :unit => '$')
%tr
%th='Housing Total:'
%td=stats[:housing_total]
%tr
%th='Beds:'
%td=stats[:housing_beds]
%tr
%th='Couch / Floorspace:'
%td=stats[:housing_couches]
%tr
%th='Campers:'
%td=stats[:housing_campers]
%tr
%th='Bikes Required:'
%td=stats[:bikes]
%tr
%th='Small Bikes:'
%td=stats[:small_bikes]
%tr
%th='Large Bikes:'
%td=stats[:large_bikes]
%h5='Stats'
%table
%tr
%th='Confirmed Registrations:'
%td=stats[:confirmed]
%tr
%th='Unconfirmed Registrations:'
%td=(stats[:total] - stats[:confirmed])
%tr
%th='Completed Registrations:'
%td=stats[:completed]
%tr
%th='Incomplete Registrations:'
%td=(stats[:total] - stats[:completed])
%tr
%th='Fees Collected:'
%td=number_to_currency(stats[:collected], :unit => '$')
%tr
%th='Housing Total:'
%td=stats[:housing_total]
%tr
%th='Beds:'
%td=stats[:housing_beds]
%tr
%th='Couch / Floorspace:'
%td=stats[:housing_couches]
%tr
%th='Campers:'
%td=stats[:housing_campers]
%tr
%th='Bikes Required:'
%td=stats[:bikes]
%tr
%th='Small Bikes:'
%td=stats[:small_bikes]
%tr
%th='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
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
visit "/confirm/#{@confirmation.token}"
end
@ -458,7 +458,7 @@ Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)
end
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)
end
@ -481,7 +481,7 @@ Then (/^I am( not)? a member of (.+)$/) do |state, org_name|
end
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(state =~ / not/ ? 'should_not' : 'should', eq(value))
end

Loading…
Cancel
Save