Name

userdb — access user database functions

ATTRIBUTES

Attribute Pos. Req. Default Description
function Yes Yes
profile default UserDB profile
db | table
nickname | nick
show_message 0 whether to return message (success or error)
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

[userdb] provides access to UserDB functions.

Create New Account

[userdb new_account] registers a new account.

Logout function

[userdb logout] performs log out operation on the current user account:

[userdb logout]

Usually, data stored in the session should be removed at the same time:

[userdb function=logout clear=1]
[userdb function=logout clear_session=1]
[userdb function=logout clear_cookie="MV_PASSWORD"]

clear=1 resets all value and scratch variables initialized by the UserDB.

clear_session=1 forces the creation of an entirely new session for the user.

clear_cookie="NAME" expires the cookie NAME.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Save cart

[userdb function=set_cart nickname=basket]

Example: Restore cart

[userdb function=get_cart nickname=basket]

NOTES

AVAILABILITY

userdb is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/SystemTag/userdb.coretag
Lines: 16


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: userdb.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $

UserTag userdb              Order        function
UserTag userdb              addAttr
UserTag userdb              attrAlias    table db
UserTag userdb              attrAlias    name nickname
UserTag userdb              PosNumber    1
UserTag userdb              Version      $Revision: 1.5 $
UserTag userdb              MapRoutine   Vend::UserDB::userdb

Source: lib/Vend/UserDB.pm
Lines: 2554

sub userdb {
my $function = shift;
my $opt = shift;

my %options;

if(ref $opt) {
  %options = %$opt;
}
else {
  %options = ($opt, @_);
}

my $status = 1;
my $user;

my $module = $Vend::Cfg->{UserControl} ? 'Vend::UserControl' : 'Vend::UserDB';

if($function eq 'login') {
  $Vend::Session->{logged_in} = 0;
  delete $Vend::Session->{username};
  delete $Vend::Session->{groups};
  undef $Vend::username;
  undef $Vend::groups;
  undef $Vend::admin;
  $user = $module->new(%options);
  unless (defined $user) {
    $Vend::Session->{failure} = errmsg("Unable to access user database.");
    return undef;
  }
  if ($status = $user->login(%options) ) {
    if( $Vend::ReadOnlyCfg->{AdminUserDB}{$user->{PROFILE}} ) {
      $Vend::admin = 1;
    }
    ::update_user();
  }
}
elsif($function eq 'new_account') {
  $user = $module->new(%options);
  unless (defined $user) {
    $Vend::Session->{failure} = errmsg("Unable to access user database.");
    return undef;
  }
  $status = $user->new_account(%options);
  if($status and ! $options{no_login}) {
    $Vend::Session->{logged_in} = 1;
    $Vend::Session->{username} = $user->{USERNAME};
  }
}
elsif($function eq 'logout') {
  $user = $module->new(%options)
    or do {
      $Vend::Session->{failure} = errmsg("Unable to create user object.");
      return undef;
    };
  $user->logout();
}
elsif (! $Vend::Session->{logged_in}) {
  $Vend::Session->{failure} = errmsg("Not logged in.");
  return undef;
}
elsif($function eq 'save') {
  $user = $module->new(%options);
  unless (defined $user) {
    $Vend::Session->{failure} = errmsg("Unable to access user database.");
    return undef;
  }
  $status = $user->set_values();
}
elsif($function eq 'load') {
  $user = $module->new(%options);
  unless (defined $user) {
    $Vend::Session->{failure} = errmsg("Unable to access user database.");
    return undef;
  }
  $status = $user->get_values();
}
else {
  $user = $module->new(%options);
  unless (defined $user) {
    $Vend::Session->{failure} = errmsg("Unable to access user database.");
    return undef;
  }
  eval {
    $status = $user->$function(%options);
  };
  $user->{ERROR} = $@ if $@;
}

if(defined $status) {
  delete $Vend::Session->{failure};
  $Vend::Session->{success} = $user->{MESSAGE};
  if($options{show_message}) {
    $status = $user->{MESSAGE};
  }
}
else {
  $Vend::Session->{failure} = $user->{ERROR};
  if($options{show_message}) {
    $status = $user->{ERROR};
  }
}
return $status unless $options{hide};
return;
}

AUTHORS

Interchange Development Group

SEE ALSO

UserDB(7ic), UserControl(7ic), load_cart(7ic), save_cart(7ic), delete_cart(7ic)

DocBook! Interchange!