[Jifty-commit] r2978 - in jifty/trunk: .
lib/Jifty/Plugin/Authentication/Password/Action
lib/Jifty/Plugin/Authentication/Password/Mixin
lib/Jifty/Plugin/Authentication/Password/Mixin/Model
lib/Jifty/Plugin/Authentication/Password/Model
lib/Jifty/Plugin/User/Mixin lib/Jifty/Plugin/User/Mixin/Model
lib/Jifty/Plugin/User/Model t/TestApp-Plugin-PasswordAuth/etc
t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Mar 16 01:09:20 EDT 2007
Author: jesse
Date: Fri Mar 16 01:09:19 2007
New Revision: 2978
Added:
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ConfirmEmail.pm (contents, props changed)
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Mixin/
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Mixin/Model/
- copied from r2963, /jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Model/
jifty/trunk/lib/Jifty/Plugin/User/Mixin/
jifty/trunk/lib/Jifty/Plugin/User/Mixin/Model/
- copied from r2963, /jifty/trunk/lib/Jifty/Plugin/User/Model/
Removed:
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/RecoverPassword.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Model/
jifty/trunk/lib/Jifty/Plugin/User/Model/
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Dispatcher.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Mixin/Model/User.pm
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm
jifty/trunk/lib/Jifty/Plugin/User/Mixin/Model/User.pm
jifty/trunk/t/TestApp-Plugin-PasswordAuth/etc/config.yml
jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm
Log:
r53500 at pinglin: jesse | 2007-03-16 00:32:24 -0400
* next major round of work on the login plugin. signup now works
Added: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ConfirmEmail.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ConfirmEmail.pm Fri Mar 16 01:09:19 2007
@@ -0,0 +1,65 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+Jifty::Plugin::Authentication::Password::Action::ConfirmEmail - Confirm a user's email address
+
+=head1 DESCRIPTION
+
+This is the link in a user's email to confirm that their email
+email is really theirs. It is not really meant to be rendered on any
+web page, but is used by the confirmation notification.
+
+=cut
+
+package Jifty::Plugin::Authentication::Password::Action::ConfirmEmail;
+use base qw/Jifty::Action/;
+
+=head2 arguments
+
+A null sub, because the superclass wants to make sure we fill in arguments
+
+=cut
+
+sub arguments { }
+
+=head2 take_action
+
+Set their confirmed status.
+
+=cut
+
+sub take_action {
+ my $self = shift;
+ my $LoginUser = Jifty->app_class('Model', 'User');
+ my $CurrentUser = Jifty->app_class('CurrentUser');
+
+
+
+ my $u = $LoginUser->new( current_user => $CurrentUser->superuser );
+ $u->load_by_cols(id => Jifty->web->current_user->user_object->id );
+
+ if ( $u->email_confirmed ) {
+ $self->result->error( email => _("You have already confirmed your account.") );
+ $self->result->success(1); # but the action is still a success
+ }
+
+ my ($val,$msg) = $u->set_email_confirmed('1') ;
+
+ unless ($val) {
+ $self->result->error($msg);
+ return undef;
+ }
+ else { warn $msg }
+
+ # Set up our login message
+ $self->result->message( _("Welcome to %1, %2. " , Jifty->config->framework('ApplicationName') , $u->name) ." "
+ . _(". Your email address has now been confirmed.") );
+
+ # Actually do the login thing.
+ Jifty->web->current_user( $CurrentUser->new( id => $u->id ) );
+ return 1;
+}
+
+1;
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm Fri Mar 16 01:09:19 2007
@@ -153,6 +153,9 @@
return;
}
}
+ unless ($user->email_confirmed) {
+ $self->result->error( q{You haven't confirmed your account yet.} ); return;
+ }
# Set up our login message
$self->result->message( $self->login_message($user));
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm Fri Mar 16 01:09:19 2007
@@ -19,7 +19,7 @@
=over 4
-=item address: the email address
+=item email: the email email
=back
@@ -28,7 +28,7 @@
sub arguments {
return (
{
- address => {
+ email => {
label => 'Email address',
mandatory => 1,
default_value => "",
@@ -51,32 +51,32 @@
$self->user_object(Jifty->app_class('Model','User')->new(current_user => Jifty->app_class('CurrentUser')->superuser));
}
-=head2 validate_address
+=head2 validate_email
-Make sure their email address is an unconfirmed user.
+Make sure their email email is an unconfirmed user.
=cut
-sub validate_address {
+sub validate_email {
my $self = shift;
my $email = shift;
unless ( $email =~ /\S\@\S/ ) {
- return $self->validation_error(address => "Are you sure that's an email address?" );
+ return $self->validation_error(email => "Are you sure that's an email email?" );
}
$self->user_object(Jifty->app_class('Model','User')->new(current_user => Jifty->app_class('CurrentUser')->superuser));
$self->user_object->load_by_cols( email => $email );
unless ($self->user_object->id) {
- return $self->validation_error(address => "It doesn't look like there's an account by that name.");
+ return $self->validation_error(email => "It doesn't look like there's an account by that name.");
}
if ($self->user_object->email_confirmed) {
- return $self->validation_error(address => "It looks like you're already confirmed.");
+ return $self->validation_error(email => "It looks like you're already confirmed.");
}
- return $self->validation_ok('address');
+ return $self->validation_ok('email');
}
=head2 take_action
@@ -89,7 +89,7 @@
my $self = shift;
my $user = $self->user_object();
- Jifty->app_class('Notification','ConfirmAddress')->new( to => $user )->send;
+ Jifty->app_class('Notification','ConfirmEmail')->new( to => $user )->send;
$self->result->message("We've re-sent your confirmation.");
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm Fri Mar 16 01:09:19 2007
@@ -48,8 +48,10 @@
sub take_action {
my $self = shift;
- my $LoginUser = "Jifty::Plugin::Authentication::Password::Model::User";
- my $CurrentUser = "Jifty::Plugin::Authentication::Password::CurrentUser";
+ my $LoginUser = Jifty->app_class('Model', 'User');
+ my $CurrentUser = Jifty->app_class('CurrentUser');
+
+
my $u = $LoginUser->new( current_user => $CurrentUser->superuser );
@@ -57,7 +59,11 @@
unless ($u) {
$self->result->error(
-_("You don't exist. I'm not sure how this happened. Really, really sorry. Please email us!")
+ join( ' ',
+ _("You don't exist."),
+ _("I'm not sure how this happened."),
+ _("Really, really sorry."),
+ _("Please email us!") )
);
}
@@ -65,13 +71,8 @@
my $pass_c = $self->argument_value('password_confirm');
# Trying to set a password (ie, submitted the form)
- unless (defined $pass
- and defined $pass_c
- and length $pass
- and $pass eq $pass_c )
- {
- $self->result->error(
-_("It looks like you didn't enter the same password into both boxes. Give it another shot?")
+ unless (defined $pass and defined $pass_c and length $pass and $pass eq $pass_c ) {
+ $self->result->error( _("It looks like you didn't enter the same password into both boxes. Give it another shot?")
);
return;
}
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm Fri Mar 16 01:09:19 2007
@@ -8,8 +8,12 @@
=cut
package Jifty::Plugin::Authentication::Password::Action::Signup;
-use Jifty::Plugin::Authentication::Password::Action::CreateUser;
-use base qw/Jifty::Plugin::Authentication::Password::Action::CreateUser/;
+our @ISA;
+{
+ my $class = Jifty->app_class('Action', 'CreateUser');
+ Jifty::Util->require($class);
+ push @ISA, $class;
+}
=head2 arguments
@@ -30,7 +34,8 @@
sub arguments {
my $self = shift;
- my $args = $self->SUPER::arguments;
+ my $args = $self->SUPER::arguments();
+
my %fields = (
name => 1,
@@ -97,16 +102,16 @@
defined $self->record->column($_) and defined $self->argument_value($_)
} $self->argument_names;
- my ($id) = $record->create(%values);
+ my ($id, $msg) = $record->create(%values);
# Handle errors?
unless ( $record->id ) {
- $self->result->error( _("Something bad happened and we couldn't create your account.").' '. _("Try again later. We're really, really sorry.")
+ $self->result->error( _("Something bad happened and we couldn't create your account: %1", $msg).' '. _("Try again later. We're really, really sorry.")
);
return;
}
- $self->result->message( _("Welcome to [_1], [_2].", Jifty->config->framework('ApplicationName'), $record->name)
+ $self->result->message( _("Welcome to %1, %2.", Jifty->config->framework('ApplicationName'), $record->name)
. ' ' . _("We've sent a confirmation message to your email box.") );
return 1;
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Dispatcher.pm Fri Mar 16 01:09:19 2007
@@ -24,7 +24,11 @@
};
-on qr/^(?:passwordreminder|signup|login)$/ => run {
+on qr/^(?:passwordreminder|signup)$/ => run {
+ redirect('/') if ( Jifty->web->current_user->id );
+ set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/login" ) );
+};
+on qr/^(?:login)$/ => run {
redirect('/') if ( Jifty->web->current_user->id );
set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/" ) );
};
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Mixin/Model/User.pm
==============================================================================
--- /jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Model/User.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Mixin/Model/User.pm Fri Mar 16 01:09:19 2007
@@ -1,13 +1,13 @@
use strict;
use warnings;
-package Jifty::Plugin::Authentication::Password::Model::User;
+package Jifty::Plugin::Authentication::Password::Mixin::Model::User;
use Jifty::DBI::Schema;
use base 'Jifty::DBI::Record::Plugin';
use Digest::MD5 qw'';
-our @EXPORT = qw(password_is);
+our @EXPORT = qw(password_is hashed_password_is regenerate_auth_token);
use Jifty::Plugin::Authentication::Password::Record schema {
@@ -16,8 +16,7 @@
render_as 'unrendered',
type is 'varchar',
default is '',
- label is 'Authentication token',
- since '0.2.34';
+ label is 'Authentication token';
@@ -33,6 +32,12 @@
};
+sub register_triggers {
+ my $self = shift;
+ $self->add_trigger(name => 'after_create', callback => \&after_create);
+ $self->add_trigger(name => 'after_set_password', callback => \&after_set_password);
+ $self->add_trigger(name => 'validate_password', callback => \&validate_password, abortable =>1);
+}
=head2 password_is PASSWORD
@@ -89,7 +94,14 @@
sub after_create {
my $self = shift;
+ # We get a reference to the return value of insert
+ my $value = shift; return unless $$value; $self->load($$value);
$self->regenerate_auth_token;
+ if ( $self->id and $self->email and not $self->email_confirmed ) {
+ Jifty->app_class('Notification','ConfirmEmail')->new( to => $self )->send;
+ } else {
+ warn $self->id . " " .$self->email;
+ }
}
@@ -118,7 +130,7 @@
$auth_token .= unpack('H2', chr(int rand(255))) for (1..16);
- $self->set_auth_token($auth_token);
+ $self->__set(column => 'auth_token', value => $auth_token);
}
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm Fri Mar 16 01:09:19 2007
@@ -29,18 +29,9 @@
template 'signup' => page {
title is 'Signup';
my ( $action, $next ) = get(qw(action next));
-
- p {
- outs(
- _( "If you have an OpenID, there's no need to signup (unless you want to, of course). You can "
- )
- );
- hyperlink( label => _("log in"), url => '/login' );
- outs( _(" with it now!") );
- };
-
Jifty->web->form->start( call => $next );
- render_param( $action => $_ ) for ( $action->argument_names );
+ render_param( $action => 'name' , focus => 1);
+ render_param( $action => $_ ) for ( grep {$_ ne 'name'} $action->argument_names );
form_submit( label => _('Signup'), submit => $action );
Jifty->web->form->end();
};
Modified: jifty/trunk/lib/Jifty/Plugin/User/Mixin/Model/User.pm
==============================================================================
--- /jifty/trunk/lib/Jifty/Plugin/User/Model/User.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/User/Mixin/Model/User.pm Fri Mar 16 01:09:19 2007
@@ -1,42 +1,39 @@
use strict;
use warnings;
-package Jifty::Plugin::User::Model::User;
+package Jifty::Plugin::User::Mixin::Model::User;
use Jifty::DBI::Schema;
=head1 NAME
-Jifty::Plugin::User::Model::User
+Jifty::Plugin::User::Mixin::Model::User
=head1 DESCRIPTION
-package MyApp::Model::User;
-
-use Jifty::DBI::Schema;
-
-use MyApp::Record schema {
-
- # column definitions
-
-};
-
-use Jifty::Plugin::User::Model::User; # Imports two columns: name and username
-
+ package MyApp::Model::User;
+ use Jifty::DBI::Schema;
+ use MyApp::Record schema {
+ # column definitions
+ };
+
+ use Jifty::Plugin::User::Mixin::Model::User; # Imports two columns: name and email
+
=cut
-
use base 'Jifty::DBI::Record::Plugin';
use Jifty::Plugin::User::Record schema {
- column name => type is 'text', label is 'How should I display your name?';
+ column
+ name => type is 'text',
+ label is 'Nickname',
+ hints is 'How should I display your name to other users?';
column
email => type is 'text',
- label is 'Email',
- default is '', is immutable, is distinct;
+ label is 'Email address', default is '', is immutable, is distinct;
column
email_confirmed => label is 'Email address confirmed?',
- type is 'boolean', render_as 'Unrendered', is immutable;
+ type is 'boolean', render_as 'Unrendered';
};
@@ -63,7 +60,7 @@
unless ( $email eq $self->__value('email') ) {
$self->__set( column => 'email_confirmed', value => '0' );
- Jifty->app_class('Notification','ConfirmAddress')->new( to => $self )->send;
+ Jifty->app_class('Notification','ConfirmEmail')->new( to => $self )->send;
}
return (@ret);
Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/etc/config.yml
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-PasswordAuth/etc/config.yml (original)
+++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/etc/config.yml Fri Mar 16 01:09:19 2007
@@ -17,8 +17,9 @@
L10N:
PoDir: share/po
LogLevel: DEBUG
- Mailer: Sendmail
- MailerArgs: []
+ Mailer: IO
+ MailerArgs:
+ - %log/mail.log%
Plugins:
- User: {}
Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm (original)
+++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm Fri Mar 16 01:09:19 2007
@@ -10,10 +10,10 @@
};
-use Jifty::Plugin::User::Model::User;
-use TestApp::Plugin::FavoriteColor;
-use TestApp::Plugin::FasterSwallow;
-use Jifty::Plugin::Authentication::Password::Model::User 'password_is';
+#use TestApp::Plugin::FavoriteColor;
+#use TestApp::Plugin::FasterSwallow;
+use Jifty::Plugin::User::Mixin::Model::User;
+use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
# Your model-specific methods go here.
More information about the Jifty-commit
mailing list