2 # (c) Petr Baudis <pasky@suse.cz>
3 # (c) Jan Krueger <jk@jk.gs>
15 my $gcgi = Girocco
::CGI
->new('User Email & SSH Key Update');
18 unless ($Girocco::Config
::manage_users
) {
19 print "<p>I don't manage users.</p>";
23 if ($cgi->param('mail')) {
24 print "<p>Go away, bot.</p>";
32 $fields = '' if (!$fields);
34 my $authtag = ($auth ?
qq(<input type
="hidden" name
="auth" value
="$auth" />) :
35 qq(<p
>Authorization code
: <input name
="auth" size
="40" /></p>));
39 <input type="hidden" name="name" value="$name" />
41 $fields<p><input type="submit" value="$submit" /></p>
46 if ($cgi->param('name')) {
47 # submitted, let's see
48 # FIXME: racy, do a lock
49 my $name = $gcgi->wparam('name');
50 (Girocco
::User
::valid_name
($name)
51 and Girocco
::User
::does_exist
($name))
52 or $gcgi->err("Username is not registered.");
54 $gcgi->err_check and exit;
57 ($user = Girocco
::User
->load($name)) && valid_email
($user->{email
})
58 or $gcgi->err("Username may not be updated.");
60 $gcgi->err_check and exit;
62 if (!$cgi->param('auth')) {
63 my $auth = $user->gen_auth;
66 open(MAIL
, '|-', '/usr/bin/mail', '-s', "[$Girocco::Config::name] Account update authorization", $user->{email
}) or
67 die "Sorry, could not send authorization code: $!";
71 you have requested an authorization code to be sent to you for updating
72 your account's email and/or SSH keys. If you don't want to actually update
73 your email or SSH keys, just ignore this e-mail. Otherwise, use this code
78 Should you run into any problems, please let us know.
84 print "<p>You should shortly receive an e-mail containing an authorization code.
85 Please enter this code below to update your SSH keys.
86 The code will expire in 24 hours or after you have used it.</p>";
87 _auth_form
($name, "'Login'");
91 print "There currently isn't any authorization code filed under your account. Please <a href=\"edituser.cgi\">generate one</a>.";
96 my $email = $cgi->param('email');
97 my $keys = $cgi->param('keys');
99 my $auth = $gcgi->wparam('auth');
100 if ($auth ne $user->{auth
}) {
101 print '<p>Invalid authorization code, please re-enter or <a href="edituser.cgi">generate a new one</a>.</p>';
102 _auth_form
($name, "'Login'");
106 if (defined($email) && defined($keys)) {
107 # Auth valid, keys given -> save
108 if (($email eq $user->{email
} || $user->update_email($gcgi, $email)) && $user->keys_fill($gcgi)) {
111 print "<p>Your Email & SSH keys have been updated.</p>";
115 # Otherwise pre-fill fields
116 $email = $user->{email
};
117 $keys = $user->{keys};
120 my $emailval = CGI
::escapeHTML
($email);
121 my $keysval = CGI
::escapeHTML
($keys);
123 <p>Authorization code validated (for now).</p>
124 <p>You can paste multiple keys in the box below, each on a separate line.
125 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>
127 <input type="hidden" name="name" value="$name" />
128 <input type="hidden" name="auth" value="$auth" />
130 <tr><td class="formlabel">Login:</td><td class="formdata">$name</td></tr>
131 <tr><td class="formlabel">Email:</td><td><input type="text" name="email" value="$emailval"/></td></tr>
132 <tr><td class="formlabel">Public SSH key(s):</td><td><textarea wrap="off" name="keys" rows="5" cols="80">$keysval</textarea></td></tr>
133 <tr><td class="formlabel"></td><td><input type="submit" value="Update" /></td></tr>
142 <p>Here you can update the email and public SSH keys associated with your user account.
143 These keys are required for you to push to projects.</p>
144 <p>SSH is used for pushing (the <tt>ssh</tt> protocol), your SSH key authenticates you -
145 there is no password (though we recommend that your SSH key is password-protected;
146 use <code>ssh-agent</code> to help your fingers).
147 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt> or <tt>~/.ssh/id_dsa.pub</tt>.
148 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.</p>
150 <p>Please enter your username below;
151 we will send you an email with an authorization code
152 and further instructions.</p>
156 <tr><td class="formlabel">Login:</td><td><input type="text" name="name" /></td></tr>
157 <tr style="display:none"><td class="formlabel">Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
158 <tr><td class="formlabel"></td><td><input type="submit" value="Send authorization code" /></td></tr>