| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
CatalystX::Usul::Model::Config::Credentials - Database connection definitions
0.3.$Revision: 591 $
# The constructor is called by Catalyst at startup
Maintains database connection strings
Defines the language independent attributes; driver, host, password, port and user for the credentials element. Returns a CatalystX::Usul::Model::Config object
Defined the ctrldir attribute
$c->model( q(Config::Credentials) )->create_or_update( $stash, $args );
Encrypts the $args->{req}->params->{password} attribute by calling
encrypt in CatalystX::Usul::Schema. Then calls method of same
name in CatalystX::Usul::Model::Config
$c->model( q(Config::Credentials) )->credentials_form( $stash );
Stuffs the stash with the data to build the credentials maintenance form
None
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <Support at RoxSoft.co.uk>
Copyright (c) 2008 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
# @(#)$Id: Credentials.pm 591 2009-06-13 13:34:41Z pjf $ package CatalystX::Usul::Model::Config::Credentials; use strict; use warnings; use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 591 $ =~ /\d+/gmx ); use parent qw(CatalystX::Usul::Model::Config); use CatalystX::Usul::Schema; use Class::C3; __PACKAGE__->config ( create_msg_key => q(Credentials [_1]/[_2] created), delete_msg_key => q(Credentials [_1]/[_2] deleted), keys_attr => q(acct), schema_attributes => { attributes => [ qw(driver host password port user) ], defaults => {}, element => q(credentials), lang_dep => undef, }, typelist => {}, update_msg_key => q(Credentials [_1]/[_2] updated) ); __PACKAGE__->mk_accessors( qw(ctrldir) ); sub new { my ($self, $app, @rest) = @_; my $new = $self->next::method( $app, @rest ); $new->ctrldir( $app->config->{ctrldir} || q() ); return $new; } sub create_or_update { my ($self, $args) = @_; my $req = $self->context->req; my $val; if (defined ($val = $self->query_value( q(password) ))) { $val = CatalystX::Usul::Schema->encrypt( $self->_seed, $val ); $req->params->{password} = q(encrypt=).$val; } $self->next::method( $args ); return; } sub credentials_form { my ($self, $level, $acct) = @_; my ($def, $e, $id); my $data = eval { $self->get_list( $level, $acct ) }; return $self->add_error( $e ) if ($e = $self->catch); my $s = $self->context->stash; $s->{pwidth} -= 10; my $creds = $data->list; unshift @{ $creds }, q(), $s->{newtag}; my $levels = [ sort keys %{ $s->{levels} } ]; my $form = $s->{form}->{name}; my $fields = $data->element; my $nitems = 0; my $stepno = 1; unshift @{ $levels }, q(), q(default); if ($fields->password and $fields->password =~ m{ \A encrypt= (.+) \z }mx) { my $schema_class = q(CatalystX::Usul::Schema); $fields->password( $schema_class->decrypt( $self->_seed, $1 ) ); } $self->clear_form( { firstfld => $form.q(.acct) } ); $self->add_field( { default => $level, id => q(config.level), stepno => 0, values => $levels } ); $nitems++; if ($level) { $self->add_field( { default => $acct, id => $form.q(.acct), stepno => 0, values => $creds } ); $nitems++; } $self->group_fields( { id => $form.q(.select), nitems => $nitems } ); $nitems = 0; return unless ($level and $acct and $self->is_member( $acct, @{ $creds } )); if ($acct eq $s->{newtag}) { $self->add_buttons( qw(Insert) ); $def = q(); $id = $form.'.nameNew'; } else { $self->add_buttons( qw(Save Delete) ); $def = $acct; $id = $form.'.name'; } $self->add_field( { ajaxid => $form.'.name', default => $def, id => $id, name => q(name), stepno => $stepno++ } ); $nitems++; $self->add_field( { ajaxid => $form.'.driver', default => $fields->driver, stepno => $stepno++ } ); $nitems++; $self->add_field( { ajaxid => $form.'.host', default => $fields->host, stepno => $stepno++ } ); $nitems++; $self->add_field( { ajaxid => $form.'.port', default => $fields->port, stepno => $stepno++ } ); $nitems++; $self->add_field( { ajaxid => $form.'.user', default => $fields->user, stepno => $stepno++ } ); $nitems++; $self->add_field( { default => $fields->password, id => $form.'.password', stepno => $stepno++ } ); $nitems++; $self->group_fields( { id => $form.'.edit', nitems => $nitems } ); return; } # Private methods sub _seed { my $self = shift; my ($args, $path); $path = $self->catfile( $self->ctrldir, $self->prefix.q(.txt) ); $args = { seed => $self->secret }; $args->{data} = $self->io( $path )->all if (-f $path); return $args; } 1; __END__
# Local Variables: # mode: perl # tab-width: 3 # End: