[Codestriker-commits] CVS update: codestriker/lib/Codestriker/Action NewPassword.pm
Brought to you by:
sits
From: <si...@us...> - 2008-09-07 12:20:34
|
User: sits Date: 08/09/07 05:20:32 Modified: t/Http/Method reset-password.t lib/Codestriker/Http/Method UpdatePasswordMethod.pm ResetPasswordMethod.pm lib/Codestriker/Http UrlBuilder.pm Dispatcher.pm Added: template/en/default newpassword.html.tmpl t/Http/Method new-password.t lib/Codestriker/Http/Method NewPasswordMethod.pm lib/Codestriker/Action NewPassword.pm Removed: template/en/default resetpassword.html.tmpl Log: More password methods added in. Index: newpassword.html.tmpl =================================================================== RCS file: newpassword.html.tmpl diff -N newpassword.html.tmpl --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ newpassword.html.tmpl 7 Sep 2008 12:20:29 -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: resetpassword.html.tmpl =================================================================== RCS file: resetpassword.html.tmpl diff -N resetpassword.html.tmpl --- resetpassword.html.tmpl 7 Sep 2008 11:49:42 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,54 +0,0 @@ -[%# 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: reset-password.t =================================================================== RCS file: /cvsroot/codestriker/codestriker/t/Http/Method/reset-password.t,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- reset-password.t 7 Sep 2008 11:49:45 -0000 1.1 +++ reset-password.t 7 Sep 2008 12:20:30 -0000 1.2 @@ -1,7 +1,7 @@ # Tests for the ResetPassword method. use strict; -use Test::More tests => 4; +use Test::More tests => 3; use lib '../../../lib'; use Test::MockObject; @@ -17,14 +17,13 @@ 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', +is($url_cgi->url(email => 'jo...@bl...'), + $mock_query->url() . '?action=reset_password&email=joe%40bloggs.com', "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', + $mock_query->url() . '/user/joe%40bloggs.com/password/reset', "Reset password URL nice syntax"); # Check that the parameters extracted correctly. @@ -33,9 +32,8 @@ $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'; + return '/user/joe%40bloggs.com/password/reset'; }); $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: new-password.t =================================================================== RCS file: new-password.t diff -N new-password.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ new-password.t 7 Sep 2008 12:20:30 -0000 1.1 @@ -0,0 +1,41 @@ +# Tests for the NewPassword method. + +use strict; +use Test::More tests => 4; + +use lib '../../../lib'; +use Test::MockObject; +use Codestriker; +use Codestriker::Http::Method::NewPasswordMethod; + +# 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::NewPasswordMethod->new($mock_query, 1); +my $url_nice = Codestriker::Http::Method::NewPasswordMethod->new($mock_query, 0); + +is($url_cgi->url(email => 'jo...@bl...', + challenge => 'abcdefg'), + $mock_query->url() . '?action=new_password&email=joe%40bloggs.com&challenge=abcdefg', + "New password URL CGI syntax"); + +is($url_nice->url(email => 'jo...@bl...', + challenge => 'abcdefg'), + $mock_query->url() . '/user/joe%40bloggs.com/password/new/challenge/abcdefg', + "New 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/new/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: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/UpdatePasswordMethod.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- UpdatePasswordMethod.pm 7 Sep 2008 11:49:45 -0000 1.1 +++ UpdatePasswordMethod.pm 7 Sep 2008 12:20:30 -0000 1.2 @@ -11,7 +11,6 @@ use strict; use Codestriker::Http::Method; -use Codestriker::Action::Login; @Codestriker::Http::Method::UpdatePasswordMethod::ISA = ("Codestriker::Http::Method"); @@ -48,7 +47,7 @@ sub execute { my ($self, $http_input, $http_output) = @_; - Codestriker::Action::ResetPasswordAction->process($http_input, $http_output); +# Codestriker::Action::UpdatePassword->process($http_input, $http_output); } 1; Index: ResetPasswordMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ResetPasswordMethod.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ResetPasswordMethod.pm 7 Sep 2008 11:49:45 -0000 1.1 +++ ResetPasswordMethod.pm 7 Sep 2008 12:20:30 -0000 1.2 @@ -5,13 +5,12 @@ # 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. +# Method for resetting a password. package Codestriker::Http::Method::ResetPasswordMethod; use strict; use Codestriker::Http::Method; -use Codestriker::Action::ResetPassword; @Codestriker::Http::Method::ResetPasswordMethod::ISA = ("Codestriker::Http::Method"); @@ -21,11 +20,10 @@ if ($self->{cgi_style}) { return $self->{url_prefix} . "?action=reset_password" . - "&email=" . CGI::escape($args{email}) . - "&challenge=" . CGI::escape($args{challenge}); + "&email=" . CGI::escape($args{email}); } else { return $self->{url_prefix} . "/user/" . CGI::escape($args{email}) . - "/password/reset/challenge/" . CGI::escape($args{challenge}); + "/password/reset"; } } @@ -37,10 +35,9 @@ 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/}) { + } elsif ($path_info =~ m{^/user/.*/password/reset$}) { $self->_extract_nice_parameters($http_input, - user => 'email', - challenge => 'challenge'); + user => 'email'); return 1; } else { return 0; @@ -50,7 +47,7 @@ sub execute { my ($self, $http_input, $http_output) = @_; - Codestriker::Action::ResetPassword->process($http_input, $http_output); +# Codestriker::Action::UpdatePassword->process($http_input, $http_output); } 1; Index: NewPasswordMethod.pm =================================================================== RCS file: NewPasswordMethod.pm diff -N NewPasswordMethod.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ NewPasswordMethod.pm 7 Sep 2008 12:20:30 -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::NewPasswordMethod; + +use strict; +use Codestriker::Http::Method; +use Codestriker::Action::NewPassword; + +@Codestriker::Http::Method::NewPasswordMethod::ISA = ("Codestriker::Http::Method"); + +# Generate a URL for this method. +sub url() { + my ($self, %args) = @_; + + if ($self->{cgi_style}) { + return $self->{url_prefix} . "?action=new_password" . + "&email=" . CGI::escape($args{email}) . + "&challenge=" . CGI::escape($args{challenge}); + } else { + return $self->{url_prefix} . "/user/" . CGI::escape($args{email}) . + "/password/new/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 "new_password") { + $http_input->extract_cgi_parameters(); + return 1; + } elsif ($path_info =~ m{^/user/.*/password/new/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::NewPassword->process($http_input, $http_output); +} + +1; Index: UrlBuilder.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- UrlBuilder.pm 7 Sep 2008 11:49:45 -0000 1.51 +++ UrlBuilder.pm 7 Sep 2008 12:20:31 -0000 1.52 @@ -37,8 +37,9 @@ use Codestriker::Http::Method::UpdateTopicStateMethod; use Codestriker::Http::Method::LoginMethod; use Codestriker::Http::Method::AuthenticateMethod; -use Codestriker::Http::Method::ResetPasswordMethod; +use Codestriker::Http::Method::NewPasswordMethod; use Codestriker::Http::Method::UpdatePasswordMethod; +use Codestriker::Http::Method::ResetPasswordMethod; # Constructor for this class. sub new { @@ -235,10 +236,10 @@ return Codestriker::Http::Method::LoginMethod->new($self->{query})->url(%args); } -# Create the URL for resetting a password. -sub reset_password_url { +# Create the URL for setting a new password. +sub new_password_url { my ($self, %args) = @_; - return Codestriker::Http::Method::ResetPasswordMethod->new($self->{query})->url(%args); + return Codestriker::Http::Method::NewPasswordMethod->new($self->{query})->url(%args); } # Create the URL for updating a password. @@ -247,6 +248,12 @@ return Codestriker::Http::Method::UpdatePasswordMethod->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 authenticating. sub authenticate_url { my ($self, %args) = @_; Index: Dispatcher.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Dispatcher.pm 7 Sep 2008 11:49:45 -0000 1.12 +++ Dispatcher.pm 7 Sep 2008 12:20:31 -0000 1.13 @@ -40,8 +40,9 @@ use Codestriker::Http::Method::AddProjectMethod; use Codestriker::Http::Method::LoginMethod; use Codestriker::Http::Method::AuthenticateMethod; -use Codestriker::Http::Method::ResetPasswordMethod; +use Codestriker::Http::Method::NewPasswordMethod; use Codestriker::Http::Method::UpdatePasswordMethod; +use Codestriker::Http::Method::ResetPasswordMethod; # Initialise all of the methods that are known to the system. # TODO: add configuration to the parameter. @@ -83,8 +84,9 @@ 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::NewPasswordMethod->new($query); push @methods, Codestriker::Http::Method::UpdatePasswordMethod->new($query); + push @methods, Codestriker::Http::Method::ResetPasswordMethod->new($query); $self->{methods} = \@methods; return bless $self, $type; Index: NewPassword.pm =================================================================== RCS file: NewPassword.pm diff -N NewPassword.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ NewPassword.pm 7 Sep 2008 12:20:31 -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 new password page. + +package Codestriker::Action::NewPassword; + +use strict; +use Codestriker::Http::UrlBuilder; + +# Create an appropriate form for entering a new password. +sub process { + my ($type, $http_input, $http_response) = @_; + + my $query = $http_response->get_query(); + + $http_response->generate_header(topic_title=>"New 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("newpassword"); + $template->process($vars); + + $http_response->generate_footer(); +} + +1; |