diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 376efc52..742013c3 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -9,11 +9,16 @@ class ServicesController < ApplicationController def create service = Service.initialize_from_omniauth( omniauth_hash ) + service.user = current_user - if current_user.services << service + if service.save flash[:success] = t('flash.service.create.success') else - flash[:error] = t('flash.service.create.error') + if service.errors.details.has_key?(:uid) && service.errors.details[:uid].any? { |err| err[:error] == :taken } + flash[:error] = "The #{service.type.split('::').last.titleize} account you are trying to connect is already connected to another #{APP_CONFIG['site_name']} account." + else + flash[:error] = t('flash.service.create.error') + end end if origin