2018-09-23 19:44:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-30 17:06:18 +00:00
|
|
|
class Profiles::KeysController < Profiles::ApplicationController
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :users
|
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
def index
|
2017-08-15 10:27:37 +00:00
|
|
|
@keys = current_user.keys.order_id_desc
|
2016-03-03 20:40:00 +00:00
|
|
|
@key = Key.new
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2011-12-19 21:32:59 +00:00
|
|
|
def show
|
|
|
|
@key = current_user.keys.find(params[:id])
|
|
|
|
end
|
2016-04-14 10:20:16 +00:00
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
def create
|
2017-10-24 06:52:47 +00:00
|
|
|
@key = Keys::CreateService.new(current_user, key_params.merge(ip_address: request.remote_ip)).execute
|
2011-10-08 21:36:38 +00:00
|
|
|
|
2017-09-15 15:35:24 +00:00
|
|
|
if @key.persisted?
|
2017-10-24 06:52:47 +00:00
|
|
|
redirect_to profile_key_path(@key)
|
2013-06-24 15:24:14 +00:00
|
|
|
else
|
2016-03-03 20:40:00 +00:00
|
|
|
@keys = current_user.keys.select(&:persisted?)
|
|
|
|
render :index
|
2013-06-24 15:24:14 +00:00
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@key = current_user.keys.find(params[:id])
|
2018-05-16 18:26:22 +00:00
|
|
|
Keys::DestroyService.new(current_user).execute(@key)
|
2011-10-08 21:36:38 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2018-07-02 10:43:06 +00:00
|
|
|
format.html { redirect_to profile_keys_url, status: :found }
|
2016-03-16 01:16:25 +00:00
|
|
|
format.js { head :ok }
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
end
|
2013-10-02 15:09:29 +00:00
|
|
|
|
2014-06-26 14:00:05 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def key_params
|
2020-03-13 09:09:23 +00:00
|
|
|
params.require(:key).permit(:title, :key, :expires_at)
|
2014-06-26 14:00:05 +00:00
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|