fb4541ed2e048719862d47f2ac5fd46370646a8f
[clearscm.git] / maps / bin / signup.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: signup.cgi,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Sign up a MAPS user
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19 $0 = $FindBin::Script;
20
21 use lib "$FindBin::Bin/../lib";
22
23 use MAPS;
24 use MAPSWeb;
25
26 use CGI qw (:standard);
27
28 my $userid            = param('userid');
29 my $fullname          = param('fullname');
30 my $email             = param('email');
31 my $password          = param('password');
32 my $repeated_password = param('repeated_password');
33 my $mapspop           = param('MAPSPOP');
34 my $history           = param('history');
35 my $days              = param('days');
36 my $dates             = param('dates');
37 my $tag_and_forward   = param('tag_and_forward');
38 my $message;
39
40 sub MyError {
41   my $errmsg = shift;
42
43   $userid = Heading (
44     'getcookie',
45     '',
46     'Signup',
47     'Signup'
48   );
49
50   NavigationBar $userid;
51
52   print h2 {-align => 'center',
53             -class => 'error'}, 'Error: ' . $errmsg;
54
55   Footing;
56
57   exit 1;
58 } # MyError
59
60 sub Body {
61   # Check required fields
62   if ($userid eq '' ) {
63     MyError 'You must specify a userid!';
64   } # if
65   if ($email eq '' ) {
66     MyError 'You must specify an email address!';
67   } # if
68   if ($password eq '') {
69     MyError 'You must specify a password!';
70   } # if
71   if ($fullname eq '') {
72     MyError 'You must specify your full name!';
73   } # if
74
75   # Password field checks
76   if (length $password < 6) {
77     MyError 'Password must be longer than 6 characters!';
78   } # if
79   if ($password ne $repeated_password) {
80     MyError 'Passwords do not match';
81   } # if
82
83   my $status = AddUser($userid, $fullname, $email, $password);
84
85   if ($status ne 0) {
86     MyError 'Username already exists';
87   } # if
88
89   my %options = (
90     MAPSPOP       => $mapspop,
91     History       => $history,
92     Page          => $days,
93     Dates         => $dates,
94     'Tag&Forward' => $tag_and_forward,
95   );
96
97   my $status = AddUserOptions($userid, %options);
98
99   if ($status == 0) {
100     print redirect ("/maps/?errormsg=User account \"$userid\" created.<br>You may now login");
101   } elsif ($status == 1) {
102     MyError "Username \"$userid\" already exists";
103   } else {
104     MyError "Unable to add useropts for \"$userid\"";
105   } # if
106 } # Body
107
108 Body;