Class: SolidLog::UI::TokensController

Inherits:
BaseController show all
Defined in:
app/controllers/solid_log/ui/tokens_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#authenticate_user!

Instance Method Details

#create ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/solid_log/ui/tokens_controller.rb', line 14

def create
  @token = SolidLog.without_logging do
    Token.generate!(token_params[:name])
  end

  # Store plaintext token in flash for one-time display
  flash[:token_plaintext] = @token[:token]
  redirect_to tokens_path, notice: "Token created successfully"
rescue ActiveRecord::RecordInvalid => e
  @token = Token.new(token_params)
  flash.now[:alert] = "Failed to create token: #{e.message}"
  render :new, status: :unprocessable_entity
end

#destroy ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/solid_log/ui/tokens_controller.rb', line 28

def destroy
  @token = Token.find(params[:id])
  token_name = @token.name

  SolidLog.without_logging do
    @token.destroy
  end

  redirect_to tokens_path, notice: "Token '#{token_name}' revoked"
end

#index ⇒ Object



4
5
6
7
8
# File 'app/controllers/solid_log/ui/tokens_controller.rb', line 4

def index
  @tokens = SolidLog.without_logging do
    Token.order(created_at: :desc)
  end
end

#new ⇒ Object



10
11
12
# File 'app/controllers/solid_log/ui/tokens_controller.rb', line 10

def new
  @token = Token.new
end