This commit adds a callback route to handle omniauth failure and removes a few unneccessary entries in en.yml

This commit is contained in:
Jesse Pollak 2013-02-14 11:11:13 -08:00
parent 9eb5c2a66a
commit ad5a5b4866
6 changed files with 84 additions and 54 deletions

View File

@ -22,6 +22,11 @@ class Users::OmniauthCallbacksController < ApplicationController
end end
end end
def failure
flash[:error] = I18n.t("login.omniauth_error", strategy: params[:strategy].titleize)
render :layout => 'no_js'
end
def create_or_sign_on_user_using_twitter(auth_token) def create_or_sign_on_user_using_twitter(auth_token)
data = auth_token[:info] data = auth_token[:info]
@ -62,7 +67,7 @@ class Users::OmniauthCallbacksController < ApplicationController
email = data[:email] email = data[:email]
name = data["name"] name = data["name"]
fb_uid = auth_token["uid"] fb_uid = auth_token["uid"]
username = User.suggest_username(name) username = User.suggest_username(name)

View File

@ -0,0 +1,11 @@
<div id="simple-container">
<%if flash[:error]%>
<div class='alert alert-error'>
<%=flash[:error]%>
</div>
<%else%>
<div class='alert alert-error'>
Something went wrong processing your log in, please try again.
</div>
<%end%>
</div>

View File

@ -1,31 +1,30 @@
require 'openid/store/filesystem'
require 'openssl' require 'openssl'
require 'openid_redis_store' require 'openid_redis_store'
# if you need to test this and are having ssl issues see: # if you need to test this and are having ssl issues see:
# http://stackoverflow.com/questions/6756460/openssl-error-using-omniauth-specified-ssl-path-but-didnt-work # http://stackoverflow.com/questions/6756460/openssl-error-using-omniauth-specified-ssl-path-but-didnt-work
Rails.application.config.middleware.use OmniAuth::Builder do Rails.application.config.middleware.use OmniAuth::Builder do
provider :open_id, provider :open_id,
:store => OpenID::Store::Redis.new($redis), :store => OpenID::Store::Redis.new($redis),
:name => 'google', :name => 'google',
:identifier => 'https://www.google.com/accounts/o8/id', :identifier => 'https://www.google.com/accounts/o8/id',
:require => 'omniauth-openid' :require => 'omniauth-openid'
provider :open_id, provider :open_id,
:store => OpenID::Store::Redis.new($redis), :store => OpenID::Store::Redis.new($redis),
:name => 'yahoo', :name => 'yahoo',
:identifier => 'https://me.yahoo.com', :identifier => 'https://me.yahoo.com',
:require => 'omniauth-openid' :require => 'omniauth-openid'
provider :facebook, provider :facebook,
SiteSetting.facebook_app_id, SiteSetting.facebook_app_id,
SiteSetting.facebook_app_secret, SiteSetting.facebook_app_secret,
:scope => "email" :scope => "email"
provider :twitter, provider :twitter,
SiteSetting.twitter_consumer_key, SiteSetting.twitter_consumer_key,
SiteSetting.twitter_consumer_secret SiteSetting.twitter_consumer_secret
end end

View File

