*.cgi: replace site-specific constansts
[girocco/ztw.git] / cgi / pwuser.cgi
blobd15244d4576aed014639eab1f3bb220a9b11cceb
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 my $domain = $repo->site_domain;
23 my $subject = "[$domain] New password for user $name";
24 open (M, '|-', 'mail', '-s', $subject, $mail)
25 or $repo->bye("Cannot spawn mail: $!");
26 print M <<EOT;
27 Hello,
29 Somebody requested the password for user '$name' to be reset,
30 so you are receiving the new password:
32 $newpwd
34 If you did not request the password to be reset, then we apologize.
35 In any event, you must now use this new password to change the settings
36 for the '$name' account.
38 If you would like to change your password again, you can use this quick
39 link to your account settings page:
41 http://$domain/m/edituser.cgi?name=$name
43 Have fun!
44 EOT
45 close M or $repo->bye("Sending mail to $mail for $name failed: $!");
47 $user->update_password($newpwd);
49 print "<p>Account password has been reset. Have a nice day.</p>\n";
50 exit;
53 print <<EOT;
54 <p>
55 If you have forgotten the password for your user account,
56 it can be reset to a random string that will be mailed to your
57 registered e-mail address.
58 </p>
59 <form method="post">
60 <input type="text" name="name" value="$name" />
61 <p><input type="submit" name="y0" value="Reset Password" /></p>
62 </form>
63 EOT