added Services controller
This commit is contained in:
parent
12180bf1f2
commit
f24433d84e
|
@ -0,0 +1,38 @@
|
||||||
|
class ServicesController < ApplicationController
|
||||||
|
|
||||||
|
skip_before_action :verify_authenticity_token, :only => :create
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@services = current_user.services
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
service = Service.initialize_from_omniauth( omniauth_hash )
|
||||||
|
|
||||||
|
if current_user.services << service
|
||||||
|
flash[:success] = 'Successfully added service'
|
||||||
|
else
|
||||||
|
flash[:error] = 'Could not add service :('
|
||||||
|
end
|
||||||
|
|
||||||
|
if origin
|
||||||
|
redirect_to origin
|
||||||
|
else
|
||||||
|
redirect_to services_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def failure
|
||||||
|
Rails.logger.info "oauth error: #{params.inspect}"
|
||||||
|
flash[:error] = 'An error occurred'
|
||||||
|
redirect_to services_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@service = current_user.services.find(params[:id])
|
||||||
|
@service.destroy
|
||||||
|
flash[:success] = 'Successfully removed service'
|
||||||
|
redirect_to services_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
module ServicesHelper
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Services#index</h1>
|
||||||
|
<p>Find me in app/views/services/index.html.erb</p>
|
|
@ -33,6 +33,16 @@ Rails.application.routes.draw do
|
||||||
match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile
|
match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile
|
||||||
match '/settings/profile', to: 'user#update', via: 'patch', as: :update_user_profile
|
match '/settings/profile', to: 'user#update', via: 'patch', as: :update_user_profile
|
||||||
|
|
||||||
|
# resources :services, only: [:index, :destroy]
|
||||||
|
match '/settings/services', to: 'services#index', via: 'get', as: :services
|
||||||
|
match '/settings/services/:id', to: 'services#destroy', via: 'delete', as: :service
|
||||||
|
controller :services do
|
||||||
|
scope "/auth", as: "auth" do
|
||||||
|
get ':provider/callback' => :create
|
||||||
|
get :failure
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
namespace :ajax do
|
namespace :ajax do
|
||||||
match '/ask', to: 'question#create', via: :post, as: :ask
|
match '/ask', to: 'question#create', via: :post, as: :ask
|
||||||
match '/answer', to: 'inbox#destroy', via: :post, as: :answer
|
match '/answer', to: 'inbox#destroy', via: :post, as: :answer
|
||||||
|
|
Loading…
Reference in New Issue