2015-12-17 11:49:40 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class ExternalCredentialsController < ApplicationController
|
|
|
|
before_action :authentication_check
|
|
|
|
|
|
|
|
def index
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
model_index_render(ExternalCredential, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
model_show_render(ExternalCredential, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-12-21 00:48:49 +00:00
|
|
|
model_create_render(ExternalCredential, params)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-12-21 00:48:49 +00:00
|
|
|
model_update_render(ExternalCredential, params)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
model_destory_render(ExternalCredential, params)
|
|
|
|
end
|
|
|
|
|
2015-12-21 00:48:49 +00:00
|
|
|
def app_verify
|
|
|
|
attributes = ExternalCredential.app_verify(params)
|
|
|
|
render json: { attributes: attributes }, status: :ok
|
|
|
|
return
|
|
|
|
rescue => e
|
|
|
|
render json: { error: e.message }, status: :ok
|
|
|
|
end
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
def link_account
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
provider = params[:provider].downcase
|
2015-12-30 13:24:13 +00:00
|
|
|
attributes = ExternalCredential.request_account_to_link(provider)
|
2015-12-17 11:49:40 +00:00
|
|
|
session[:request_token] = attributes[:request_token]
|
|
|
|
redirect_to attributes[:authorize_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
def callback
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
provider = params[:provider].downcase
|
|
|
|
channel = ExternalCredential.link_account(provider, session[:request_token], params)
|
|
|
|
session[:request_token] = nil
|
2015-12-21 00:48:49 +00:00
|
|
|
redirect_to app_url(provider, channel.id)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def callback_url(provider)
|
2015-12-30 13:24:13 +00:00
|
|
|
ExternalCredential.callback_url(provider)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
2015-12-21 00:48:49 +00:00
|
|
|
def app_url(provider, channel_id)
|
2015-12-30 13:24:13 +00:00
|
|
|
ExternalCredential.app_url(provider, channel_id)
|
2015-12-21 00:48:49 +00:00
|
|
|
end
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|