Class: Profiles::KeysController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/profiles/keys_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/profiles/keys_controller.rb', line 18

def create
  @key = current_user.keys.new(key_params)

  if @key.save
    redirect_to profile_key_path(@key)
  else
    @keys = current_user.keys.select(&:persisted?)
    render :index
  end
end

#destroyObject


29
30
31
32
33
34
35
36
37
# File 'app/controllers/profiles/keys_controller.rb', line 29

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_keysObject

Get all keys of a user(params) in a text format Helpful for sysadmins to put in respective servers


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/profiles/keys_controller.rb', line 41

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

#indexObject


4
5
6
7
# File 'app/controllers/profiles/keys_controller.rb', line 4

def index
  @keys = current_user.keys
  @key = Key.new
end

#newObject

Back-compat: We need to support this URL since git-annex webapp points to it


14
15
16
# File 'app/controllers/profiles/keys_controller.rb', line 14

def new
  redirect_to profile_keys_path
end

#showObject


9
10
11
# File 'app/controllers/profiles/keys_controller.rb', line 9

def show
  @key = current_user.keys.find(params[:id])
end