Jifty::Plugin::Authentication::Password::Action::Signup - signup for an account


Jifty documentation Contained in the Jifty distribution.

Index


Code Index:

NAME

Top

Jifty::Plugin::Authentication::Password::Action::Signup - signup for an account

arguments

The fields for Signup are:

email: the email address
password and password_confirm: the requested password
name: your full name

validate_email

Make sure their email address looks sane

take_action

Overrides the virtual take_action method on Jifty::Action to call the appropriate Jifty::Record's create method when the action is run, thus creating a new object in the database.

Makes sure that the user only specifies things we want them to.


Jifty documentation Contained in the Jifty distribution.
use warnings;
use strict;

package Jifty::Plugin::Authentication::Password::Action::Signup;
our @ISA;
{
    my $class = Jifty->app_class('Action', 'CreateUser');
    push @ISA, $class;
}

sub arguments {
    my $self = shift;
    my $args = $self->SUPER::arguments();
    

    my %fields = (
        name             => 1,
        email            => 1,
        password         => 1,
        password_confirm => 1,
    );

    for (keys %$args){
        delete $args->{$_} unless $fields{$_};
    }

    $args->{'email'}{'ajax_validates'}   = 1;
    $args->{'email'}{'mandatory'}        = 1;
    $args->{'name'}{'ajax_validates'}   = 1;
    $args->{'password_confirm'}{'label'} = _("Type that again?");
    return $args;
}

sub validate_email {
    my $self  = shift;
    my $email = shift;
    my $LoginUser   = Jifty->app_class('Model', 'User');
    my $CurrentUser   = Jifty->app_class('CurrentUser');


    return $self->validation_error( email => _("That doesn't look like an email address.") ) unless ( $email =~ /\S\@\S/ );

    my $u = $LoginUser->new( current_user => $CurrentUser->superuser );
    $u->load_by_cols( email => $email );
    if ( $u->id ) {
        return $self->validation_error( email => _('It looks like you already have an account. Perhaps you want to <a href="/login">log in</a> instead?')
        );
    }

    return $self->validation_ok('email');
}

sub take_action {
    my $self   = shift;
    my $LoginUser   = Jifty->app_class('Model', 'User');
    my $CurrentUser   = Jifty->app_class('CurrentUser');
        
    my $record = $LoginUser->new( current_user => $CurrentUser->superuser );

    my %values;
    $values{$_} = $self->argument_value($_) for grep {
        defined $self->record->column($_) and defined $self->argument_value($_)
    } $self->argument_names;

    my ($id, $msg) = $record->create(%values);

    # Handle errors?
    unless ( $record->id ) {
        $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)
          . ' ' . _("We've sent a confirmation message to your email box.") );

    return 1;
}

1;