#! /usr/bin/perl ################################################################################ # # # login.cgi # # --------- # # INDIW-2000 / Futurama-prosjektet # # # ################################################################################ # # # This file is © Arne Sommer - rev. 10. May 2000. # # # ################################################################################ use FindBin; use lib "$FindBin::Bin/mylib"; # Get the directory where the program resides, and add the 'mylib' # # subdirectory to the library lookup table. # use CGI; require "lib/indifu.pl"; ## Language Specific ########################################################### my($lang) = language(); # Get the user's prefered language. # ################################################################################ error_doc($lang) unless connect_db(); # Die gracefully if the database failed to respond. # ################################################################################ $q = new CGI; my($header, $user_id) = cookie_header($q); # Set up (parse and maintain) the cookie. # my(@links); push(@links, $header); ## The rest of the document #################################################### push(@links, start_doc($q, "indifu $l_title{$lang}")); push(@links, $q->h2($l_title{$lang}), "\n"); ## Both email address and password given ####################################### my($reg_ok) = 0; if ($q->param('password') && $q->param('mail')) { ## An existing user ########################################################## if (check_password($user_id, $q->param('mail'), $q->param('password'))) { print @links; @links = (); box_text($l_reg{$lang}, "#00FF00"); $reg_ok++; } ## An old user ############################################################### else { my($new_user_id) = check_password(undef, $q->param('mail'), $q->param('password')); if ($new_user_id) ## Logged in with another user_id than the one given by the system. { $user_id = $new_user_id; $reg_ok++; my($header, $user_id) = cookie_header($q, $user_id); # Set up (parse and maintain) the cookie. # @links = ($header, start_doc($q, "indifu $l_title{$lang}"), $q->h2($l_title{$lang}), "\n"); print @links; @links = (); print $q->em($l_recov{$lang}), $q->p; # Recovered old user ID. # } else { print @links; @links = (); print $q->em($l_err{$lang}); # Error. # } } } ## Email address given ######################################################### elsif ($q->param('mail')) { print @links; @links = (); my($mail) = $q->param('mail'); my($password) = random_password(6); ## Check if the mail address is in the database already. ###################### my($id) = mail2user($mail); if ($id) { set_password($id, $password); } else { set_password($user_id, $password); set_mailaddress($user_id, $mail, $password); } send_mail($mail, 'INDIFU Story Site', "$l_six{$lang}: '$password'.") ? box_text($l_ma_pa{$lang}, "#00FF00") # OK. # : box_text($l_no_pa{$lang}, "#FF0000"); # Error. # } ################################################################################ unless ($reg_ok) { print @links; @links = (); unless ($q->param('mail')) { print $l_se_ma{$lang}, $q->p; } my($name) = $q->remote_user . '@'; my($host) = $q->remote_host; $name .= $host unless $host =~ /^\d+\.\d+\.\d+\.\d+$/; # But skip this if the host is on the 'xxx.xxx.xxx.xxx' digit form. print $q->startform, $l_email{$lang}, $q->textfield('mail', $name, 50), $q->br, $l_passw{$lang}, $q->password_field('password', "", 6), "   ", $q->submit('form_1','Send'), $q->br, $q->endform; print $q->hr; } ## Finished #################################################################### print @links; @links = (); push(@links, $q->a({-href=>"index.cgi"}, $i_main{$lang})); push(@links, $q->a({-href=>"help.cgi?help=reg"}, $i_help{$lang})); print $q->p, join(" | ", @links), $q->p; print bottom_line(), $q->end_html(); disconnect_db(); ################################################################################