summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-sysadm/2011-January/001717.html
diff options
context:
space:
mode:
Diffstat (limited to 'zarb-ml/mageia-sysadm/2011-January/001717.html')
-rw-r--r--zarb-ml/mageia-sysadm/2011-January/001717.html501
1 files changed, 501 insertions, 0 deletions
diff --git a/zarb-ml/mageia-sysadm/2011-January/001717.html b/zarb-ml/mageia-sysadm/2011-January/001717.html
new file mode 100644
index 000000000..85699dda0
--- /dev/null
+++ b/zarb-ml/mageia-sysadm/2011-January/001717.html
@@ -0,0 +1,501 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<HTML>
+ <HEAD>
+ <TITLE> [Mageia-sysadm] [249] commit implement forgot_password patch from Maarten Vanraes
+ </TITLE>
+ <LINK REL="Index" HREF="index.html" >
+ <LINK REL="made" HREF="mailto:mageia-sysadm%40mageia.org?Subject=Re%3A%20%5BMageia-sysadm%5D%20%5B249%5D%20commit%20implement%20forgot_password%20patch%20from%0A%09Maarten%20Vanraes&In-Reply-To=%3C20110107232015.1D80741BF8%40valstar.mageia.org%3E">
+ <META NAME="robots" CONTENT="index,nofollow">
+ <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
+ <LINK REL="Previous" HREF="001716.html">
+ <LINK REL="Next" HREF="001719.html">
+ </HEAD>
+ <BODY BGCOLOR="#ffffff">
+ <H1>[Mageia-sysadm] [249] commit implement forgot_password patch from Maarten Vanraes</H1>
+ <B>root at mageia.org</B>
+ <A HREF="mailto:mageia-sysadm%40mageia.org?Subject=Re%3A%20%5BMageia-sysadm%5D%20%5B249%5D%20commit%20implement%20forgot_password%20patch%20from%0A%09Maarten%20Vanraes&In-Reply-To=%3C20110107232015.1D80741BF8%40valstar.mageia.org%3E"
+ TITLE="[Mageia-sysadm] [249] commit implement forgot_password patch from Maarten Vanraes">root at mageia.org
+ </A><BR>
+ <I>Sat Jan 8 00:20:15 CET 2011</I>
+ <P><UL>
+ <LI>Previous message: <A HREF="001716.html">[Mageia-sysadm] [248] commit spec file from Maarten Vanraes
+</A></li>
+ <LI>Next message: <A HREF="001719.html">[Mageia-sysadm] [249] commit implement forgot_password patch from Maarten Vanraes
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#1717">[ date ]</a>
+ <a href="thread.html#1717">[ thread ]</a>
+ <a href="subject.html#1717">[ subject ]</a>
+ <a href="author.html#1717">[ author ]</a>
+ </LI>
+ </UL>
+ <HR>
+<!--beginarticle-->
+<PRE>Revision: 249
+Author: rda
+Date: 2011-01-08 00:20:14 +0100 (Sat, 08 Jan 2011)
+Log Message:
+-----------
+commit implement forgot_password patch from Maarten Vanraes
+
+Modified Paths:
+--------------
+ identity/CatDap/trunk/catdap.yml
+ identity/CatDap/trunk/root/index.tt
+
+Added Paths:
+-----------
+ identity/CatDap/trunk/lib/CatDap/Controller/forgot_password.pm
+ identity/CatDap/trunk/root/email/forgot_password.tt
+ identity/CatDap/trunk/root/forgot_password/
+ identity/CatDap/trunk/root/forgot_password/check.tt
+ identity/CatDap/trunk/root/forgot_password/complete.tt
+ identity/CatDap/trunk/root/forgot_password/confirm.tt
+ identity/CatDap/trunk/root/forgot_password/index.tt
+
+Modified: identity/CatDap/trunk/catdap.yml
+===================================================================
+--- identity/CatDap/trunk/catdap.yml 2011-01-07 23:15:42 UTC (rev 248)
++++ identity/CatDap/trunk/catdap.yml 2011-01-07 23:20:14 UTC (rev 249)
+@@ -35,6 +35,12 @@
+ login_blacklist:
+ - apache
+
++forgot_password:
++ secret:
++ path: '/tmp/'
++ prefix: 'catdap-forgot_password-'
++ timeout: 259200
++
+ authentication:
+ default_realm: ldap
+ realms:
+@@ -55,6 +61,7 @@
+ user_filter: '(&amp;(objectClass=inetOrgPerson)(uid=%s))'
+ user_scope: 'one'
+ user_field: 'uid'
++ email_filter: '(&amp;(objectClass=inetOrgPerson)(|(mail=%s)(mailAlternateAddress=%s)))'
+ use_roles: 1
+ role_basedn: 'dc=mageia,dc=org'
+ role_scope: 'sub'
+
+Added: identity/CatDap/trunk/lib/CatDap/Controller/forgot_password.pm
+===================================================================
+--- identity/CatDap/trunk/lib/CatDap/Controller/forgot_password.pm (rev 0)
++++ identity/CatDap/trunk/lib/CatDap/Controller/forgot_password.pm 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,270 @@
++package CatDap::Controller::forgot_password;
++use Moose;
++use namespace::autoclean;
++use Email::Valid;
++use Data::UUID;
++
++BEGIN {extends 'Catalyst::Controller'; }
++
++=head1 NAME
++
++CatDap::Controller::forgot_password - Catalyst Controller
++
++=head1 DESCRIPTION
++
++Catalyst Controller.
++
++=head1 METHODS
++
++=cut
++
++
++=head2 index
++
++=cut
++
++sub index :Path :Args(0) : Form {
++ my ( $self, $c ) = @_;
++
++ if (defined $c-&gt;user) {
++ # if we're logged in, we haven't forgotten the password
++ $c-&gt;log-&gt;debug('Redirecting to /user');
++ $c-&gt;res-&gt;redirect('/user');
++ }
++}
++
++sub check : Local {
++ my ( $self, $c ) = @_;
++
++ my %details = %{$c-&gt;request-&gt;params};
++ my $username = lc($c-&gt;request-&gt;params-&gt;{uid});
++ my @errors;
++ $c-&gt;stash(errors =&gt; []);
++ my $email = $c-&gt;request-&gt;params-&gt;{mail};
++ if (! Email::Valid-&gt;address($email)) {
++ push @errors, $c-&gt;loc('Invalid email address');
++ }
++
++ if (@errors) {
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++
++ # check in LDAP now that we have validated username and email
++ my $emailfilter = $c-&gt;config-&gt;{'authentication'}{'realms'}{'ldap'}{'store'}{'email_filter'};
++ $emailfilter =~ s/\%s/$email/g,
++ $c-&gt;log-&gt;debug(&quot;Searching for email $email with filter $emailfilter&quot;);
++ my $mesg = $c-&gt;model('Proxy')-&gt;search($emailfilter);
++ if (!$mesg-&gt;entries()) {
++ push @errors,$c-&gt;loc(
++ 'This email address is not bound to an account'
++ );
++ }
++
++ if (@errors) {
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++
++ if ($mesg-&gt;code) {
++ push @errors,$mesg-&gt;error;
++ $c-&gt;log-&gt;info( sprintf(&quot;finding email $email failed: %s&quot;, $mesg-&gt;error) );
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'register/index.tt');
++ return;
++ }
++
++ my $secret = gen_secret($c, $email);
++
++ $c-&gt;stash(
++ email =&gt; {
++ 'to' =&gt; $email,
++ 'from' =&gt; ${$c-&gt;config}{'emailfrom'},
++ 'subject' =&gt; ${$c-&gt;config}{'apptitle'} . &quot; - &quot; . $c-&gt;loc('Forgot password'),
++ 'template' =&gt; 'forgot_password.tt',
++ },
++ url =&gt; $c-&gt;uri_for('/forgot_password/confirm') . &quot;?secret=$secret&quot;,
++ );
++
++ $c-&gt;log-&gt;info(&quot;Sending forgot password mail to email address $email&quot;);
++ $c-&gt;forward( $c-&gt;view('Email::Template') );
++ if ( @{ $c-&gt;error } ) {
++ my $errors = join &quot;\n&quot;,@{ $c-&gt;error };
++ $c-&gt;log-&gt;info(&quot;Sending activation mail to $email failed: $errors&quot;);
++ $c-&gt;response-&gt;body($c-&gt;loc('An error occured sending the email, please try again later. Errors [_1]', $errors));
++ $c-&gt;error(0); # Reset the error condition if you need to
++ }
++ $c-&gt;stash(template =&gt; 'forgot_password/complete.tt');
++}
++
++sub confirm : Local {
++ my ($self, $c) = @_;
++ my $secret = $c-&gt;req-&gt;param('secret');
++ my @errors;
++
++ # show confirm page which can enter new password
++ if (defined $c-&gt;user) {
++ # if we're logged in, we haven't forgotten the password
++ $c-&gt;log-&gt;debug('Redirecting to /user');
++ $c-&gt;res-&gt;redirect('/user');
++ }
++
++ # find secret
++ my $email = find_secret($c, $secret);
++ if (!$email) {
++ push @errors, &quot;Secret has expired, please try again.&quot;;
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++ my $mesg = find_user_email($c, $email);
++ if ($mesg-&gt;code) {
++ push @errors, &quot;Secret has expired, please try again.&quot;;
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++
++ # show template to enter a new password
++ $c-&gt;stash(secret =&gt; $secret, template =&gt; 'forgot_password/confirm.tt');
++}
++
++sub change_password : Local {
++ my ($self, $c) = @_;
++ my @errors = ();
++ my $secret = $c-&gt;req-&gt;param('secret');
++ my $newpass;
++
++ # find secret
++ my $email = find_secret($c, $secret);
++ if (!$email) {
++ push @errors, &quot;Secret has expired, please try again.&quot;;
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++ my $mesg = find_user_email($c, $email);
++ if ( $mesg-&gt;code) {
++ push @errors, &quot;Secret has expired, please try again.&quot;;
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/index.tt');
++ return;
++ }
++ my $entry = $mesg-&gt;entry;
++
++ # check if both passwords are equal and are confirm the validation norms
++ if ($c-&gt;req-&gt;param('newpassword1') eq $c-&gt;req-&gt;param('newpassword2')) {
++ $newpass = $c-&gt;req-&gt;param('newpassword1');
++ } else {
++ push @errors, &quot;New passwords dont match&quot;;
++ }
++ # if error show confirm page again to retry
++ if (@errors) {
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/confirm.tt');
++ return;
++ }
++
++ # change password
++ my $pp = Net::LDAP::Control::PasswordPolicy-&gt;new;
++ $mesg = $c-&gt;model('Proxy')-&gt;set_password(
++ user =&gt; $entry-&gt;dn,
++ newpasswd =&gt; $newpass,
++ control =&gt; [ $pp ],
++ );
++ if ($mesg-&gt;code) {
++ my $perror = $mesg-&gt;error;
++ push @errors, &quot;Password change failed: $perror&quot;;
++ $c-&gt;detach;
++ }
++
++ # if error show confirm page again to retry
++ if (@errors) {
++ $c-&gt;stash(errors =&gt; \@errors);
++ $c-&gt;stash(template =&gt; 'forgot_password/confirm.tt');
++ return;
++ }
++
++ # TODO: log in by setting the $c-&gt;user
++
++ # remove the stored secret
++ remove_secret($c, $secret);
++
++ # redirect to /
++ $c-&gt;log-&gt;debug('Redirecting to /');
++ $c-&gt;res-&gt;redirect('/');
++}
++
++sub gen_secret {
++ my ($c, $email) = @_;
++ my $ug = new Data::UUID;
++ # generate a unique secret
++ my $secret = $ug-&gt;create_str();
++ my $filename = $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'path'} .'/'. $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'prefix'} . $secret;
++ # store secret with email
++ open FILE, &quot;&gt;$filename&quot;;
++ print FILE $email;
++ close FILE;
++ return $secret;
++}
++
++sub find_secret {
++ my ($c, $secret) = @_;
++ my $email;
++ my $filename = $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'path'} .'/'. $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'prefix'} . $secret;
++ my $timeout = 259200; # 3days in seconds
++ if ($c-&gt;config-&gt;{'forgot_password'}{'secret'}{'timeout'}) {
++ $timeout = $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'timeout'};
++ }
++
++ # find secret
++ if (!$secret || !open(FILE, &quot;&lt;$filename&quot;)) {
++ # if secret is wrong, timeout expired?
++ return '';
++ }
++ read(FILE, $email, 255);
++ close FILE;
++
++ # check the time, and see if it's longer than timeout
++ my @s = stat($filename);
++ if (time() &gt; $s[9] + $timeout) {
++ # expired
++ return '';
++ }
++
++ return $email;
++}
++
++sub remove_secret {
++ my ($c, $secret) = @_;
++ my $filename = $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'path'} .'/'. $c-&gt;config-&gt;{'forgot_password'}{'secret'}{'prefix'} . $secret;
++ unlink $filename;
++}
++
++sub find_user_email {
++ my ($c, $email) = @_;
++
++ # find user by email;
++ my $emailfilter = $c-&gt;config-&gt;{'authentication'}{'realms'}{'ldap'}{'store'}{'email_filter'};
++ $emailfilter =~ s/\%s/$email/g,
++ $c-&gt;log-&gt;debug(&quot;Searching for email $email with filter $emailfilter&quot;);
++ return $c-&gt;model('Proxy')-&gt;search($emailfilter);
++}
++
++
++=head1 AUTHOR
++
++Buchan Milne
++
++=head1 LICENSE
++
++This library is free software. You can redistribute it and/or modify
++it under the same terms as Perl itself.
++
++=cut
++
++__PACKAGE__-&gt;meta-&gt;make_immutable;
++
++1;
+
+Added: identity/CatDap/trunk/root/email/forgot_password.tt
+===================================================================
+--- identity/CatDap/trunk/root/email/forgot_password.tt (rev 0)
++++ identity/CatDap/trunk/root/email/forgot_password.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,7 @@
++[% l('Dear [_1],',cn) %]
++[% l('Your [_1] account has been requested to change the password. If you did not do this, or you do not want to change your password; you can just do nothing.',c.config.organisation) %]
++[% l('To reset your password, please follow the link below.') %]
++[% url %]
++
++--
++<A HREF="http://mageia.org/">http://mageia.org/</A>
+
+Added: identity/CatDap/trunk/root/forgot_password/check.tt
+===================================================================
+--- identity/CatDap/trunk/root/forgot_password/check.tt (rev 0)
++++ identity/CatDap/trunk/root/forgot_password/check.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,4 @@
++&lt;h2&gt;Success&lt;/h2&gt;
++&lt;p&gt;
++[% message %]
++&lt;/p&gt;
+\ No newline at end of file
+
+Added: identity/CatDap/trunk/root/forgot_password/complete.tt
+===================================================================
+--- identity/CatDap/trunk/root/forgot_password/complete.tt (rev 0)
++++ identity/CatDap/trunk/root/forgot_password/complete.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,6 @@
++&lt;h2&gt;[% l('Email sent.') %]&lt;/h2&gt;
++
++&lt;p&gt;
++ [% l('Operation was successful.') %]
++ [% l('Check your mail for password reset instructions.') %]
++&lt;/p&gt;
+
+Added: identity/CatDap/trunk/root/forgot_password/confirm.tt
+===================================================================
+--- identity/CatDap/trunk/root/forgot_password/confirm.tt (rev 0)
++++ identity/CatDap/trunk/root/forgot_password/confirm.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,21 @@
++
++&lt;h1&gt;[% l('Enter new password.') %]&lt;/h1&gt;
++
++&lt;div id=&quot;input_form&quot;&gt;
++&lt;form method=&quot;post&quot; action=&quot;/forgot_password/change_password&quot;&gt;
++ &lt;table&gt;
++ &lt;tr&gt;
++ &lt;td&gt;&lt;label for=&quot;newpassword1_&quot;&gt;[% l('New Password') %]&lt;/label&gt;&lt;/td&gt;
++ &lt;td&gt;&lt;input id=&quot;newpassword1_&quot; name=&quot;newpassword1&quot; type=&quot;password&quot; value=&quot;&quot; /&gt;&lt;/td&gt;
++ &lt;/tr&gt;&lt;tr&gt;
++ &lt;td&gt;&lt;label for=&quot;newpassword2_&quot;&gt;[% l('Repeat New Password') %]&lt;/label&gt;&lt;/td&gt;
++ &lt;td&gt;&lt;input id=&quot;newpassword2_&quot; name=&quot;newpassword2&quot; type=&quot;password&quot; value=&quot;&quot; /&gt;&lt;/td&gt;
++ &lt;/tr&gt;&lt;tr&gt;
++ &lt;td colspan=&quot;2&quot; style=&quot;text-align:center;&quot;&gt;
++ &lt;input type=&quot;hidden&quot; name=&quot;secret&quot; value=&quot;[% secret %]&quot; /&gt;
++ &lt;button type=&quot;submit&quot; value=&quot;[% l('Set new password') %]&quot;&gt;[% l('Set new password') %]&lt;/button&gt;
++ &lt;/td&gt;
++ &lt;/tr&gt;
++ &lt;/table&gt;
++&lt;/form&gt;
++&lt;/div&gt;
+
+Added: identity/CatDap/trunk/root/forgot_password/index.tt
+===================================================================
+--- identity/CatDap/trunk/root/forgot_password/index.tt (rev 0)
++++ identity/CatDap/trunk/root/forgot_password/index.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -0,0 +1,17 @@
++
++&lt;h1&gt;[% l('Forgot your password?') %]&lt;/h1&gt;
++
++&lt;div id=&quot;input_form&quot;&gt;
++&lt;form method=&quot;post&quot; action=&quot;/forgot_password/check&quot;&gt;
++ &lt;table&gt;
++ &lt;tr&gt;
++ &lt;td&gt;&lt;label for=&quot;mail_&quot;&gt;[% l('Email address') %]&lt;/label&gt;&lt;/td&gt;
++ &lt;td&gt;&lt;input id=&quot;mail_&quot; type=&quot;text&quot; name=&quot;mail&quot; value=&quot;[% c.request.params.mail %]&quot; /&gt;&lt;/td&gt;
++ &lt;/tr&gt;&lt;tr&gt;
++ &lt;td colspan=&quot;2&quot; style=&quot;text-align:center;&quot;&gt;
++ &lt;button type=&quot;submit&quot; value=&quot;[% l('Reset password') %]&quot;&gt;[% l('Reset password') %]&lt;/button&gt;
++ &lt;/td&gt;
++ &lt;/tr&gt;
++ &lt;/table&gt;
++&lt;/form&gt;
++&lt;/div&gt;
+
+Modified: identity/CatDap/trunk/root/index.tt
+===================================================================
+--- identity/CatDap/trunk/root/index.tt 2011-01-07 23:15:42 UTC (rev 248)
++++ identity/CatDap/trunk/root/index.tt 2011-01-07 23:20:14 UTC (rev 249)
+@@ -14,8 +14,7 @@
+ &lt;/div&gt;
+ &lt;div id=&quot;login_form_line&quot;&gt;
+ &lt;span&gt;&lt;a href=&quot;/register&quot;&gt;[% l('Register') %]&lt;/a&gt; |
+- @todo [% l('Forgotten password?') %]
+- &lt;!--&lt;a href=&quot;/forgot_password&quot;&gt;[% l('Forgotten password?') %]&lt;/a&gt; --&gt;
++ &lt;a href=&quot;/forgot_password&quot;&gt;[% l('Forgotten password?') %]&lt;/a&gt;
+ &lt;/span&gt;
+ &lt;/div&gt;
+ &lt;/form&gt;
+-------------- next part --------------
+An HTML attachment was scrubbed...
+URL: &lt;/pipermail/mageia-sysadm/attachments/20110108/f0712891/attachment-0001.html&gt;
+</PRE>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<!--endarticle-->
+ <HR>
+ <P><UL>
+ <!--threads-->
+ <LI>Previous message: <A HREF="001716.html">[Mageia-sysadm] [248] commit spec file from Maarten Vanraes
+</A></li>
+ <LI>Next message: <A HREF="001719.html">[Mageia-sysadm] [249] commit implement forgot_password patch from Maarten Vanraes
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#1717">[ date ]</a>
+ <a href="thread.html#1717">[ thread ]</a>
+ <a href="subject.html#1717">[ subject ]</a>
+ <a href="author.html#1717">[ author ]</a>
+ </LI>
+ </UL>
+
+<hr>
+<a href="https://www.mageia.org/mailman/listinfo/mageia-sysadm">More information about the Mageia-sysadm
+mailing list</a><br>
+</body></html>