Parley
view release on metacpan or search on metacpan
lib/Parley/Controller/User/SignUp.pm view on Meta::CPAN
# elsif ($c->form->has_invalid()) {
# $c->stash->{view}{error}{message}
# = $c->localize(q{DFV FIELDS INVALID});
# foreach my $f ( $c->form->invalid ) {
# push @{ $c->stash->{view}{error}{messages} }, $f;
# }
# }
#
# # otherwise the form data is ok...
# else {
# @messages = $self->_add_new_user($c, $results);
# }
return (uniq(sort @messages));
}
sub _username_exists {
my ($self, $c, $username) = @_;
# look for the specified username
$c->log->info("Looking for: $username");
my $match_count = $c->model('ParleyDB')->resultset('Authentication')->count(
username => $username,
);
# return the number of matches
return $match_count;
}
# send notification email
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Functions for database transactions
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub _txn_add_new_user {
my ($self, $c) = @_;
my ($valid_results, $new_auth, $new_person, $new_preference, $status_ok);
# less typing
$valid_results = $c->stash->{validation}->valid;
use Data::Dump qw(pp); $c->log->debug( pp($valid_results) );
# add authentication record
$new_auth = $c->model('ParleyDB')->resultset('Authentication')->create(
{
username => $valid_results->{new_username},
password => md5_hex( $valid_results->{new_password} ),
}
);
# add new person
$new_person = $c->model('ParleyDB')->resultset('Person')->create(
{
first_name => $valid_results->{first_name},
last_name => $valid_results->{last_name},
forum_name => $valid_results->{forum_name},
email => $valid_results->{email},
authentication_id => $new_auth->id(),
}
);
# add (default) prefs for new person
$new_preference = $c->model('ParleyDB')->resultset('Preference')->create(
{
# default everything
show_tz => 1,
}
);
# and link to the new person
$new_person->preference_id( $new_preference->id() );
$new_person->update;
# send an authentication email
$status_ok = $self->_new_user_authentication_email( $c, $new_person );
# if we sent the email OK take them off to a "it worked" type screen
if ($status_ok) {
$c->stash->{newdata} = $new_person;
$c->stash->{template} = q{user/auth_emailed};
}
}
1;
__END__
=pod
=head1 NAME
Parley::Controller::User::SignUp
=cut
vim: ts=8 sts=4 et sw=4 sr sta
( run in 1.382 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )