<commit_before>class SecretsController < ApplicationController
  
  before_action :set_record, except: [:index, :new, :create]
  before_action :authenticate_user!
  
  def new
    #Enforce maximum record count to prevent abuse and overuse
    if current_user.secrets.count >= 100
      flash[:notice] = "Maximum number of records exceeded."
      redirect_to secrets_path
    else
      @secret = Secret.new
    end
    
  end

  def create
     #@secret = Secret.new(secret_params)
     @secret =current_user.secrets.build(secret_params)
    
    if @secret.save
      flash[:notice] = "Saved"
      redirect_to secrets_path
    else
      flash[:error] = @secret.errors.full_messages.to_sentence
      render :new
    end
  end

  def update
    @secret.assign_attributes(secret_params)
     if @secret.save
       flash[:notice] = "Record was updated."
      redirect_to secrets_path 
     else
       flash[:error] = @secret.errors.full_messages.to_sentence
       render :edit
     end
  end

  def edit
    # Render the edit view
  end

  def destroy
    @secret = Secret.find(params[:id])
     if @secret.destroy
       flash[:notice] = "Record was deleted successfully."
       redirect_to action: :index
     else
       flash[:error] = "There was an error deleting the record."
       render :show
     end
  end

  def index
    #Rails.logger.info ">>>>> pin: #{session[:pin]}"
   begin
   #Catch decryption error
   #Try to decrypt a field to make sure encryption key and pin are correct
   current_user.secrets.first.pw if current_user.secrets.any?
   rescue Exception => e
    if e.message == "bad decrypt"
      flash[:error] = "Unable to decrypt.  Sign-out and back in again with the correct PIN."
      Rails.logger.info ">>>> flash: #{flash.inspect}"
      redirect_to signout_path
      #redirect_to root_path
      #redirect_to destroy_user_session_path, method: :delete
      
    end
   end
   @secrets_grid = initialize_grid(current_user.secrets,
                    name:                 'g1',
                    order:                'secrets.catname',
                    order_direction:      'asc',
                    per_page:             10,
                    enable_export_to_csv: true,<commit_msg>Fixed error message when incorrect PIN entered during login<commit_after>class SecretsController < ApplicationController
  
  before_action :set_record, except: [:index, :new, :create]
  before_action :authenticate_user!
  
  def new
    #Enforce maximum record count to prevent abuse and overuse
    if current_user.secrets.count >= 100
      flash[:notice] = "Maximum number of records exceeded."
      redirect_to secrets_path
    else
      @secret = Secret.new
    end
    
  end

  def create
     #@secret = Secret.new(secret_params)
     @secret =current_user.secrets.build(secret_params)
    
    if @secret.save
      flash[:notice] = "Saved"
      redirect_to secrets_path
    else
      flash[:error] = @secret.errors.full_messages.to_sentence
      render :new
    end
  end

  def update
    @secret.assign_attributes(secret_params)
     if @secret.save
       flash[:notice] = "Record was updated."
      redirect_to secrets_path 
     else
       flash[:error] = @secret.errors.full_messages.to_sentence
       render :edit
     end
  end

  def edit
    # Render the edit view
  end

  def destroy
    @secret = Secret.find(params[:id])
     if @secret.destroy
       flash[:notice] = "Record was deleted successfully."
       redirect_to action: :index
     else
       flash[:error] = "There was an error deleting the record."
       render :show
     end
  end

  def index
    #Rails.logger.info ">>>>> pin: #{session[:pin]}"
   begin
   #Catch decryption error
   #Try to decrypt a field to make sure encryption key and pin are correct
   current_user.secrets.first.pw if current_user.secrets.any?
   rescue Exception => e
    if e.message == "bad decrypt"
      flash[:error] = "Unable to decrypt.  Log in again with the correct PIN."
      Rails.logger.info ">>>> flash: #{flash.inspect}"
      redirect_to signout_path
      #redirect_to root_path
      #redirect_to destroy_user_session_path, method: :delete
      
    end
   end
   @secrets_grid = initialize_grid(current_user.secrets,
                    name:                 'g1',
                    order:                'secrets.catname',
                    order_direction:      'asc',
                    per_page:             10,
                    enable_export_to_csv: true,
{'fraction_non_alphanumeric': 0.08470431302801246, 'fraction_numerical': 0.0026678523788350376, 'mean_word_length': 2.2983870967741935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7232646', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1288, 'n_words': 365}