[interchange-cvs] interchange - heins modified lib/Vend/UserDB.pm
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Mon Jul 24 13:06:59 EDT 2006
User: heins
Date: 2006-07-24 17:06:59 GMT
Modified: lib/Vend UserDB.pm
Log:
* Add username_email option so that one can easily user the username
as an email address. It is as simple as:
UserDB default username_email 1
Suggested also is:
UserDB default ignore_case 1
This simply makes the value of username be set in the email field. The
name of the field defaults to "email", but can be set:
UserDB default username_email_field other_email_field
It doesn't gang the email field to username. We could set a
way of changing username -- I will look at that.
* Add a "constant" feature. This is similar to the "scratch" feature,
but allows you to set immutable session values in $Session->{constant}.
If the database field "foo" had the value of "bar" in it, then
this:
UserDB default constant foo
would result in this in upon login:
$Vend::Session->{constant} = { foo => 'bar' }
* Add a "session_hash" feature. This is similar to the "scratch" feature,
but allows you to set hashes of session values in $Session->{$foo}.
If the database field "key_phrase" had the value of "{ foo => 'bar'}"
in it, then this:
UserDB default session_hash key_phrase
would result in this in upon login:
$Vend::Session->{key_phrase} = { foo => 'bar' }
* Add the ability to redirect scratch, constant, and session_hash
variables to different DB fields, i.e.:
UserDB default scratch database_field=scratch_field
if the database field "bar" had the value of "baz" in it, then this:
UserDB default scratch foo=bar
would result in:
$Scratch->{foo} eq 'baz'
Revision Changes Path
2.43 +141 -21 interchange/lib/Vend/UserDB.pm
rev 2.43, prev_rev 2.42
Index: UserDB.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/UserDB.pm,v
retrieving revision 2.42
retrieving revision 2.43
diff -u -r2.42 -r2.43
--- UserDB.pm 9 Dec 2005 17:39:26 -0000 2.42
+++ UserDB.pm 24 Jul 2006 17:06:59 -0000 2.43
@@ -1,6 +1,6 @@
# Vend::UserDB - Interchange user database functions
#
-# $Id: UserDB.pm,v 2.42 2005/12/09 17:39:26 racke Exp $
+# $Id: UserDB.pm,v 2.43 2006/07/24 17:06:59 mheins Exp $
#
# Copyright (C) 2002-2005 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -17,7 +17,7 @@
package Vend::UserDB;
-$VERSION = substr(q$Revision: 2.42 $, 10);
+$VERSION = substr(q$Revision: 2.43 $, 10);
use vars qw!
$VERSION
@@ -530,6 +530,10 @@
$ignore{$_} = 1;
}
+ if($self->{OPTIONS}{username_email}) {
+ $ignore{$self->{OPTIONS}{username_email_field} || 'email'} = 1;
+ }
+
for(values %{$self->{LOCATION}}) {
$ignore{$_} = 1;
}
@@ -568,22 +572,52 @@
@fields = @{ $self->{DB_FIELDS} } unless @fields;
+ my %constant;
my %scratch;
+ my %session_hash;
+
+ if($self->{OPTIONS}->{constant}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{constant} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $constant{$k} = $v;
+ }
+ }
if($self->{OPTIONS}->{scratch}) {
- my (@s) = split /[\s,]+/, $self->{OPTIONS}{scratch} ;
- @scratch{@s} = @s;
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{scratch} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $scratch{$k} = $v;
+ }
+ }
+
+ if($self->{OPTIONS}->{session_hash}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{session_hash} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $session_hash{$k} = $v;
+ }
}
for(@fields) {
- if($scratch{$_}) {
- if (exists $Vend::Cfg->{ScratchDefault}->{$_}) {
- $::Scratch->{$_} = $Vend::Cfg->{ScratchDefault}->{$_};
+ if(my $s = $scratch{$_}) {
+ if (exists $Vend::Cfg->{ScratchDefault}->{$s}) {
+ $::Scratch->{$s} = $Vend::Cfg->{ScratchDefault}->{$s};
}
else {
- delete $::Scratch->{$_};
+ delete $::Scratch->{$s};
}
}
+ elsif($constant{$_}) {
+ delete $Vend::Session->{constant}{$constant{$_}};
+ }
+ elsif($session_hash{$_}) {
+ delete $Vend::Session->{$session_hash{$_}};
+ }
else {
if (exists $Vend::Cfg->{ValuesDefault}->{$_}) {
$::Values->{$_} = $Vend::Cfg->{ValuesDefault}->{$_};
@@ -599,10 +633,11 @@
}
sub get_values {
- my($self, $valref, $scratchref) = @_;
+ my($self, $valref, $scratchref, $constref) = @_;
$valref = $::Values unless ref($valref);
$scratchref = $::Scratch unless ref($scratchref);
+ $constref = $Vend::Session->{constant} unless ref($constref);
my @fields = @{ $self->{DB_FIELDS} };
@@ -616,6 +651,8 @@
my %ignore;
my %scratch;
+ my %constant;
+ my %session_hash;
for(values %{$self->{LOCATION}}) {
$ignore{$_} = 1;
@@ -627,10 +664,34 @@
push @fields, keys %outboard;
}
+ if($self->{OPTIONS}->{constant}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{constant} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $constant{$k} = $v;
+ }
+#::logDebug("constant ones: " . join " ", @s);
+ }
+
+ if($self->{OPTIONS}->{session_hash}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{session_hash} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $session_hash{$k} = $v;
+ }
+#::logDebug("session_hash ones: " . join " ", @s);
+ }
+
if($self->{OPTIONS}->{scratch}) {
- my (@s) = split /[\s,]+/, $self->{OPTIONS}{scratch} ;
- @scratch{@s} = @s;
-#::logError("scratch ones: " . join " ", @s);
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{scratch} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $scratch{$k} = $v;
+ }
+#::logDebug("scratch ones: " . join " ", @s);
}
my @needed;
@@ -665,11 +726,20 @@
$val = $row->{$_};
}
- if($scratch{$_}) {
- $::Scratch->{$_} = $val;
+ my $k;
+ if($k = $scratch{$_}) {
+ $scratchref->{$k} = $val;
next;
}
- $::Values->{$_} = $val;
+ elsif($k = $constant{$_}) {
+ $constref->{$k} = $val;
+ next;
+ }
+ elsif($k = $session_hash{$_}) {
+ $Vend::Session->{$k} = string_to_ref($val) || {};
+ next;
+ }
+ $valref->{$_} = $val;
}
@@ -687,10 +757,11 @@
}
sub set_values {
- my($self, $valref, $scratchref) = @_;
+ my($self, $valref, $scratchref, $constref) = @_;
$valref = $::Values unless ref($valref);
$scratchref = $::Scratch unless ref($scratchref);
+ $constref = $Vend::Session->{constant} unless ref($constref);
my $user = $self->{USERNAME};
@@ -703,10 +774,34 @@
return undef;
}
my %scratch;
+ my %constant;
+ my %session_hash;
if($self->{OPTIONS}->{scratch}) {
- my (@s) = split /[\s,]+/, $self->{OPTIONS}{scratch} ;
- @scratch{@s} = @s;
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{scratch} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $scratch{$k} = $v;
+ }
+ }
+
+ if($self->{OPTIONS}->{constant}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{constant} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $constant{$k} = $v;
+ }
+ }
+
+ if($self->{OPTIONS}->{session_hash}) {
+ my (@s) = grep /\w/, split /[\s,]+/, $self->{OPTIONS}{session_hash} ;
+ for(@s) {
+ my ($k, $v) = split /=/, $_;
+ $v ||= $k;
+ $session_hash{$k} = $v;
+ }
}
my $val;
@@ -742,9 +837,17 @@
for( @fields ) {
#::logDebug("set_values saving $_ as $valref->{$_}\n");
my $val;
- if ($scratch{$_}) {
- $val = $scratchref->{$_}
- if defined $scratchref->{$_};
+ my $k;
+ if ($k = $scratch{$_}) {
+ $val = $scratchref->{$k}
+ if defined $scratchref->{$k};
+ }
+ elsif ($constant{$_}) {
+ # we never store constants
+ next;
+ }
+ elsif ($k = $session_hash{$_}) {
+ $val = uneval_it($Vend::Session->{$k});
}
else {
$val = $valref->{$_}
@@ -776,6 +879,8 @@
push @bvals, shift @extra;
}
+#::logDebug("bfields=" . ::uneval(\@bfields));
+#::logDebug("bvals=" . ::uneval(\@bvals));
if(@bfields) {
$db->set_slice($user, \@bfields, \@bvals);
}
@@ -1499,6 +1604,9 @@
die errmsg("Sorry, reserved user name.") . "\n"
if $self->{OPTIONS}{username_mask}
and $self->{USERNAME} =~ m!$self->{OPTIONS}{username_mask}!;
+ die errmsg("Sorry, user name must be an email address.") . "\n"
+ if $self->{OPTIONS}{username_email}
+ and $self->{USERNAME} !~ m!^[a-zA-Z]([.]?([[:alnum:]_-]+)*)?@([[:alnum:]\-_]+\.)+[a-zA-Z]{2,4}$!;
die errmsg("Must enter at least %s characters for password.",
$self->{PASSMINLEN}) . "\n"
if length($self->{PASSWORD}) < $self->{PASSMINLEN};
@@ -1574,7 +1682,19 @@
$self->{LOCATION}{PASSWORD},
$pw,
);
+
die errmsg("Database access error.") . "\n" unless defined $pass;
+
+ if($self->{OPTIONS}{username_email}) {
+ my $field_name = $self->{OPTIONS}{username_email_field} || 'email';
+ $::Values->{$field_name} ||= $self->{USERNAME};
+ $udb->set_field(
+ $self->{USERNAME},
+ $field_name,
+ $self->{USERNAME},
+ )
+ or die errmsg("Database access error: %s", $udb->errstr) . "\n";
+ }
if($options{no_login}) {
$Vend::Session->{auto_created_user} = $self->{USERNAME};
More information about the interchange-cvs
mailing list