Browse Source

Required that all accounts that can be used to log in have an email address

development
Godwin 8 years ago
parent
commit
08244444b0
  1. 4
      app/assets/stylesheets/bumbleberry-settings.json
  2. 72
      app/controllers/oauths_controller.rb
  3. 9
      app/views/application/update_user.html.haml
  4. 3
      config/locales/en.yml
  5. 6
      config/routes.rb
  6. 5
      db/migrate/20161006021205_add_fb_id_to_user.rb
  7. 5
      db/schema.rb

4
app/assets/stylesheets/bumbleberry-settings.json

@ -5,8 +5,8 @@
"chrome": ["51"] "chrome": ["51"]
}, },
"development": { "development": {
"and_chr": ["51"], "and_chr": ["53"],
"chrome": ["52"], "chrome": ["53"],
"edge": ["13"], "edge": ["13"],
"firefox": ["44"], "firefox": ["44"],
"ie": ["11"], "ie": ["11"],

72
app/controllers/oauths_controller.rb

@ -13,18 +13,76 @@ class OauthsController < ApplicationController
set_callback set_callback
user_info = (sorcery_fetch_user_hash auth_params[:provider] || {})[:user_info] user_info = (sorcery_fetch_user_hash auth_params[:provider] || {})[:user_info]
user = User.find_by_email(user_info['email'])
email = user_info['email']
fb_id = user_info['id']
# try to find the user by facebook id
user = User.find_by_fb_id(fb_id)
# 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?
end
# create the user if the email is not recognized # create the user if the email is not recognized
unless user if user.nil?
user = User.new(email: user_info['email'], firstname: user_info['name']) if email.present?
user = User.new(email: email, firstname: user_info['name'], fb_id: fb_id)
user.save!
else
session[:oauth_update_user_info] = user_info
return redirect_to oauth_update_path
end
elsif user.fb_id.blank? || user.email.blank?
user.email = email
user.fb_id = fb_id
user.save! user.save!
end end
# log in the user if user.present? && user.email.present?
auto_login(user) if user # log in the user
auto_login(user)
end
oauth_last_url = (session[:oauth_last_url] || home_path)
session.delete(:oauth_last_url)
redirect_to oauth_last_url
end
def update
@main_title = @page_title = 'articles.conference_registration.headings.email_confirm'
@errors = { email: flash[:error] } if flash[:error].present?
render 'application/update_user'
end
def save
unless params[:email].present?
return redirect_to oauth_update_path
end
user = User.find_by_email(params[:email])
if user.present?
flash[:error] = :exists
return redirect_to oauth_update_path
end
redirect_to (session[:oauth_last_url] || home_path) # create the user
user = User.new(email: params[:email], firstname: session[:oauth_update_user_info]['name'], fb_id: session[:oauth_update_user_info]['id'])
user.save!
# log in
auto_login(user)
# clear out the session
oauth_last_url = (session[:oauth_last_url] || home_path)
session.delete(:oauth_last_url)
session.delete(:oauth_update_user_info)
# go to our final destination
redirect_to oauth_last_url
end end
private private

9
app/views/application/update_user.html.haml

@ -0,0 +1,9 @@
= render :partial => 'application/header', :locals => {:image_file => 'grafitti.jpg'}
%article
= row do
= columns do
%h2=_'articles.conference_registration.headings.Enter_Your_Email'
%p=_'articles.conference_registration.paragraphs.provide_email', :p
= form_tag oauth_save_path, class: 'flex-form' do
= emailfield :email, nil, required: true, big: true
= button_tag :save, value: :save

3
config/locales/en.yml

@ -169,6 +169,8 @@ en:
empty: 'Please enter an address' empty: 'Please enter an address'
space: space:
empty: 'Please select a space' empty: 'Please select a space'
email:
exists: An account with this email address already exists
housing: housing:
space: space:
companions: This host wishes to be housed with %{name} companions: This host wishes to be housed with %{name}
@ -1026,6 +1028,7 @@ en:
info: Info info: Info
companion: Companion companion: Companion
paragraphs: paragraphs:
provide_email: Bike!Bike! uses email to communicate between you and your conference hosts, however your Facebook account does not provide us an email address. Before proceeding, you must provide us an email address.
Policy_Agreement: Ensuring that all attendees feel welcome, safe, and respected at all times is especially important to us all. Please ensure that you have fully read and understand our safer spaces policy below, if you have any questions or concerns you can reach out to the organizers at any time. Policy_Agreement: Ensuring that all attendees feel welcome, safe, and respected at all times is especially important to us all. Please ensure that you have fully read and understand our safer spaces policy below, if you have any questions or concerns you can reach out to the organizers at any time.
Confirm_Agreement: By clicking the "I Agree" button, you are pledging to do your best to uphold Bike!Bike!'s safer space agreement. Thank you! Confirm_Agreement: By clicking the "I Agree" button, you are pledging to do your best to uphold Bike!Bike!'s safer space agreement. Thank you!
Registration_Info: Please fill in this registration form to help us prepare for your arrival to %{city}. If you wish to ask questions or tell us information we did not ask, please fill in the preferences field at the bottom of the page or use the contact us link. Registration_Info: Please fill in this registration form to help us prepare for your arrival to %{city}. If you wish to ask questions or tell us information we did not ask, please fill in the preferences field at the bottom of the page or use the contact us link.

6
config/routes.rb

@ -47,7 +47,7 @@ BikeBike::Application.routes.draw do
get '/confirm/:token' => 'application#confirm', :as => :confirm get '/confirm/:token' => 'application#confirm', :as => :confirm
match '/doconfirm' => 'application#do_confirm', :as => :do_confirm, via: [:get, :post] match '/doconfirm' => 'application#do_confirm', :as => :do_confirm, via: [:get, :post]
#post '/doconfirm' => 'application#do_confirm', :as => :do_confirm
match '/user/logout' => 'application#user_logout', :as => :logout, :via => [:get, :post] match '/user/logout' => 'application#user_logout', :as => :logout, :via => [:get, :post]
get '/contact' => 'application#contact', :as => :contact get '/contact' => 'application#contact', :as => :contact
post '/contact/send' => 'application#contact_send', :as => :contact_send post '/contact/send' => 'application#contact_send', :as => :contact_send
@ -55,10 +55,10 @@ BikeBike::Application.routes.draw do
get '/user' => 'application#user_settings', :as => :settings get '/user' => 'application#user_settings', :as => :settings
post '/user/update' => 'application#update_user_settings', :as => :update_settings post '/user/update' => 'application#update_user_settings', :as => :update_settings
match '/oauth/callback' => 'oauths#callback', :via => [:get, :post] match '/oauth/callback' => 'oauths#callback', :via => [:get, :post]
get '/oauth/update' => 'oauths#update', :as => :oauth_update
post '/oauth/save' => 'oauths#save', :as => :oauth_save
get '/oauth/:provider' => 'oauths#oauth', :as => :auth_at_provider get '/oauth/:provider' => 'oauths#oauth', :as => :auth_at_provider
# post '/translator-request' => 'application#translator_request', :as => :translator_request
# patch '/capture_view' => 'application#capture_view'
post '/js_error' => 'application#js_error' post '/js_error' => 'application#js_error'
get '/error_403' => 'application#do_403' get '/error_403' => 'application#do_403'
get '/error_404' => 'application#error_404' get '/error_404' => 'application#error_404'

5
db/migrate/20161006021205_add_fb_id_to_user.rb

@ -0,0 +1,5 @@
class AddFbIdToUser < ActiveRecord::Migration
def change
add_column :users, :fb_id, :bigint
end
end

5
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160814000940) do ActiveRecord::Schema.define(version: 20161006021205) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -328,7 +328,7 @@ ActiveRecord::Schema.define(version: 20160814000940) do
t.string "activation_state" t.string "activation_state"
t.string "activation_token" t.string "activation_token"
t.datetime "activation_token_expires_at" t.datetime "activation_token_expires_at"
t.integer "failed_logins_count", default: 0 t.integer "failed_logins_count", default: 0
t.datetime "lock_expires_at" t.datetime "lock_expires_at"
t.string "unlock_token" t.string "unlock_token"
t.string "avatar" t.string "avatar"
@ -340,6 +340,7 @@ ActiveRecord::Schema.define(version: 20160814000940) do
t.json "languages" t.json "languages"
t.string "locale" t.string "locale"
t.boolean "is_subscribed" t.boolean "is_subscribed"
t.integer "fb_id", limit: 8
end end
add_index "users", ["activation_token"], name: "index_users_on_activation_token", using: :btree add_index "users", ["activation_token"], name: "index_users_on_activation_token", using: :btree

Loading…
Cancel
Save