gitlab-org--gitlab-foss/app/controllers/profiles/keys_controller.rb
Dmitry Medvinsky fefab47456 Fix /:username.keys response content type
Currently this method responds with `text/html`. It is kind of unusable
if you open it in a browser. The browser thinks it is HTML and renders
it as HTML, meaning new lines are dropped. So it's very hard to
distinguish where the key starts and where it ends.

This commit changes the content type header to `text/plain`.
2014-03-20 19:09:14 +04:00

56 lines
1.2 KiB
Ruby

class Profiles::KeysController < ApplicationController
layout "profile"
skip_before_filter :authenticate_user!, only: [:get_keys]
def index
@keys = current_user.keys.order('id DESC')
end
def show
@key = current_user.keys.find(params[:id])
end
def new
@key = current_user.keys.new
end
def create
@key = current_user.keys.new(params[:key])
if @key.save
redirect_to profile_key_path(@key)
else
render 'new'
end
end
def destroy
@key = current_user.keys.find(params[:id])
@key.destroy
respond_to do |format|
format.html { redirect_to profile_keys_url }
format.js { render nothing: true }
end
end
# Get all keys of a user(params[:username]) in a text format
# Helpful for sysadmins to put in respective servers
def get_keys
if params[:username].present?
begin
user = User.find_by_username(params[:username])
if user.present?
render text: user.all_ssh_keys.join("\n"), content_type: "text/plain"
else
render_404 and return
end
rescue => e
render text: e.message
end
else
render_404 and return
end
end
end