AMF-Perl

 view release on metacpan or  search on metacpan

doc/examples/petmarket/petmarket/api/userservice.pm  view on Meta::CPAN

            "description" => "Add a user with the given credentials",
            "access" => "remote", 
        },
        "updateUser" => {
            "description" => "Add a user with the given credentials",
            "access" => "remote", 
        },
    };
    
}

my @userFields = ("firstname", "lastname", "homestreet1", "homestreet2", "homecity", "homestate", "homecountry", "homezip", "homephone", "creditcardnumber", "creditcardtype", "creditcardexpiry");

my @shippingFields = ("shippingstreet1", "shippingstreet2", "shippingcity", "shippingcountry", "shippingzip", "shippingphone"); 

my @fields = ("email", "password", @userFields, @shippingFields);

sub authenticate
{
    my ($self, $email, $password) = @_;
    my $ary_ref = $self->dbh->selectall_arrayref("SELECT count(*) FROM user_details where email='$email' AND password='$password'");

    return $ary_ref->[0]->[0] > 0;
}

sub addUser
{
    my ($self, $email, $password) = @_;
	
    $self->dbh->do("INSERT INTO user_details set email='$email', password='$password'");

    my $result = new AMF::Perl::Util::Object;
    $result->{"useroid"} = $email;
    $result->{"email"} = $email;
    $result->{"password"} = $password;

    return $result;
}


sub getUser
{
  my ($self, $email, $password) = @_;

    return 0 unless $self->authenticate($email, $password);

    my $result = new AMF::Perl::Util::Object;

    my $hash_ref = $self->dbh->selectall_hashref("SELECT * FROM user_details WHERE email='$email'", "email");

    my $rowRef = $hash_ref->{$email};

    foreach my $field (@fields)
    {
        $result->{$field} = $rowRef->{$field};
    }
    $result->{useroid} = $email;
    return $result;
}

sub updateUser
{
    my ($self, $userObject) = @_;

    return 0 unless $self->authenticate($userObject->{"email"}, $userObject->{"password"});

    my $setString = "";

    my @setStringArray = map {"$_='".$userObject->{$_}."'"} @userFields;
    $setString = join ",", @setStringArray;

    $self->dbh->do("UPDATE user_details SET $setString");

    return $userObject;
}

1;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.586 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )