<commit_before># TimeClock V2
# Basic timeclock functionality


require "sinatra"
require 'rubygems'
require 'dm-core'
require 'digest/sha1'

DataMapper.setup(:default, 'mysql://rubytest:rubytestpass@local.derbserv.org/rubytest')

class Punch
  include DataMapper::Resource
  property :id, Serial
  property :username, String
  property :punchtime, DateTime
  property :punchstate, String
end

class User
  include DataMapper::Resource
  property :id, Serial
  property :username, String
  property :password, String
  property :cookie, String
  property :admin, String
end

DataMapper.auto_upgrade!

get '/' do
  username = cookiecheck(request.cookies["MainSiteKey"])
  if !username
    redirect '/login'
  end
  punchstate=getstate(username)

  return <<-EOL
  <title>Basic Timeclockiness</title>
  <body>
  <form method=post action="submit" />
  <input type="submit" value="Punch #{username} #{punchstate}" />
  </form>
  </body>
  EOL
end

post '/submit' do

  username = cookiecheck(request.cookies["MainSiteKey"])
  if !username
    redirect '/login'
  end
  punchstate = getstate(username)

  Punch.create(
    :username =>  username,
    :punchtime  =>  Time.now,
    :punchstate =>  punchstate
  )
  return "Punch #{punchstate} for #{username} successful!"
end

get '/login' do
  return <<-EOL
  <title>Basic Timeclockiness</title>
  <body>You must log in:<br/>
  <form method=post action="loginsubmit" />
Username:<br/>
  <input type="text" name="username" /><br/>
Password:<br/>
  <input type="text" name="password" />
  <input type="submit" value="Log in" />
  </form>
  </body>
  EOL
end

post '/loginsubmit' do
  username=params[:username]
  password=params[:password]
  if passcheck(username,password)
    redirect '/'
  else
    redirect '/login'
  end
  
end


get '/admin' do

end

get '/report' do

end


# Checks for a cookie, returns a username
def cookiecheck(sessioncookie)

  whoitbe = User.first(:cookie => sessioncookie)
  if whoitbe
    loggedusername = whoitbe.username<commit_msg>	modified:   main.rb<commit_after># TimeClock V2
# Basic timeclock functionality

require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'digest/sha1'

# DataMapper.setup(:default, 'mysql://rubytest:rubytestpass@local.derbserv.org/rubytest')
DataMapper.setup(:default, 'sqlite3:timeclock.db')

class Punch
  include DataMapper::Resource
  property :id, Serial
  property :username, String
  property :punchtime, DateTime
  property :punchstate, String
end

class User
  include DataMapper::Resource
  property :id, Serial
  property :username, String
  property :password, String
  property :cookie, String
  property :admin, String
end

DataMapper.auto_upgrade!

get '/' do
  username = cookiecheck(request.cookies["MainSiteKey"])
  if !username
      return <<-EOL
      <title>Basic Timeclockiness</title>
      <body>You must log in:<br/>
      <form method=post action="loginsubmit" />
    Username:<br/>
      <input type="text" name="username" /><br/>
    Password:<br/>
      <input type="text" name="password" />
      <input type="submit" value="Log in" />
      </form>
      </body>
      EOL
  else
  punchstate=getstate(username)

  return <<-EOL
  <title>Basic Timeclockiness</title>
  <body>
  <form method=post action="submit" />
  <input type="submit" value="Punch #{username} #{punchstate}" />
  </form>
  </body>
  EOL
end
end

post '/submit' do

  username = cookiecheck(request.cookies["MainSiteKey"])
  if !username
    redirect '/'
  end
  punchstate = getstate(username)

  Punch.create(
    :username =>  username,
    :punchtime  =>  Time.now,
    :punchstate =>  punchstate
  )
  return "Punch #{punchstate} for #{username} successful!"
end

get '/login' do

end

post '/loginsubmit' do
  username=params[:username]
  password=params[:password]
#  if passcheck(username,password)
    redirect '/'
#  else
#    redirect '/login'
#  end
  
end


get '/admin' do

end

get '/report' do

end


# Checks for a cookie, returns a username
def cookiecheck(sessioncookie)

  whoitbe = User.first(:cookie => sessioncookie)
  if whoitbe
    loggedusername = whoitbe.username
{'fraction_non_alphanumeric': 0.1292352371732817, 'fraction_numerical': 0.0012100677637947724, 'mean_word_length': 3.9437799043062203, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6084148', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1368, 'n_words': 353}