moth/www/cgi-bin/register.cgi

34 lines
967 B
Plaintext
Raw Normal View History

2015-05-26 10:16:22 -06:00
#! /usr/bin/env lua
2015-05-26 10:14:30 -06:00
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
2015-04-21 07:57:11 -06:00
local cgi = require "cgi"
local koth = require "koth"
local team = cgi.fields["n"] or ""
local hash = cgi.fields["h"] or ""
hash = hash:match("[0-9a-f]*")
if ((hash == "") or (team == "")) then
koth.page("Invalid Entry", "Oops! Are you sure you got that right?")
2017-10-11 18:55:34 -06:00
elseif (not koth.anchored_search(koth.path("state/assigned.txt"), hash)) then
koth.page("Invalid Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?")
end
2015-04-21 07:57:11 -06:00
local f = io.open(koth.path("state/teams/" .. hash))
if (f) then
f:close()
koth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
end
2015-04-21 07:57:11 -06:00
local f, err = io.open(koth.path("state/teams/" .. hash), "w+")
if (not f) then
koth.page("Kersplode", err)
end
f:write(team)
f:close()
koth.page("Success", "Okay, your team has been named and you may begin using your hash!")