@ -13,7 +13,7 @@ en:
education: education:
until_posts: until_posts:
one: "post" one: "post"
other: "%{count} posts" other: "%{count} posts"
'new-topic': | 'new-topic': |
@ -66,7 +66,7 @@ en:
trust_levels: trust_levels:
new: new:
title: "new user" title: "new user"
basic: basic:
title: "basic user" title: "basic user"
regular: regular:
title: "regular user" title: "regular user"
@ -91,7 +91,7 @@ en:
datetime: datetime:
distance_in_words: distance_in_words:
half_a_minute: "< 1m" half_a_minute: "< 1m"
less_than_x_seconds: less_than_x_seconds:
one: "< 1s" one: "< 1s"
other: "< %{count}s" other: "< %{count}s"
@ -127,7 +127,7 @@ en:
other: "%{count}y" other: "%{count}y"
distance_in_words_verbose: distance_in_words_verbose:
half_a_minute: "just now" half_a_minute: "just now"
less_than_x_seconds: less_than_x_seconds:
one: "just now" one: "just now"
other: "just now" other: "just now"
@ -212,7 +212,7 @@ en:
user_must_edit: '<p>Flagged content hidden.</p>' user_must_edit: '<p>Flagged content hidden.</p>'
archetypes: archetypes:
regular: regular:
title: "Regular Topic" title: "Regular Topic"
unsubscribed: unsubscribed:
@ -363,7 +363,7 @@ en:
types: types:
category: 'Categories' category: 'Categories'
topic: 'Topics' topic: 'Topics'
user: 'Users' user: 'Users'
youve_posted: "You've Posted" youve_posted: "You've Posted"
original_poster: "Original Poster" original_poster: "Original Poster"
@ -397,7 +397,7 @@ en:
edited: "edited" edited: "edited"
move_posts: move_posts:
moderator_post: moderator_post:
one: "I moved a post to a new topic: %{topic_link}" one: "I moved a post to a new topic: %{topic_link}"
other: "I moved %{count} posts to a new topic: %{topic_link}" other: "I moved %{count} posts to a new topic: %{topic_link}"
@ -411,7 +411,7 @@ en:
visible_enabled: "This topic is now visible. It will be displayed in topic lists." visible_enabled: "This topic is now visible. It will be displayed in topic lists."
visible_disabled: "This topic is now invisible. It will no longer be displayed in any topic lists. The only way to access this topic is via direct link." visible_disabled: "This topic is now invisible. It will no longer be displayed in any topic lists. The only way to access this topic is via direct link."
login: login:
not_approved: "Your account hasn't been approved yet. You will be notified by email when you are ready to log in." not_approved: "Your account hasn't been approved yet. You will be notified by email when you are ready to log in."
incorrect_username_email_or_password: "Incorrect username, email or password" incorrect_username_email_or_password: "Incorrect username, email or password"
wait_approval: "Thanks for signing up. We will notify you when your account has been approved." wait_approval: "Thanks for signing up. We will notify you when your account has been approved."
@ -420,6 +420,8 @@ en:
not_activated: "You can't log in yet. We sent an activation email to you. Please follow the instructions in the email to activate your account." not_activated: "You can't log in yet. We sent an activation email to you. Please follow the instructions in the email to activate your account."
errors: "%{errors}" errors: "%{errors}"
not_available: "Not available. Try %{suggestion}?" not_available: "Not available. Try %{suggestion}?"
omniauth_error: "Sorry, there was an error authorizing your %{strategy} account. Perhaps you did not approve authorization?"
user: user:
username: username:
@ -494,7 +496,7 @@ en:
subject_template: "%{site_name} Notice: Posting Hidden due to Community Flagging" subject_template: "%{site_name} Notice: Posting Hidden due to Community Flagging"
text_body_template: | text_body_template: |
Hello, Hello,
This is an automated message from %{site_name} to inform you that the following post was hidden as a result of community flagging. This is an automated message from %{site_name} to inform you that the following post was hidden as a result of community flagging.
%{base_url}%{url} %{base_url}%{url}
@ -608,7 +610,7 @@ en:
unsubscribe_link: "If you'd like to unsubscribe from these emails, visit your [user preferences](%{user_preferences_url})." unsubscribe_link: "If you'd like to unsubscribe from these emails, visit your [user preferences](%{user_preferences_url})."
user_notifications: user_notifications:
unsubscribe: unsubscribe:
title: "Unsubscribe" title: "Unsubscribe"
description: "Not interested in getting these emails? No problem! Click below to unsubscribe instantly:" description: "Not interested in getting these emails? No problem! Click below to unsubscribe instantly:"
@ -627,7 +629,7 @@ en:
--- ---
%{message} %{message}
--- ---
Please visit this link to respond: %{base_url}%{url} Please visit this link to respond: %{base_url}%{url}
user_quoted: user_quoted:
@ -638,7 +640,7 @@ en:
--- ---
%{message} %{message}
--- ---
Please visit this link to respond: %{base_url}%{url} Please visit this link to respond: %{base_url}%{url}
user_mentioned: user_mentioned:
@ -649,7 +651,7 @@ en:
--- ---
%{message} %{message}
--- ---
Please visit this link to respond: %{base_url}%{url} Please visit this link to respond: %{base_url}%{url}
@ -675,9 +677,9 @@ en:
subject_template: "[%{site_name}] Password reset" subject_template: "[%{site_name}] Password reset"
text_body_template: | text_body_template: |
Somebody asked to reset your password on [%{site_name}](%{base_url}). Somebody asked to reset your password on [%{site_name}](%{base_url}).
If it was not you, you can safely ignore this email. If it was not you, you can safely ignore this email.
Click the following link to choose a new password: Click the following link to choose a new password:
%{base_url}/users/password-reset/%{email_token} %{base_url}/users/password-reset/%{email_token}
@ -685,14 +687,14 @@ en:
subject_template: "[%{site_name}] Confirm your new email address" subject_template: "[%{site_name}] Confirm your new email address"
text_body_template: | text_body_template: |
Confirm your new email address for %{site_name} by clicking on the following link: Confirm your new email address for %{site_name} by clicking on the following link:
%{base_url}/users/authorize-email/%{email_token} %{base_url}/users/authorize-email/%{email_token}
signup: signup:
subject_template: "[%{site_name}] Activate your new account" subject_template: "[%{site_name}] Activate your new account"
text_body_template: | text_body_template: |
Welcome to %{site_name}! Welcome to %{site_name}!
Click the following link to confirm and activate your new account: Click the following link to confirm and activate your new account:
%{base_url}/users/activate-account/%{email_token} %{base_url}/users/activate-account/%{email_token}

