/[suikacvs]/test/suika-accounts/add.cgi
Suika

Contents of /test/suika-accounts/add.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Oct 29 16:27:15 2008 UTC (16 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.1: +1 -0 lines
Properties

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use lib qw[/home/httpd/html/www/markup/html/whatpm
5     /home/wakaba/work/manakai2/lib];
6    
7     use CGI::Carp qw[fatalsToBrowser];
8     require Message::CGI::Carp;
9    
10     require 'users.pl';
11    
12     require Message::CGI::HTTP;
13     require Encode;
14     my $cgi = Message::CGI::HTTP->new;
15     $cgi->{decoder}->{'#default'} = sub {
16     return Encode::decode ('utf-8', $_[1]);
17     };
18    
19     require Message::DOM::DOMImplementation;
20     my $dom = Message::DOM::DOMImplementation->new;
21    
22     my $path = $cgi->path_info;
23     $path = '' unless defined $path;
24    
25     my @path = split m#/#, percent_decode ($path), -1;
26     shift @path;
27    
28     if (@path == 1 and $path[0] eq 'new-user') {
29     if ($cgi->request_method eq 'POST') {
30     lock_start ();
31     binmode STDOUT, ':encoding(utf-8)';
32    
33     my $user_id = $cgi->get_parameter ('user-id');
34    
35     if ($user_id !~ /\A[0-9a-z-]{4,20}\z/) {
36     print_error (400, qq[User id "$user_id" is invalid; use characters [0-9a-z-]{4,20}]);
37     exit;
38     }
39    
40     if (get_user_prop ($user_id)) {
41     print_error (400, qq[User id "$user_id" is already used]);
42     exit;
43     }
44    
45     my $pass_crypted = check_password ($cgi);
46    
47     my $user_prop = {id => $user_id, pass_crypted => $pass_crypted};
48     set_user_prop ($user_id, $user_prop);
49    
50 wakaba 1.2 regenerate_htpasswd_and_htgroup ();
51 wakaba 1.1 commit ();
52    
53     my $user_url = get_absolute_url ('../edit/users/' . $user_id . '/');
54    
55     print qq[Status: 201 User registered
56     Location: $user_url
57     Content-Type: text/html; charset=utf-8
58    
59     <!DOCTYPE HTML>
60     <html lang=en>
61     <title>User "@{[htescape ($user_id)]}" registered</title>
62     <link rel=stylesheet href="/www/style/html/xhtml">
63     <h1>User "@{[htescape ($user_id)]}" registered</h1>
64     <p>Your user account is created successfully.
65     <p>See <a href="@{[htescape ($user_url)]}">your user account information page</a>.];
66     exit;
67     } else {
68     binmode STDOUT, ":encoding(utf-8)";
69     print qq[Content-Type: text/html; charset=utf-8
70    
71     <!DOCTYPE HTML>
72     <html lang=en>
73     <title>Create a new user account</title>
74     <link rel=stylesheet href="/www/style/html/xhtml">
75     <h1>Create a new user account</h1>
76    
77     <form action=new-user accept-charset=utf-8 method=post>
78    
79     <p><strong>User id</strong>: <input type=text name=user-id
80     maxlength=20 size=10 required pattern="[0-9a-z-]{4,20}"
81     title="Use a string of characters 'a'..'z', '0'..'9', and '-' with length 4..10 (inclusive)">
82    
83     <p><strong>Password</strong>: <input type=password name=user-pass
84     size=10 required pattern=".{4,}" title="Type 4 characters at minimum">
85    
86     <p><strong>Password</strong> (type again): <input type=password
87     name=user-pass2 size=10 required pattern=".{4,}">
88    
89     <p><input type=submit value=Create>
90    
91     </form>];
92     exit;
93     }
94     } elsif (@path == 0) {
95     my $root_url = get_absolute_url ('add/new-user');
96    
97     print qq[Status: 301 Moved permanently
98     Location: $root_url
99     Content-Type: text/html; charset=us-ascii
100    
101     See <a href="@{[htescape ($root_url)]}">other page</a>.];
102     exit;
103     }
104    
105     print_error (404, 'Not found');
106     exit;
107    
108     sub percent_decode ($) {
109     return $dom->create_uri_reference ($_[0])
110     ->get_iri_reference
111     ->uri_reference;
112     } # percent_decode
113    
114     sub get_absolute_url ($) {
115     return $dom->create_uri_reference ($_[0])
116     ->get_absolute_reference ($cgi->request_uri)
117     ->get_iri_reference
118     ->uri_reference;
119     } # get_absolute_url

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24