]> cat aescling's git repositories - mastodon.git/blob - app/controllers/settings/identity_proofs_controller.rb
squashed identity proof updates (#10375)
[mastodon.git] / app / controllers / settings / identity_proofs_controller.rb
1 # frozen_string_literal: true
2
3 class Settings::IdentityProofsController < Settings::BaseController
4 layout 'admin'
5
6 before_action :authenticate_user!
7 before_action :check_required_params, only: :new
8
9 def index
10 @proofs = AccountIdentityProof.where(account: current_account).order(provider: :asc, provider_username: :asc)
11 @proofs.each(&:refresh!)
12 end
13
14 def new
15 @proof = current_account.identity_proofs.new(
16 token: params[:token],
17 provider: params[:provider],
18 provider_username: params[:provider_username]
19 )
20
21 if current_account.username == params[:username]
22 render layout: 'auth'
23 else
24 flash[:alert] = I18n.t('identity_proofs.errors.wrong_user', proving: params[:username], current: current_account.username)
25 redirect_to settings_identity_proofs_path
26 end
27 end
28
29 def create
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]
32
33 if @proof.save
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])
36 else
37 flash[:alert] = I18n.t('identity_proofs.errors.failed', provider: @proof.provider.capitalize)
38 redirect_to settings_identity_proofs_path
39 end
40 end
41
42 private
43
44 def check_required_params
45 redirect_to settings_identity_proofs_path unless [:provider, :provider_username, :username, :token].all? { |k| params[k].present? }
46 end
47
48 def resource_params
49 params.require(:account_identity_proof).permit(:provider, :provider_username, :token)
50 end
51
52 def publish_proof?
53 ActiveModel::Type::Boolean.new.cast(post_params[:post_status])
54 end
55
56 def post_params
57 params.require(:account_identity_proof).permit(:post_status, :status_text)
58 end
59
60 def set_body_classes
61 @body_classes = ''
62 end
63 end
This page took 0.101446 seconds and 5 git commands to generate.