Added use lib for clearscm
[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 use lib "$FindBin::Bin/../../lib";
24
25 use MAPS;
26 use MAPSWeb;
27
28 use CGI qw (:standard);
29
30 my $userid            = param('userid');
31 my $fullname          = param('fullname');
32 my $email             = param('email');
33 my $password          = param('password');
34 my $repeated_password = param('repeated_password');
35 my $mapspop           = param('MAPSPOP');
36 my $history           = param('history');
37 my $days              = param('days');
38 my $dates             = param('dates');
39 my $tag_and_forward   = param('tag_and_forward');
40
41 sub MyError {
42   my $errmsg = shift;
43
44   $userid = Heading (
45     'getcookie',
46     '',
47     'Signup',
48     'Signup'
49   );
50
51   NavigationBar $userid;
52
53   print h2 {-align => 'center',
54             -class => 'error'}, 'Error: ' . $errmsg;
55
56   Footing;
57
58   exit 1;
59 } # MyError
60
61 sub Body {
62   # Check required fields
63   if ($userid eq '' ) {
64     MyError 'You must specify a userid!';
65   } # if
66   if ($email eq '' ) {
67     MyError 'You must specify an email address!';
68   } # if
69   if ($password eq '') {
70     MyError 'You must specify a password!';
71   } # if
72   if ($fullname eq '') {
73     MyError 'You must specify your full name!';
74   } # if
75
76   # Password field checks
77   if (length $password < 6) {
78     MyError 'Password must be longer than 6 characters!';
79   } # if
80   if ($password ne $repeated_password) {
81     MyError 'Passwords do not match';
82   } # if
83
84   my $status = AddUser(
85     userid   => $userid,
86     name     => $fullname,
87     email    => $email,
88     password => $password,
89   );
90
91   if ($status != 0) {
92     MyError 'Username already exists';
93   } # if
94
95   my %options = (
96     MAPSPOP       => $mapspop,
97     History       => $history,
98     Page          => $days,
99     Dates         => $dates,
100     'Tag&Forward' => $tag_and_forward,
101   );
102
103   $status = AddUserOptions($userid, %options);
104
105   if ($status == 0) {
106     print redirect ("/maps/?errormsg=User account \"$userid\" created.<br>You may now login");
107   } elsif ($status == 1) {
108     MyError "Username \"$userid\" already exists";
109   } else {
110     MyError "Unable to add useropts for \"$userid\"";
111   } # if
112   
113   return;
114 } # Body
115
116 Body;