blob: b0a5a631c63e3282a4aed088b7ad2749a7ad7581 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
class Profiles::KeysController < ApplicationController
layout "profile"
skip_before_action :authenticate_user!, only: [:get_keys]
def index
@keys = current_user.keys
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(key_params)
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
private
def key_params
params.require(:key).permit(:title, :key)
end
end
|