83e459e1c4692d1d259942a2859144cc171fea4c
[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
20 local $0 = $FindBin::Script;
21
22 use lib "$FindBin::Bin/../lib";
23
24 use MAPS;
25 use MAPSWeb;
26
27 use CGI qw (:standard);
28
29 my $userid            = param('userid');
30 my $fullname          = param('fullname');
31 my $email             = param('email');
32 my $password          = param('password');
33 my $repeated_password = param('repeated_password');
34 my $mapspop           = param('MAPSPOP');
35 my $history           = param('history');
36 my $days              = param('days');
37 my $dates             = param('dates');
38 my $tag_and_forward   = param('tag_and_forward');
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(
84     userid   => $userid,
85     name     => $fullname,
86     email    => $email,
87     password => $password,
88   );
89
90   if ($status != 0) {
91     MyError 'Username already exists';
92   } # if
93
94   my %options = (
95     MAPSPOP       => $mapspop,
96     History       => $history,
97     Page          => $days,
98     Dates         => $dates,
99     'Tag&Forward' => $tag_and_forward,
100   );
101
102   $status = AddUserOptions($userid, %options);
103
104   if ($status == 0) {
105     print redirect ("/maps/?errormsg=User account \"$userid\" created.<br>You may now login");
106   } elsif ($status == 1) {
107     MyError "Username \"$userid\" already exists";
108   } else {
109     MyError "Unable to add useropts for \"$userid\"";
110   } # if
111   
112   return;
113 } # Body
114
115 Body;