View File

@ -3,7 +3,7 @@ require 'sidekiq/web'
require_dependency 'admin_constraint' require_dependency 'admin_constraint'
# This used to be User#username_format, but that causes a preload of the User object # This used to be User#username_format, but that causes a preload of the User object
# and makes Guard not work properly. # and makes Guard not work properly.
USERNAME_ROUTE_FORMAT = /[A-Za-z0-9\._]+/ USERNAME_ROUTE_FORMAT = /[A-Za-z0-9\._]+/
Discourse::Application.routes.draw do Discourse::Application.routes.draw do
@ -12,8 +12,8 @@ Discourse::Application.routes.draw do
mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new
resources :forums do resources :forums do
collection do collection do
get 'request_access' get 'request_access'
post 'request_access_submit' post 'request_access_submit'
end end
@ -60,24 +60,24 @@ Discourse::Application.routes.draw do
post 'email/resubscribe/:key' => 'email#resubscribe', as: 'email_resubscribe' post 'email/resubscribe/:key' => 'email#resubscribe', as: 'email_resubscribe'
resources :session, id: USERNAME_ROUTE_FORMAT do resources :session, id: USERNAME_ROUTE_FORMAT do
collection do collection do
post 'forgot_password' post 'forgot_password'
end end
end end
resources :users, :except => [:show, :update] do resources :users, :except => [:show, :update] do
collection do collection do
get 'check_username' get 'check_username'
get 'is_local_username' get 'is_local_username'
end end
end end
resources :static resources :static
get 'faq' => 'static#show', id: 'faq' get 'faq' => 'static#show', id: 'faq'
get 'tos' => 'static#show', id: 'tos' get 'tos' => 'static#show', id: 'tos'
get 'privacy' => 'static#show', id: 'privacy' get 'privacy' => 'static#show', id: 'privacy'
get 'users/search/users' => 'users#search_users' get 'users/search/users' => 'users#search_users'
get 'users/password-reset/:token' => 'users#password_reset' get 'users/password-reset/:token' => 'users#password_reset'
put 'users/password-reset/:token' => 'users#password_reset' put 'users/password-reset/:token' => 'users#password_reset'
@ -88,10 +88,10 @@ Discourse::Application.routes.draw do
get 'user_preferences' => 'users#user_preferences_redirect' get 'user_preferences' => 'users#user_preferences_redirect'
get 'users/:username/private-messages' => 'user_actions#private_messages', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} get 'users/:username/private-messages' => 'user_actions#private_messages', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
get 'users/:username' => 'users#show', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} get 'users/:username' => 'users#show', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
put 'users/:username' => 'users#update', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} put 'users/:username' => 'users#update', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
get 'users/:username/preferences' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}, :as => :email_preferences get 'users/:username/preferences' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}, :as => :email_preferences
get 'users/:username/preferences/email' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} get 'users/:username/preferences/email' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
put 'users/:username/preferences/email' => 'users#change_email', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} put 'users/:username/preferences/email' => 'users#change_email', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
get 'users/:username/preferences/username' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} get 'users/:username/preferences/username' => 'users#preferences', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
put 'users/:username/preferences/username' => 'users#username', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT} put 'users/:username/preferences/username' => 'users#username', :format => false, :constraints => {:username => USERNAME_ROUTE_FORMAT}
get 'users/:username/avatar(/:size)' => 'users#avatar', :constraints => {:username => USERNAME_ROUTE_FORMAT} get 'users/:username/avatar(/:size)' => 'users#avatar', :constraints => {:username => USERNAME_ROUTE_FORMAT}
@ -115,13 +115,14 @@ Discourse::Application.routes.draw do
resources :categories resources :categories
match "/auth/:provider/callback", to: "users/omniauth_callbacks#complete" match "/auth/:provider/callback", to: "users/omniauth_callbacks#complete"
match "/auth/failure", to: "users/omniauth_callbacks#failure"
get 'twitter/frame' => 'twitter#frame' get 'twitter/frame' => 'twitter#frame'
get 'twitter/complete' => 'twitter#complete' get 'twitter/complete' => 'twitter#complete'
get 'facebook/frame' => 'facebook#frame' get 'facebook/frame' => 'facebook#frame'
get 'facebook/complete' => 'facebook#complete' get 'facebook/complete' => 'facebook#complete'
resources :clicks do resources :clicks do
collection do collection do
get 'track' => 'clicks#track' get 'track' => 'clicks#track'
@ -162,13 +163,13 @@ Discourse::Application.routes.draw do
get 't/:id' => 'topics#show' get 't/:id' => 'topics#show'
delete 't/:id' => 'topics#destroy' delete 't/:id' => 'topics#destroy'
put 't/:id' => 'topics#update' put 't/:id' => 'topics#update'
post 't' => 'topics#create' post 't' => 'topics#create'
post 'topics/timings' => 'topics#timings' post 'topics/timings' => 'topics#timings'
# Legacy route for old avatars # Legacy route for old avatars
get 'threads/:topic_id/:post_number/avatar' => 'topics#avatar', :constraints => {:topic_id => /\d+/, :post_number => /\d+/} get 'threads/:topic_id/:post_number/avatar' => 'topics#avatar', :constraints => {:topic_id => /\d+/, :post_number => /\d+/}
# Topic routes # Topic routes
get 't/:slug/:topic_id/best_of' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/} get 't/:slug/:topic_id/best_of' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/}
get 't/:topic_id/best_of' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/} get 't/:topic_id/best_of' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/}
put 't/:slug/:topic_id' => 'topics#update', :constraints => {:topic_id => /\d+/} put 't/:slug/:topic_id' => 'topics#update', :constraints => {:topic_id => /\d+/}
@ -181,18 +182,18 @@ Discourse::Application.routes.draw do
get 't/:topic_id/:post_number' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/} get 't/:topic_id/:post_number' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/}
get 't/:slug/:topic_id' => 'topics#show', :constraints => {:topic_id => /\d+/} get 't/:slug/:topic_id' => 'topics#show', :constraints => {:topic_id => /\d+/}
get 't/:slug/:topic_id/:post_number' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/} get 't/:slug/:topic_id/:post_number' => 'topics#show', :constraints => {:topic_id => /\d+/, :post_number => /\d+/}
post 't/:topic_id/timings' => 'topics#timings', :constraints => {:topic_id => /\d+/} post 't/:topic_id/timings' => 'topics#timings', :constraints => {:topic_id => /\d+/}
post 't/:topic_id/invite' => 'topics#invite', :constraints => {:topic_id => /\d+/} post 't/:topic_id/invite' => 'topics#invite', :constraints => {:topic_id => /\d+/}
post 't/:topic_id/move-posts' => 'topics#move_posts', :constraints => {:topic_id => /\d+/} post 't/:topic_id/move-posts' => 'topics#move_posts', :constraints => {:topic_id => /\d+/}
delete 't/:topic_id/timings' => 'topics#destroy_timings', :constraints => {:topic_id => /\d+/} delete 't/:topic_id/timings' => 'topics#destroy_timings', :constraints => {:topic_id => /\d+/}
post 't/:topic_id/notifications' => 'topics#set_notifications' , :constraints => {:topic_id => /\d+/} post 't/:topic_id/notifications' => 'topics#set_notifications' , :constraints => {:topic_id => /\d+/}
resources :invites resources :invites
delete 'invites' => 'invites#destroy' delete 'invites' => 'invites#destroy'
get 'request_access' => 'request_access#new' get 'request_access' => 'request_access#new'
post 'request_access' => 'request_access#create' post 'request_access' => 'request_access#create'

View File

@ -0,0 +1,12 @@
require "spec_helper"
describe "users/omniauth_callbacks/failure.html.erb" do
it "renders the failure page" do
flash[:error] = I18n.t("login.omniauth_error", strategy: 'test')
render
rendered.match(I18n.t("login.omniauth_error", strategy: 'test')).should be_true
end
end