Improve error messaging when trying to attach a service connected to another account
This commit is contained in:
parent
5ffce61efe
commit
fe6dff8ed6
|
@ -9,11 +9,16 @@ class ServicesController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
service = Service.initialize_from_omniauth( omniauth_hash )
|
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')
|
flash[:success] = t('flash.service.create.success')
|
||||||
else
|
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
|
end
|
||||||
|
|
||||||
if origin
|
if origin
|
||||||
|
|
Loading…
Reference in New Issue