#!/usr/bin/perl
# EasyHost
# Built by CyberScript
# Website: http://www.cyberscript.net
# Email: rcampbell@cyberscript.net
# (C) Copyright 2001, All Rights Reserved.
#####################################################
# The following code may not be modified            #
# or redistributed by anyone other then CyberScript #
#####################################################

$pwd = ($0 =~ /^(.+)[\/\\]/)[0] || '.';
require ("$pwd/cs-lib.pl");

&validate if ($tokens{code} || $ENV{REQUEST_METHOD} eq 'POST');

print &ct("text/html").&display("validate");

exit (0);

sub validate {
	&error("The validation code field is required","code") if (!$tokens{code});
	&error("The validation code field contains invalid characters","code") if ($tokens{code} !~ /^[\w]{15}$/);

	$tokens{name} = &file_read("$tokens{data_dir}/validation/$tokens{code}");

	&error("The validation code you entered wasn't found in our database","code") if (!$tokens{name});
	&error("The user attached to this validation code is no longer in our database","code") if (!&user_exist($tokens{name}));

	if (!$tokens{error_message}) {
		my %data = ();

		$data{status} = 1;

		&user_modify($tokens{name},%data);

		$tokens{c} = 'done';

		&notice('validate','validated their account');
	} else {
		&error("The validation code you entered wasn't found in our database","code");
	}
}