#!/usr/bin/perl -w # --------------------------------------------- # create-user.cgi - Create by Lance Wicks # e-judo.sourceforge.net # This is free open source software! Released under GPL # # Description: # This script adds a new user to the users database # # History: # ======== # 20 December 2003, Lance Wicks - Created initial file. # use strict; # force strict programming controls use CGI qw(:standard); # use the CGI.PM module use lib './MyLib'; # use the modules in MyLib, this is the DBD::Anydata used for database activities use DBI; # This calls the DBI module, which along with the line above allows us to do database activities print header(), start_html("e-Judo Test Area"), h1("CREATE NEW USER"); # This line uses CGI.PM to to create the webpage if (param()){ # If there is a parameter(or parameters) then validate, else show the login screen. # the following lines are excecuted if paramaters HAVE been entered print p("start of the data"); my $ID = param("ID"); # the next few lines alocate the info from the completed form to variables. my $first_name = param("first_name"); my $surname = param("surname"); my $date_of_birth = param("date_of_borth"); my $email = param("email"); my $password = param("ejudopass"); # now give values to the other user data field variables my $active = "NO"; # the user is not immediately active, we will email them first. my $last_login = "now"; # set the last login time to now my $create_date = "now"; # set the date we created this user to now as well my $earnings = 0; # They have not earned any thing yet so set it to Zero my $cash = 50; # This is their cash on hand, lets give them 50 credits by default my $judoka_limit = 1; # They can create 1 Judoka my $sensei_limit = 0; # They can NOT create a sensei (YET) my $dojo_limit = 0; # They can not create a Dojo my $team_limit = 0; # They can not create a team my $rank = "Novice"; # They are a novice user to start with # Add in some data validation here!!!! # Next connect to the database and check if they exist already. print p("about to open the DB"); my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'users', 'CSV', 'data/users.csv', 'ad_catalog'); # Connect to the users.csv data file my $sth = $dbh->prepare("SELECT id FROM users WHERE id = '$ID'"); # select the ID field from the database for the ID enetered by the user $sth->execute(); # excecute the select command above my @result = $sth->fetchrow_array; # this line takes the results of the select and puts it in the array called RESULTS $dbh->disconnect(); # we are done with the datbase for now, so disconnect from it (MAY NOT BE NECESSARY) print p("result = @result"); if (@result) { #if the result array is in existence (ie we found the username) then... print p("Sorry this ID is in use already"); exit; } else { print p("about to insert the new record"); # if the user does not exist then add them! # so connect to the database and insert a record my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'users', 'CSV', 'data/users.csv', 'ad_catalog'); # Connect to the users.csv data file my $sth = $dbh->prepare('INSERT INTO users VALUES ( \" $ID, $first_name, $surname, $date_of_birth, $email, $password, $active, $last_login, $create_date, $earnings, $cash, $judoka_limit, $sensei_limit, $dojo_limit, $team_limit, $rank \" ) '); $sth->execute(); # excecute the command above # $dbh->commit(); $dbh->disconnect(); print p("Inserted Record"); } } else { # The following lines are excecuted only if no parameters have been entered. (Ie when you first arrive) print hr, start_form; # create a form using CGI.PM print p("User ID: ", textfield("ID"), " - This is the ID you will use to login to the system"); # what username do they want. print p("First Name: ", textfield("first_name"), " - This is your REAL name"); # what is their real name print p("Surname: ", textfield("surname"), " - This is your REAL last name"); # what is their real name print p("Date of Birth: ", textfield("date_of_birth"), " - (DD/MM/YYYY) This is your date of birth, used if you ever need to prove who you are"); print p("Email address: ", textfield("email"), " - the email address you would like to use."); print p("Password: ", password_field("ejudopass"), " - Choose a password to use on the system"); print end_form, hr; # end the form } print end_html; # this closes the web page properly