2015-04-30 13:06:18 -04:00
|
|
|
class Profiles::KeysController < Profiles::ApplicationController
|
2015-04-16 08:03:37 -04:00
|
|
|
skip_before_action :authenticate_user!, only: [:get_keys]
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
def index
|
2015-02-05 17:20:55 -05:00
|
|
|
@keys = current_user.keys
|
2016-03-03 15:40:00 -05:00
|
|
|
@key = Key.new
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2011-12-19 16:32:59 -05:00
|
|
|
def show
|
|
|
|
@key = current_user.keys.find(params[:id])
|
|
|
|
end
|
2016-04-14 06:20:16 -04:00
|
|
|
|
|
|
|
# Back-compat: We need to support this URL since git-annex webapp points to it
|
|
|
|
def new
|
|
|
|
redirect_to profile_keys_path
|
|
|
|
end
|
2011-12-19 16:32:59 -05:00
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def create
|
2014-06-26 10:00:05 -04:00
|
|
|
@key = current_user.keys.new(key_params)
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2013-06-24 11:24:14 -04:00
|
|
|
if @key.save
|
|
|
|
redirect_to profile_key_path(@key)
|
|
|
|
else
|
2016-03-03 15:40:00 -05:00
|
|
|
@keys = current_user.keys.select(&:persisted?)
|
|
|
|
render :index
|
2013-06-24 11:24:14 -04:00
|
|
|
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|
|
2013-06-24 11:24:14 -04:00
|
|
|
format.html { redirect_to profile_keys_url }
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-02 11:09:29 -04:00
|
|
|
|
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
|
2013-10-02 11:09:29 -04:00
|
|
|
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?
|
2014-03-19 09:32:38 -04:00
|
|
|
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
|
2013-10-02 11:09:29 -04:00
|
|
|
rescue => e
|
|
|
|
render text: e.message
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_404 and return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 10:00:05 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def key_params
|
|
|
|
params.require(:key).permit(:title, :key)
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|