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. 2
      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

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

@ -22,7 +22,7 @@
- @registrations.each do |registration|
%tr
- data = YAML.load(registration.data)
- user = User.find_by(:email => registration.email)
- user = User.find_user(registration.email)
- stats[:total] += 1
- stats[:confirmed] += (registration.is_confirmed ? 1 : 0)
- stats[:completed] += (registration.completed ? 1 : 0)

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