external_credentials_controller.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class ExternalCredentialsController < ApplicationController
  3. before_action { authentication_check(permission: ['admin.channel_twitter', 'admin.channel_facebook']) }
  4. def index
  5. model_index_render(ExternalCredential, params)
  6. end
  7. def show
  8. model_show_render(ExternalCredential, params)
  9. end
  10. def create
  11. model_create_render(ExternalCredential, params)
  12. end
  13. def update
  14. model_update_render(ExternalCredential, params)
  15. end
  16. def destroy
  17. model_destory_render(ExternalCredential, params)
  18. end
  19. def app_verify
  20. attributes = ExternalCredential.app_verify(params)
  21. render json: { attributes: attributes }, status: :ok
  22. return
  23. rescue => e
  24. render json: { error: e.message }, status: :ok
  25. end
  26. def link_account
  27. provider = params[:provider].downcase
  28. attributes = ExternalCredential.request_account_to_link(provider)
  29. session[:request_token] = attributes[:request_token]
  30. redirect_to attributes[:authorize_url]
  31. end
  32. def callback
  33. provider = params[:provider].downcase
  34. channel = ExternalCredential.link_account(provider, session[:request_token], params)
  35. session[:request_token] = nil
  36. redirect_to app_url(provider, channel.id)
  37. end
  38. private
  39. def callback_url(provider)
  40. ExternalCredential.callback_url(provider)
  41. end
  42. def app_url(provider, channel_id)
  43. ExternalCredential.app_url(provider, channel_id)
  44. end
  45. end