<commit_before>require './config/environment'
require 'rack-flash'

class AdminController < Sinatra::Base
  set :public_folder, './public'
  set :views, 'app/views'
  enable :sessions unless test?
  set :session_secret, "secret"
  use Rack::Flash

  get '/admin' do
    erb :'admin/login'
  end

  post '/admin' do
    @admin = Admin.find_by(name: params[:name])
    binding.pry
    if @admin && @admin.authenticate(params[:password])
      binding.pry
      session[:admin_id] = @admin.id
      redirect "/admin/#{@admin.id}"
    else
      binding.pry
      flash[:message] = "Something went wrong. Please try again."
      @params = params
      erb :'/admin/login'
    end
  end

  get '/admin/:id' do
    @admin = Admin.find(params[:id])
    if @admin == Helpers.current_admin(session)
      erb :'admin/show'
    else
      "You're not an admin"
    end
  end

  get '/admin/:id/users' do
    @admin = Admin.find(params[:id])
    if @admin == Helpers.current_admin(session)
      erb :'admin/users'
    else
      "You're not an admin"
    end
  end
end<commit_msg>add new product form<commit_after>require './config/environment'
require 'rack-flash'

class AdminController < Sinatra::Base
  set :public_folder, './public'
  set :views, 'app/views'
  enable :sessions unless test?
  set :session_secret, "secret"
  use Rack::Flash

  get '/admin' do
    erb :'admin/login'
  end

  post '/admin' do
    @admin = Admin.find_by(name: params[:name])
    binding.pry
    if @admin && @admin.authenticate(params[:password])
      binding.pry
      session[:admin_id] = @admin.id
      redirect "/admin/#{@admin.id}"
    else
      binding.pry
      flash[:message] = "Something went wrong. Please try again."
      @params = params
      erb :'/admin/login'
    end
  end

  get '/admin/:id' do
    @admin = Admin.find(params[:id])
    if @admin == Helpers.current_admin(session)
      erb :'admin/show'
    else
      "You're not an admin"
    end
  end

  get '/admin/:id/users' do
    @admin = Admin.find(params[:id])
    if @admin == Helpers.current_admin(session)
      erb :'admin/users'
    else
      "You're not an admin"
    end
  end

  get '/admin/:id/product' do
    @admin = Admin.find(params[:id])
    if @admin == Helpers.current_admin(session)
      erb :'admin/product'
    else
      "You're not an admin"
    end
  end
end
{'fraction_non_alphanumeric': 0.13785744771660263, 'fraction_numerical': 0.0, 'mean_word_length': 2.6625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3499933', 'n_tokens_mistral': 809, 'n_tokens_neox': 791, 'n_words': 205}