edituser.cgi: Do not show keys list on error
[girocco.git] / cgi / reguser.cgi
blob87a86b6a9057ea32d1684fcc1a3703f1753b74f1
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::User;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('User Registration');
15 my $cgi = $gcgi->cgi;
17 unless ($Girocco::Config::manage_users) {
18 print "<p>I don't manage users.</p>";
19 exit;
22 if ($cgi->param('mail')) {
23 print "<p>Go away, bot.</p>";
24 exit;
27 my $y0 = $cgi->param('y0') || '';
28 if ($cgi->param('name') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
29 # submitted, let's see
30 # FIXME: racy, do a lock
31 my $name = $gcgi->wparam('name');
32 if (!Girocco::User::valid_name($name)) {
33 $gcgi->err("Invalid user name.");
34 $gcgi->err_check;
35 } elsif (Girocco::User::does_exist($name)) {
36 $gcgi->err("A user with that name already exists.");
37 $gcgi->err_check;
38 } else {
39 my $user = Girocco::User->ghost($name);
40 if ($user->cgi_fill($gcgi)) {
41 $user->conjure;
42 my $keysdiv = '';
43 my $keylist = $user->keys_html_list;
44 if ($keylist) {
45 $keysdiv = <<EOT;
47 <div id="keys"><p>The following keys have been registered for user $name as
48 shown below along with their <tt>ssh-keygen -l</tt> fingerprint:</p>
49 $keylist</div>
50 EOT
52 print <<EOT;
53 <p>User $name successfully registered.</p>
54 <p>Project administrators can now give you push access to their projects.</p>
55 <p>Congratulations, and have a lot of fun!</p>$keysdiv
56 EOT
57 exit;
62 my $httpspara = '';
63 $httpspara = <<EOT if $Girocco::Config::httpspushurl;
64 <p>Please be sure to include at least one RSA key (starts with the <tt>ssh-rsa</tt> prefix) in
65 order to enable HTTPS pushing. <sup><a href="@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html">(learn more)</a></sup><br />
66 X.509 (e.g. OpenSSL) format public keys can be converted to SSH .pub format with the
67 <a href="http://repo.or.cz/w/ezcert.git/blob/master:/ConvertPubKey">ConvertPubKey</a> utility thus obviating the
68 need for OpenSSH if all pushing is to be done using HTTPS (see the example in the TIPS section of the <tt>ConvertPubKey -h</tt> output).</p>
69 EOT
70 my $dsablurb = '';
71 $dsablurb = ' or <tt>~/.ssh/id_dsa.pub</tt>' unless $Girocco::Config::disable_dsa;
72 print <<EOT;
73 <p>Here you can register a user.
74 You need to register a user so that you can push to the hosted projects.</p>
75 <p>SSH (the <tt>ssh</tt> protocol) or HTTPS is used for pushing, your SSH key authenticates you -
76 there is no password (though we recommend that your SSH key is password-protected;
77 use <code>ssh-agent</code> to help your fingers).
78 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt>$dsablurb.
79 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.
80 You can paste multiple keys in the box below, each on a separate line.
81 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>
82 $httpspara<p>We won't bother to verify your email contact,
83 but fill in something sensible in your own interest
84 so that we may contact you or confirm your identity should the need arise.
85 We also need to send you an e-mail if you want to update your SSH keys later.</p>
86 $Girocco::Config::legalese
87 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">
88 <table class="form">
89 <tr><td class="formlabel">Login:</td><td><input type="text" name="name" /></td></tr>
90 <tr><td class="formlabel">Email:</td><td><input type="text" name="email" /></td></tr>
91 <tr><td class="formlabel">Public SSH key(s):</td><td><textarea wrap="off" name="keys" rows="5" cols="80"></textarea></td></tr>
92 <tr style="display:none"><td class="formlabel">Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
93 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
94 </table>
95 </form>
96 EOT