1 # frozen_string_literal: true
3 class Settings
::IdentityProofsController < Settings
::BaseController
6 before_action
:authenticate_user!
7 before_action
:check_required_params, only
: :new
10 @proofs = AccountIdentityProof
.where(account
: current_account
).order(provider
: :asc, provider_username
: :asc)
11 @proofs.each(&:refresh!
)
15 @proof = current_account
.identity_proofs
.new(
16 token
: params
[:token],
17 provider
: params
[:provider],
18 provider_username
: params
[:provider_username]
21 if current_account
.username
== params
[:username]
24 flash
[:alert] = I18n
.t('identity_proofs.errors.wrong_user', proving
: params
[:username], current
: current_account
.username
)
25 redirect_to settings_identity_proofs_path
30 @proof = current_account
.identity_proofs
.where(provider
: resource_params
[:provider], provider_username
: resource_params
[:provider_username]).first_or_initialize(resource_params
)
31 @proof.token
= resource_params
[:token]
34 PostStatusService
.new
.call(current_user
.account
, text
: post_params
[:status_text]) if publish_proof
?
35 redirect_to
@proof.on_success_path(params
[:user_agent])
37 flash
[:alert] = I18n
.t('identity_proofs.errors.failed', provider
: @proof.provider
.capitalize
)
38 redirect_to settings_identity_proofs_path
44 def check_required_params
45 redirect_to settings_identity_proofs_path
unless [:provider, :provider_username, :username, :token].all
? { |k
| params
[k
].present
? }
49 params
.require(:account_identity_proof).permit(:provider, :provider_username, :token)
53 ActiveModel
::Type::Boolean.new
.cast(post_params
[:post_status])
57 params
.require(:account_identity_proof).permit(:post_status, :status_text)