diff --git a/app/assets/stylesheets/_application.scss b/app/assets/stylesheets/_application.scss index 795266e..db038fb 100644 --- a/app/assets/stylesheets/_application.scss +++ b/app/assets/stylesheets/_application.scss @@ -1179,6 +1179,11 @@ $header-tilt: 8deg; .secondary { font-size: 1.5em; } + + body.error-500 & { + background-position: 50% 50%; + background-color: $colour-2; + } } #footer { diff --git a/app/assets/stylesheets/user-mailer.scss b/app/assets/stylesheets/user-mailer.scss index fdf404c..2fc4871 100644 --- a/app/assets/stylesheets/user-mailer.scss +++ b/app/assets/stylesheets/user-mailer.scss @@ -102,6 +102,10 @@ table { td { border-collapse: collapse; } + + th { + text-align: left; + } } table#bb_full_width, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f9fc7bc..c427c21 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -92,12 +92,22 @@ class ApplicationController < LinguaFrancaApplicationController def do_403(template = nil) @template = template + @page_title ||= 'page_titles.403.Access_Denied' @main_title ||= @page_title params[:_original_action] = params[:action] params[:action] = 'error-403' render 'application/permission_denied', status: 403 end + def error_500(exception) + + @page_title = 'page_titles.500.An_Error_Occurred' + @main_title = 'error.500.title' + params[:_original_action] = params[:action] + params[:action] = 'error-500' + render 'application/500', status: 500 + end + rescue_from ActiveRecord::RecordNotFound do |exception| do_404 end @@ -119,6 +129,22 @@ class ApplicationController < LinguaFrancaApplicationController end end + rescue_from StandardError do |exception| + # send and email if this is production + UserMailer.error_report( + "An error has occurred in #{Rails.env}", + nil, + exception.to_s, + exception, + request, + params, + current_user, + ).deliver_now if Rails.env.preview? || Rails.env.production? + + # show the error page + error_500 exception + end + def generate_confirmation(user, url, expiry = nil) if user.is_a? String user = User.find_by_email(user) @@ -128,8 +154,6 @@ class ApplicationController < LinguaFrancaApplicationController end expiry ||= (Time.now + 12.hours) session[:confirm_uid] = user.id - #confirmation = EmailConfirmation.create(user_id: user.id, expiry: expiry, url: url) - #UserMailer.email_confirmation(confirmation).deliver_now UserMailer.send_mail :email_confirmation do { :args => EmailConfirmation.create(user_id: user.id, expiry: expiry, url: url) @@ -247,4 +271,17 @@ class ApplicationController < LinguaFrancaApplicationController end end end + + def i18n_exception(str, exception, locale, key) + # send and email if this is production + UserMailer.error_report( + "A missing translation found in #{Rails.env}", + "A translation for #{key} in #{locale.to_s} was found. The text that was rendered to the user was \"#{str || 'nil'}\".", + exception.to_s, + exception, + request, + params, + current_user, + ).deliver_now if Rails.env.preview? || Rails.env.production? + end end diff --git a/app/controllers/oauths_controller.rb b/app/controllers/oauths_controller.rb index 9b411dd..376bc9e 100644 --- a/app/controllers/oauths_controller.rb +++ b/app/controllers/oauths_controller.rb @@ -33,8 +33,12 @@ class OauthsController < ApplicationController end def set_callback + # force https for prod + protocol = Rails.env.preview? || Rails.env.production? ? 'https://' : request.protocol + + # build the callback url Sorcery::Controller::Config.send(params[:provider]).callback_url = - "#{request.protocol}#{request.env['HTTP_HOST']}/oauth/callback?provider=facebook" + "#{protocol}#{request.env['HTTP_HOST']}/oauth/callback?provider=facebook" end end \ No newline at end of file diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index baa4bb5..c050d34 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -164,4 +164,15 @@ class UserMailer < ActionMailer::Base mail to: user.email, subject: @subject end + def error_report(subject, message, report, exception, request, params, user) + @host = UserMailer.default_url_options[:host] + @subject = subject + @message = message + @report = report + @exception = exception + @request = request + @params = params + @user = user + mail to: 'goodgodwin@hotmail.com', subject: @subject + end end diff --git a/app/views/application/permission_denied.html.haml b/app/views/application/permission_denied.html.haml index c89daec..0b86b15 100644 --- a/app/views/application/permission_denied.html.haml +++ b/app/views/application/permission_denied.html.haml @@ -5,5 +5,5 @@ - else = row do = columns do - %h2=_'articles.permission_denied.headings.main','Sorry, you currently don\'t have access to this page' - %p=_'articles.permission_denied.paragraphs.main', :p + %h2=_'error.403.title','Sorry, you currently don\'t have access to this page' + %p=_'error.403.description', :p diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d9ba37..26a2232 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5601,6 +5601,7 @@ en: facebook_sign_in: Facebook Sign In page_titles: '403': + Access_Denied: Access Denied Please_Confirm_Email: Please confirm your email Please_Check_Email: Please check your email Please_Login: Please login @@ -5628,6 +5629,8 @@ en: About: 'About' Register: 'Register' Pre_Register: 'Pre-Register' + '500': + An_Error_Occurred: An Error Occurred links: footer: help_text: @@ -5667,11 +5670,17 @@ en: conference: Translate: Edit %{language} version error: + '403': + description: You do not currently have sufficient permissions to access this page. If you believe this is an error, please contact us or file an issue. + title: You do not have access to this page '404': description: Sorry, we couldn't find the page you were looking for. If you really believe that it should exist please contact admin@bikebike.org or file an issue on github: https://github.com/bikebike/BikeBike/issues title: '404: This page doesn''t exist' + '500': + title: There is a problem + description: 'An error has occurred, details about the error have been sent to our development team. In addition, you may contact us or report an issue.' roles: workshops: facilitator: diff --git a/config/routes.rb b/config/routes.rb index 198ed2c..2f35a17 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,7 +50,9 @@ BikeBike::Application.routes.draw do get '/oauth/:provider' => 'oauths#oauth', :as => :auth_at_provider post '/translator-request' => 'application#translator_request', :as => :translator_request + get '/error_403' => 'application#do_403' get '/error_404' => 'application#error_404' + get '/error_500' => 'application#error_500' get '/404' => 'application#error_404' get '/about' => 'application#about', :as => :about get '/policy' => 'application#policy', :as => :policy