Newer
Older
dmpopidor / app / controllers / user_identifiers_controller.rb
@Brian Riley Brian Riley on 7 Sep 2018 873 bytes Remove old JS form validations (#1867)
# frozen_string_literal: true

class UserIdentifiersController < ApplicationController

  respond_to :html
  after_action :verify_authorized

  # DELETE /users/identifiers
  # ---------------------------------------------------------------------
  def destroy
    authorize UserIdentifier
    user = User.find(current_user.id)
    identifier = UserIdentifier.find(params[:id])

    # If the requested identifier belongs to the current user remove it
    if user.user_identifiers.include?(identifier)
      identifier.destroy!
      flash[:notice] = _("Successfully unlinked your account from %{is}.") % {
        is: identifier.identifier_scheme.description
      }
    else
      flash[:alert] = _("Unable to unlink your account from %{is}.") % {
        is: identifier.identifier_scheme.description
      }
    end

    redirect_to edit_user_registration_path
  end

end