[Codestriker-commits] CVS update: codestriker/lib/Codestriker/Action ResetPassword.pm
Brought to you by:
sits
|
From: <si...@us...> - 2008-09-07 11:49:47
|
User: sits
Date: 08/09/07 04:49:45
Modified: lib/Codestriker/Http UrlBuilder.pm Method.pm Input.pm
Dispatcher.pm
Added: template/en/default resetpassword.html.tmpl
t/Http/Method update-password.t reset-password.t
lib/Codestriker/Http/Method UpdatePasswordMethod.pm
ResetPasswordMethod.pm
lib/Codestriker/Action ResetPassword.pm
Log:
Added in support for the ResetPassword and UpdatePassword methods.
Index: resetpassword.html.tmpl
===================================================================
RCS file: resetpassword.html.tmpl
diff -N resetpassword.html.tmpl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ resetpassword.html.tmpl 7 Sep 2008 11:49:42 -0000 1.1
@@ -0,0 +1,54 @@
+[%# Screen for the reset password form. #%]
+
+[% PROCESS header.html.tmpl version = version displaymenu = 1
+ closehead = 1 subtitle = "Reset Password" %]
+<p>
+Please enter your new password.
+</p>
+
+<form method="post" enctype="application/x-www-form-urlencoded" action="[% action_url %]">
+
+<input type="hidden" name="action" value="update_password" />
+<input type="hidden" name="email" value="[% email %]" />
+<input type="hidden" name="challenge" value="[% challenge %]" />
+
+ <table>
+ <tr>
+ <th align="right">New password:</th>
+ <td>
+ <input type="password" size="40" name="password">
+ </td>
+ </tr>
+ <tr>
+ <th> </th><td> </td>
+ </tr>
+ </table>
+
+ <input type="submit" name=".submit" value="Reset Password" />
+
+</form>
+
+<!--
+<hr>
+
+<p>
+If you don't have a Codestriker account, you can create a new account.
+</p>
+
+<hr>
+
+<form method="post" enctype="application/x-www-form-urlencoded" action="[% action_url %]">
+ <input type="hidden" name="action" value="reset_password">
+ <p>
+ If you have an account, but have forgotten your password,
+ enter your e-mail address below to generate a new password.
+ </p>
+ <input size="40" maxlength="80" name="email">
+ <input type="submit" name=".submit2" value="Regenerate Password">
+</form>
+-->
+
+[% PROCESS trailer.html.tmpl %]
+
+</body>
+</html>
Index: update-password.t
===================================================================
RCS file: update-password.t
diff -N update-password.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ update-password.t 7 Sep 2008 11:49:45 -0000 1.1
@@ -0,0 +1,39 @@
+# Tests for the UpdatePassword method.
+
+use strict;
+use Test::More tests => 3;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::UpdatePasswordMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl' } );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi = Codestriker::Http::Method::UpdatePasswordMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::UpdatePasswordMethod->new($mock_query, 0);
+
+is($url_cgi->url(email => 'jo...@bl...'),
+ $mock_query->url() . '?action=update_password&email=joe%40bloggs.com',
+ "Update password URL CGI syntax");
+
+is($url_nice->url(email => 'jo...@bl...',
+ challenge => 'abcdefg'),
+ $mock_query->url() . '/user/joe%40bloggs.com/password/update',
+ "Update password URL nice syntax");
+
+# Check that the parameters extracted correctly.
+my $mock_http_input = Test::MockObject->new();
+$mock_http_input->{query} = $mock_query;
+$mock_http_input->mock('extract_cgi_parameters', sub { return undef; });
+$mock_query->mock('path_info',
+ sub {
+ return '/user/joe%40bloggs.com/password/update';
+ });
+$mock_query->mock('param', sub { return undef; });
+$url_nice->extract_parameters($mock_http_input);
+is ($mock_http_input->{email}, 'jo...@bl...', "email nice URL parameter extraction");
Index: reset-password.t
===================================================================
RCS file: reset-password.t
diff -N reset-password.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ reset-password.t 7 Sep 2008 11:49:45 -0000 1.1
@@ -0,0 +1,41 @@
+# Tests for the ResetPassword method.
+
+use strict;
+use Test::More tests => 4;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::ResetPasswordMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl' } );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi = Codestriker::Http::Method::ResetPasswordMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::ResetPasswordMethod->new($mock_query, 0);
+
+is($url_cgi->url(email => 'jo...@bl...',
+ challenge => 'abcdefg'),
+ $mock_query->url() . '?action=reset_password&email=joe%40bloggs.com&challenge=abcdefg',
+ "Reset password URL CGI syntax");
+
+is($url_nice->url(email => 'jo...@bl...',
+ challenge => 'abcdefg'),
+ $mock_query->url() . '/user/joe%40bloggs.com/password/reset/challenge/abcdefg',
+ "Reset password URL nice syntax");
+
+# Check that the parameters extracted correctly.
+my $mock_http_input = Test::MockObject->new();
+$mock_http_input->{query} = $mock_query;
+$mock_http_input->mock('extract_cgi_parameters', sub { return undef; });
+$mock_query->mock('path_info',
+ sub {
+ return '/user/joe%40bloggs.com/password/reset/challenge/abcdefg';
+ });
+$mock_query->mock('param', sub { return undef; });
+$url_nice->extract_parameters($mock_http_input);
+is ($mock_http_input->{email}, 'jo...@bl...', "email nice URL parameter extraction");
+is ($mock_http_input->{challenge}, 'abcdefg', "challenge nice URL parameter extraction");
Index: UpdatePasswordMethod.pm
===================================================================
RCS file: UpdatePasswordMethod.pm
diff -N UpdatePasswordMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ UpdatePasswordMethod.pm 7 Sep 2008 11:49:45 -0000 1.1
@@ -0,0 +1,54 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for updating a password.
+
+package Codestriker::Http::Method::UpdatePasswordMethod;
+
+use strict;
+use Codestriker::Http::Method;
+use Codestriker::Action::Login;
+
+@Codestriker::Http::Method::UpdatePasswordMethod::ISA = ("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=update_password" .
+ "&email=" . CGI::escape($args{email});
+ } else {
+ return $self->{url_prefix} . "/user/" . CGI::escape($args{email}) .
+ "/password/update";
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "update_password") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^/user/.*/password/update$}) {
+ $self->_extract_nice_parameters($http_input,
+ user => 'email');
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::ResetPasswordAction->process($http_input, $http_output);
+}
+
+1;
Index: ResetPasswordMethod.pm
===================================================================
RCS file: ResetPasswordMethod.pm
diff -N ResetPasswordMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ResetPasswordMethod.pm 7 Sep 2008 11:49:45 -0000 1.1
@@ -0,0 +1,56 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for going to the reset password form.
+
+package Codestriker::Http::Method::ResetPasswordMethod;
+
+use strict;
+use Codestriker::Http::Method;
+use Codestriker::Action::ResetPassword;
+
+@Codestriker::Http::Method::ResetPasswordMethod::ISA = ("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=reset_password" .
+ "&email=" . CGI::escape($args{email}) .
+ "&challenge=" . CGI::escape($args{challenge});
+ } else {
+ return $self->{url_prefix} . "/user/" . CGI::escape($args{email}) .
+ "/password/reset/challenge/" . CGI::escape($args{challenge});
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "reset_password") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^/user/.*/password/reset/challenge/}) {
+ $self->_extract_nice_parameters($http_input,
+ user => 'email',
+ challenge => 'challenge');
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::ResetPassword->process($http_input, $http_output);
+}
+
+1;
Index: UrlBuilder.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- UrlBuilder.pm 7 Sep 2008 04:49:26 -0000 1.50
+++ UrlBuilder.pm 7 Sep 2008 11:49:45 -0000 1.51
@@ -37,6 +37,8 @@
use Codestriker::Http::Method::UpdateTopicStateMethod;
use Codestriker::Http::Method::LoginMethod;
use Codestriker::Http::Method::AuthenticateMethod;
+use Codestriker::Http::Method::ResetPasswordMethod;
+use Codestriker::Http::Method::UpdatePasswordMethod;
# Constructor for this class.
sub new {
@@ -233,6 +235,18 @@
return Codestriker::Http::Method::LoginMethod->new($self->{query})->url(%args);
}
+# Create the URL for resetting a password.
+sub reset_password_url {
+ my ($self, %args) = @_;
+ return Codestriker::Http::Method::ResetPasswordMethod->new($self->{query})->url(%args);
+}
+
+# Create the URL for updating a password.
+sub update_password_url {
+ my ($self, %args) = @_;
+ return Codestriker::Http::Method::UpdatePasswordMethod->new($self->{query})->url(%args);
+}
+
# Create the URL for authenticating.
sub authenticate_url {
my ($self, %args) = @_;
Index: Method.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Method.pm 6 Sep 2008 06:03:56 -0000 1.6
+++ Method.pm 7 Sep 2008 11:49:45 -0000 1.7
@@ -24,7 +24,7 @@
if (defined $cgi_style) {
$self->{cgi_style} = $cgi_style;
} else {
- $self->{cgi_style} = $query->url() =~ /codestriker.pl$/ ? 1 : 0;
+ $self->{cgi_style} = $query->url() =~ /codestriker.pl/ ? 1 : 0;
}
# Determine what prefix is required when using relative URLs.
Index: Input.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Input.pm,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- Input.pm 6 Sep 2008 00:31:47 -0000 1.51
+++ Input.pm 7 Sep 2008 11:49:45 -0000 1.52
@@ -106,6 +106,8 @@
$self->{selected_comments} = \@selected_comments;
$self->{default_to_head} = $query->param('default_to_head');
$self->{email_event} = $query->param('email_event');
+ $self->{redirect} = $query->param('redirect');
+ $self->{challenge} = $query->param('challenge');
# Set any missing parameters from the cookie.
my %cookie = Codestriker::Http::Cookie->get($query);
Index: Dispatcher.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Dispatcher.pm 7 Sep 2008 04:49:26 -0000 1.11
+++ Dispatcher.pm 7 Sep 2008 11:49:45 -0000 1.12
@@ -40,6 +40,8 @@
use Codestriker::Http::Method::AddProjectMethod;
use Codestriker::Http::Method::LoginMethod;
use Codestriker::Http::Method::AuthenticateMethod;
+use Codestriker::Http::Method::ResetPasswordMethod;
+use Codestriker::Http::Method::UpdatePasswordMethod;
# Initialise all of the methods that are known to the system.
# TODO: add configuration to the parameter.
@@ -81,6 +83,8 @@
push @methods, Codestriker::Http::Method::AddProjectMethod->new($query);
push @methods, Codestriker::Http::Method::LoginMethod->new($query);
push @methods, Codestriker::Http::Method::AuthenticateMethod->new($query);
+ push @methods, Codestriker::Http::Method::ResetPasswordMethod->new($query);
+ push @methods, Codestriker::Http::Method::UpdatePasswordMethod->new($query);
$self->{methods} = \@methods;
return bless $self, $type;
Index: ResetPassword.pm
===================================================================
RCS file: ResetPassword.pm
diff -N ResetPassword.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ResetPassword.pm 7 Sep 2008 11:49:45 -0000 1.1
@@ -0,0 +1,37 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Action object for displaying the reset password page.
+
+package Codestriker::Action::ResetPassword;
+
+use strict;
+use Codestriker::Http::UrlBuilder;
+
+# Create an appropriate form for reseting the password.
+sub process {
+ my ($type, $http_input, $http_response) = @_;
+
+ my $query = $http_response->get_query();
+
+ $http_response->generate_header(topic_title=>"Reset Password",
+ reload=>0, cache=>1);
+
+ # Target URL to divert the post to.
+ my $vars = {};
+ my $url_builder = Codestriker::Http::UrlBuilder->new($query);
+ $vars->{'action_url'} = $url_builder->update_password_url();
+ $vars->{'challenge'} = $http_input->get('challenge');
+ $vars->{'email'} = $http_input->get('email');
+
+ my $template = Codestriker::Http::Template->new("resetpassword");
+ $template->process($vars);
+
+ $http_response->generate_footer();
+}
+
+1;
|