gitlab-org--gitlab-foss/app/controllers/profiles/keys_controller.rb

62 lines
1.2 KiB
Ruby
Raw Normal View History

class Profiles::KeysController < ApplicationController
2011-11-02 11:21:17 -04:00
layout "profile"
skip_before_filter :authenticate_user!, only: [:get_keys]
2011-10-08 17:36:38 -04:00
def index
@keys = current_user.keys
2011-10-08 17:36:38 -04:00
end
def show
@key = current_user.keys.find(params[:id])
end
2011-10-08 17:36:38 -04:00
def new
@key = current_user.keys.new
end
def create
@key = current_user.keys.new(key_params)
2011-10-08 17:36:38 -04:00
if @key.save
redirect_to profile_key_path(@key)
else
render 'new'
end
2011-10-08 17:36:38 -04:00
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 }
2011-10-08 17:36:38 -04:00
end
end
2014-02-11 08:34:47 -05:00
# 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])
2014-02-11 08:34:47 -05:00
if user.present?
render text: user.all_ssh_keys.join("\n"), content_type: "text/plain"
2014-02-11 08:34:47 -05:00
else
render_404 and return
end
rescue => e
render text: e.message
end
else
render_404 and return
end
end
private
def key_params
params.require(:key).permit(:title, :key)
end
2011-10-08 17:36:38 -04:00
end