Allow user to creates named auth keys with token
This commit is contained in:
51
app/controllers/keys_controller.rb
Normal file
51
app/controllers/keys_controller.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
class KeysController < ApplicationController
|
||||
before_filter :set_key, only: %i[show edit update destroy]
|
||||
|
||||
def index
|
||||
@keys = current_user.keys
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@key = current_user.keys.new
|
||||
end
|
||||
|
||||
def create
|
||||
@key = current_user.keys.build key_params
|
||||
|
||||
if @key.save
|
||||
redirect_to action: :index
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @key.update_attributes key_params
|
||||
redirect_to action: :index
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@key.destroy
|
||||
redirect_to keys_path
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_key
|
||||
@key = current_user.keys.find(params[:id])
|
||||
end
|
||||
|
||||
def key_params
|
||||
params.require(:key).permit :name
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user