<commit_before>APP_ROOT = File.dirname(__FILE__)

require 'rubygems'
require 'sinatra/base'
require "sinatra/reloader"
require 'haml'

class GitLabTimeTracking < Sinatra::Base
  configure :development do
    register Sinatra::Reloader
  end

  set :database_file, "#{APP_ROOT}/config/database.yml"
  set :sessions, true

  require 'sinatra/activerecord'
  require './helpers/render_partial'
  require './lib/network'
  require './models/user'
  require './models/time_log'

  get '/' do
    authenticate_user!

    @day_from = 1.weeks.ago.to_date
    @day_to = Date.today
    @time_logs = TimeLog.where(user_id: current_user.id).where("day >= ? AND day <= ?", @day_from, @day_to)
    @days = (@day_from..@day_to).to_a

    haml :index
  end

  get '/profile' do
    authenticate_user!

    haml :profile
  end

  get '/login' do
    haml :login
  end

  get '/logout' do
    sign_out
    redirect '/'
  end

  post '/user_sessions' do
    user = User.authenticate(params[:user_session])

    if user && sign_in(user)
      redirect '/'
    else
      haml :login
    end
  end

  get '/log_time' do
    haml :log_time
  end

  post '/create_time_log' do
    time_log = TimeLog.new(params['time_log'])
    time_log.user_id = current_user.id

    if time_log.save
      redirect '/'
    else
      haml :log_time
    end
  end


  helpers do
    def current_user
      @current_user ||= begin
                          if session[:current_user]
                            Marshal.load(session[:current_user])
                          end
                        end
    end

    def sign_in(user)
      session[:current_user] = Marshal.dump user
    end

    def sign_out
      session[:current_user] = nil
    end

    def authenticate_user!<commit_msg>Require auth for time logging<commit_after>APP_ROOT = File.dirname(__FILE__)

require 'rubygems'
require 'sinatra/base'
require "sinatra/reloader"
require 'haml'

class GitLabTimeTracking < Sinatra::Base
  configure :development do
    register Sinatra::Reloader
  end

  set :database_file, "#{APP_ROOT}/config/database.yml"
  set :sessions, true

  require 'sinatra/activerecord'
  require './helpers/render_partial'
  require './lib/network'
  require './models/user'
  require './models/time_log'

  get '/' do
    authenticate_user!

    @day_from = 1.weeks.ago.to_date
    @day_to = Date.today
    @time_logs = TimeLog.where(user_id: current_user.id).where("day >= ? AND day <= ?", @day_from, @day_to)
    @days = (@day_from..@day_to).to_a

    haml :index
  end

  get '/profile' do
    authenticate_user!

    haml :profile
  end

  get '/login' do
    haml :login
  end

  get '/logout' do
    sign_out
    redirect '/'
  end

  post '/user_sessions' do
    user = User.authenticate(params[:user_session])

    if user && sign_in(user)
      redirect '/'
    else
      haml :login
    end
  end

  get '/log_time' do
    authenticate_user!

    haml :log_time
  end

  post '/create_time_log' do
    authenticate_user!

    time_log = TimeLog.new(params['time_log'])
    time_log.user_id = current_user.id

    if time_log.save
      redirect '/'
    else
      haml :log_time
    end
  end


  helpers do
    def current_user
      @current_user ||= begin
                          if session[:current_user]
                            Marshal.load(session[:current_user])
                          end
                        end
    end

    def sign_in(user)
      session[:current_user] = Marshal.dump user
    end

    def sign_out
      session[:current_user] = nil
    end

    def authenticate_user!
{'fraction_non_alphanumeric': 0.10302351623740201, 'fraction_numerical': 0.0005599104143337066, 'mean_word_length': 2.317548746518106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6446694', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1172, 'n_words': 271}