moth/www/cgi-bin/register.cgi

34 lines
961 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 moth = require "moth"
local team = cgi.fields["n"] or ""
local hash = cgi.fields["h"] or ""
hash = hash:match("[0-9a-f]*")
if ((hash == "") or (team == "")) then
moth.page("Invalid Entry", "Oops! Are you sure you got that right?")
elseif (not moth.anchored_search(moth.path("assigned.txt"), hash)) then
moth.page("Invalid Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?")
end
local f = io.open(moth.path("state/teams/" .. hash))
if (f) then
f:close()
moth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
end
local f, err = io.open(moth.path("state/teams/" .. hash), "w+")
2015-04-21 07:57:11 -06:00
if (not f) then
moth.page("Kersplode", err)
2015-04-21 07:57:11 -06:00
end
f:write(team)
f:close()
moth.page("Success", "Okay, your team has been named and you may begin using your hash!")