editproj: improve mirror and password handling
[girocco/ztw.git] / cgi / pwuser.cgi
blob39c352d1fff705ac601378623103c04e32aeae53
1 #!/usr/bin/perl
2 # (c) Zachary T Welch <zw@superlucidity.net>
3 # (c) Petr Baudis <pasky@suse.cz>
4 # GPLv2
6 use strict;
7 use warnings;
9 use lib qw(/home/repo/repomgr/cgi);
10 use Git::RepoCGI;
12 my $repo = Git::RepoCGI->new('Forgotten User Password');
14 my $name = $repo->sparam('name');
15 my $user = Git::RepoCGI::User->load($name);
16 my $mail = $user->{email};
18 if ($repo->sparam('y0')) {
19 # submitted
20 my $newpwd = genpwd();
22 # TODO: get hard-coded domain name from a config file
23 my $domain = 'repo.or.cz';
24 my $subject = "[$domain] New password for user $name";
25 open (M, '|-', 'mail', '-s', $subject, $mail)
26 or $repo->bye("Cannot spawn mail: $!");
27 print M <<EOT;
28 Hello,
30 Somebody requested the password for user '$name' to be reset,
31 so you are receiving the new password:
33 $newpwd
35 If you did not request the password to be reset, then we apologize.
36 In any event, you must now use this new password to change the settings
37 for the '$name' account.
39 If you would like to change your password again, you can use this quick
40 link to your account settings page:
42 http://repo.or.cz/m/edituser.cgi?name=$name
44 Have fun!
45 EOT
46 close M or $repo->bye("Sending mail to $mail for $name failed: $!");
48 $user->update_password($newpwd);
50 print "<p>Account password has been reset. Have a nice day.</p>\n";
51 exit;
54 print <<EOT;
55 <p>
56 If you have forgotten the password for your user account,
57 it can be reset to a random string that will be mailed to your
58 registered e-mail address.
59 </p>
60 <form method="post">
61 <input type="text" name="name" value="$name" />
62 <p><input type="submit" name="y0" value="Reset Password" /></p>
63 </form>
64 EOT