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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Thu Oct 30 11:57:07 2008 UTC (15 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +46 -20 lines
Pseudo-I18N; Japanese language catalog added

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 require 'texts.pl';
12
13 require Message::CGI::HTTP;
14 require Encode;
15 my $cgi = Message::CGI::HTTP->new;
16 $cgi->{decoder}->{'#default'} = sub {
17 return Encode::decode ('utf-8', $_[1]);
18 };
19
20 our $Lang = 'ja'
21 if $cgi->get_meta_variable ('HTTP_ACCEPT_LANGUAGE') =~ /\bja\b/; ## TODO: ...
22
23 require Message::DOM::DOMImplementation;
24 my $dom = Message::DOM::DOMImplementation->new;
25
26 my $path = $cgi->path_info;
27 $path = '' unless defined $path;
28
29 my @path = split m#/#, percent_decode ($path), -1;
30 shift @path;
31
32 if (@path == 1 and $path[0] eq 'new-user') {
33 if ($cgi->request_method eq 'POST') {
34 lock_start ();
35 binmode STDOUT, ':encoding(utf-8)';
36
37 my $user_id = $cgi->get_parameter ('user-id');
38
39 if ($user_id !~ /\A[0-9a-z-]{4,20}\z/) {
40 print_error (400,
41 q[User id %s is invalid; use characters [0-9a-z-]{4,20}],
42 $user_id);
43 exit;
44 }
45
46 if (get_user_prop ($user_id)) {
47 print_error (400, q[User id %s is already used], $user_id);
48 exit;
49 }
50
51 my $pass_crypted = check_password ($cgi);
52
53 my $user_prop = {id => $user_id, pass_crypted => $pass_crypted};
54 set_user_prop ($user_id, $user_prop);
55
56 regenerate_htpasswd_and_htgroup ();
57 commit ();
58
59 my $user_url = get_absolute_url ('../edit/users/' . $user_id . '/');
60
61 print qq[Status: 201 User registered
62 Location: $user_url
63 Content-Type: text/html; charset=utf-8
64
65 <!DOCTYPE HTML>
66 <html lang=en>
67 <title>];
68 print_text ('User %s registered', sub { print '', htescape ($user_id) });
69 print q[</title>
70 <link rel=stylesheet href="/www/style/html/xhtml">
71 <h1>];
72 print_text ('User %s registered', sub { print '', htescape ($user_id) });
73 print q[</h1><p>];
74 print_text ('Your user account is created successfully.');
75 print q[<p>];
76 print_text ('See %s.', sub {
77 print q[<a href="@{[htescape ($user_url)]}">];
78 print_text ('your user account information page');
79 print q[</a>];
80 });
81 exit;
82 } else {
83 binmode STDOUT, ":encoding(utf-8)";
84 print q[Content-Type: text/html; charset=utf-8
85
86 <!DOCTYPE HTML>
87 <html lang=en>
88 <title>];
89 print_text ('Create a new user account');
90 print q[</title>
91 <link rel=stylesheet href="/www/style/html/xhtml">
92 <h1>];
93 print_text ('Create a new user account');
94 print q[</h1>
95
96 <form action=new-user accept-charset=utf-8 method=post>
97
98 <p><strong>];
99 print_text ('User id');
100 print q[</strong>: <input type=text name=user-id
101 maxlength=20 size=10 required pattern="[0-9a-z-]{4,20}"> (];
102 print_text ('Use [0-9a-z-]{4,20}.');
103 print q[)<p><strong>];
104 print_text ('Password');
105 print q[</strong>: <input type=password name=user-pass
106 size=10 required pattern=".{4,}"> (];
107 print_text ('Type 4 characters at minimum');
108 print q[)<p><strong>];
109 print_text ('Password');
110 print q[</strong> (];
111 print_text ('type again');
112 print q[): <input type=password
113 name=user-pass2 size=10 required pattern=".{4,}">
114
115 <p><input type=submit value="];
116 print_text ('Create');
117 print q["></form>];
118 exit;
119 }
120 } elsif (@path == 0) {
121 my $root_url = get_absolute_url ('add/new-user');
122
123 print qq[Status: 301 Moved permanently
124 Location: $root_url
125 Content-Type: text/html; charset=us-ascii
126
127 See <a href="@{[htescape ($root_url)]}">other page</a>.];
128 exit;
129 }
130
131 print_error (404, 'Not found');
132 exit;
133
134 sub percent_decode ($) {
135 return $dom->create_uri_reference ($_[0])
136 ->get_iri_reference
137 ->uri_reference;
138 } # percent_decode
139
140 sub get_absolute_url ($) {
141 return $dom->create_uri_reference ($_[0])
142 ->get_absolute_reference ($cgi->request_uri)
143 ->get_iri_reference
144 ->uri_reference;
145 } # get_absolute_url

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24