#!/usr/bin/perl ########################################################################### # User Creation. # # This program will be used to create users. # # (c) 2002 The Stigmata Organization ############################################################################ # Uses and Requires use lib qw( . ); use CGI; use CGI::Carp qw( fatalsToBrowser ); use DBI; use DTO::Site; use strict; # Run Main main(); # Sub It sub main { # Create CGI Object my $q = CGI->new(); # Create DTO Site Object my $dtos = DTO::Site->new($q); # Generate Page print $dtos->generate_top(); print $dtos->revnavbar(); print main_page($q); print $dtos->generate_bottom(); } sub main_page { # Passed Q my $q = shift; # HTML Variable my $html; # Where do you want to go today? if ($q->param('done') == 1) { $html .= process_form($q); } else { $html .= create_form($q); } return $html; } sub create_form { # Passed Q my $q = shift; # HTML Variable my $html; # Header $html .= $q->h2("Create a New User"); # Make My Form $html .= $q->startform(); $html .= $q->hidden(-name=>'done', -value=>1); $html .= $q->table( $q->TR( $q->td($q->b("First Name")), $q->td($q->b("Last Name")) ), $q->TR( $q->td($q->textfield(-name=>'fname', -size=>25)), $q->td($q->textfield(-name=>'lname', -size=>25)) ), $q->TR( $q->td($q->b("User Name")), $q->td($q->b("E-Mail Address")) ), $q->TR( $q->td($q->textfield(-name=>'username', -size=>25, -maxlength=>25)), $q->td($q->textfield(-name=>'email', -size=>25, -maxlength=>25)) ), $q->TR( $q->td($q->b("Password")), $q->td($q->b("Re-Type Password")) ), $q->TR( $q->td($q->password_field(-name=>'passwd1', -size=>25, -maxlength=>25)), $q->td($q->password_field(-name=>'passwd2', -size=>25, -maxlength=>25)) ), $q->TR( $q->td($q->b("AIM")), $q->td($q->b("Yahoo IM")) ), $q->TR( $q->td($q->textfield(-name=>'aim', -size=>25, -maxlength=>50)), $q->td($q->textfield(-name=>'yahoo', -size=>25, -maxlength=>50)) ), $q->TR( $q->td($q->b("ICQ")), $q->td($q->b("MSN")) ), $q->TR( $q->td($q->textfield(-name=>'icq', -size=>25, -maxlength=>50)), $q->td($q->textfield(-name=>'msn', -size=>25, -maxlength=>50)) ), $q->TR( $q->td({-colspan=>2}, $q->checkbox(-name=>'privacy', -value=>1, -label=>"Click here to have your information kept private")) ), $q->TR( $q->td($q->submit(-name=>' Create User ')), $q->td($q->reset(-name=>' Clear All Fields ')), ) ); $html .= $q->endform(); $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; # Return Info return $html; } sub process_form { # Passed Q my $q = shift; # HTML Var my $html; # Dump #$html .= $q->Dump(); # Error Checking my @errors = checkerrors($q); if (@errors) { $html = $q->b("Please correct the following errors and resubmit:") . $q->p; $html .= ""; $html .= $q->p; $html .= create_form($q); return $html; } # Database Information my $database = "dtorg"; my $host = "wicked.stigmata.org"; my $data_source = "DBI:mysql:$database;host=$host"; my $username = "skadz"; my $password = "egenera"; my $dbh = DBI->connect( $data_source, $username, $password); if (!$dbh) { die "Can't connect to $data_source:" . $dbh->errstr. "\n"; } my $sth = $dbh->prepare(qq( INSERT INTO users (user_name, user_passwd, user_fname, user_lname, user_email, user_aim, user_yahoo, user_icq, user_msn, user_privacy) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) )); $sth->bind_param(1, $q->param('username')); $sth->bind_param(2, $q->param('passwd1')); $sth->bind_param(3, $q->param('fname')); $sth->bind_param(4, $q->param('lname')); $sth->bind_param(5, $q->param('email')); $sth->bind_param(6, $q->param('aim')); $sth->bind_param(7, $q->param('yahoo')); $sth->bind_param(8, $q->param('icq')); $sth->bind_param(9, $q->param('msn')); $sth->bind_param(10, $q->param('privacy')); $sth->execute || die "Unable to execute: " . $dbh->errstr; $dbh->disconnect; $sth->finish; $html .= $q->b("User " . $q->param('username') . " Created."); $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; $html .= $q->br . $q->br . $q->br . $q->br . $q->br . $q->br . $q->br; # Return Page return $html; } sub checkerrors { # Passed Q my $q = shift; # Error List my @errors = (); # Check all my Data if ($q->param('fname') =~ /^\s*$/) { push @errors, "First Name is Missing"; } if ($q->param('lname') =~ /^\s*$/) { push @errors, "Last Name is Missing"; } if ($q->param('username') =~ /^\s*$/) { push @errors, "User Name is Missing"; } if ($q->param('email') =~ /^\s*$/) { push @errors, "E-Mail Address is Missing"; } if ($q->param('passwd1') =~ /^\s*$/) { push @errors, "Password is Missing"; } if ($q->param('passwd2') =~ /^\s*$/) { push @errors, "Re-Type of Password is Missing"; } if ($q->param('passwd1') != $q->param('passwd2')) { push @errors, "Passwords Do Not Match"; } # Check for User Name Dupe # Database Information my $database = "dtorg"; my $host = "wicked.stigmata.org"; my $data_source = "DBI:mysql:$database;host=$host"; my $username = "skadz"; my $password = "egenera"; my $dbh = DBI->connect( $data_source, $username, $password); if (!$dbh) { die "Can't connect to $data_source:" . $dbh->errstr. "\n"; } my $sth = $dbh->prepare(qq( SELECT COUNT(user_id) CNT FROM users WHERE UPPER(?) = UPPER(user_name) )); $sth->bind_param(1, $q->param('username')); $sth->execute || die "Unable to execute: " . $dbh->errstr; my $ref = $sth->fetchrow_hashref(); if ($ref->{'CNT'} != 0) { push @errors, "Username already exists"; } $dbh->disconnect; $sth->finish; return @errors; }