diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb new file mode 100644 index 00000000..d81ca389 --- /dev/null +++ b/app/controllers/services_controller.rb @@ -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 diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb new file mode 100644 index 00000000..de584353 --- /dev/null +++ b/app/helpers/services_helper.rb @@ -0,0 +1,2 @@ +module ServicesHelper +end diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml new file mode 100644 index 00000000..98d876a5 --- /dev/null +++ b/app/views/services/index.html.haml @@ -0,0 +1,2 @@ +
Find me in app/views/services/index.html.erb
diff --git a/config/routes.rb b/config/routes.rb index 81fe8d51..0f0be3d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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#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 match '/ask', to: 'question#create', via: :post, as: :ask match '/answer', to: 'inbox#destroy', via: :post, as: :answer