Sources for file plugins/auth/sql.php in version 4.0 Beta 1



Click on a comment to hide it. Click here to show all comments.

/**
 * Project:     Xnyo 4: Bubbles
 * File:        plugins/auth/sql.php
 *
 * Version:     4.0-dev
 * SVN Id:      $Id: sql.php 5 2007-05-18 03:49:07Z bok $
 * SVN URL:     $HeadURL: http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/auth/sql.php $
 * Authors:     Robert Amos <bok[at]odynia.org>
 *
 * Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/

class XnyoAuthSQL implements XnyoAuthPlugin
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo SQL Authentication Handler',
        
'description' => 'Authenticates against an SQL database',
        
'action' => XNYO_PLUGIN_ACTION_RETURN
    
);

    
/**
     * Constructor
    **/
    
private $xnyo;
    public function 
__construct ()
    {
        
$this->xnyo $GLOBALS['xnyo_parent'];
    }

    
/**
     * Login
    **/
    
public function login ($user$pass$domain)
    {
        
// for the SQL plugin, we need to know which table we are using. We use the domain switch for
that.
        if (
is_null($domain))
            
// default to the "table" parameter in $xnyo->session->params['table'];
            
if (!isset($this->xnyo->session->params['table']) ||
empty(
$this->xnyo->session->params['table']))
                throw new 
XnyoError('No DbSpec classname was passed as the $domain argument for
XnyoAuthPlugin::login() and $xnyo->session->params[\'
table\'] is empty, unable to continue
login.');
            else
                $domain = $this->xnyo->session->params['
table'];

        // assume that we SHA-1 the password if no function is specified.
        if (isset($this->xnyo->session->params['
hash']) && !empty($this->xnyo->session->params['hash']) &&
is_callable($this->xnyo->session->params['
hash']))
            $pass = call_user_func_array($this->xnyo->session->params['
hash'], array($pass));
         elseif (!isset($this->xnyo->session->params['
no_hash']))
            $pass = sha1($pass);

        // make an instance of the class then
        if (!class_exists($domain, false) && !$this->xnyo->inc($domain, XNYO_PLUGIN_DBSPEC))
            throw new XnyoError('
DbSpec plugin <b>%s</bwas not found.', $domain);

        //
        $table = new $domain;
        $email_field = isset($table->email) ? $table->email : '
email';
        $pass_field = isset($table->password) ? $table->password : '
password';    
        if (!$table->find(array($email_field => $user, $pass_field => $pass)))
            throw new XnyoClient($this->xnyo->session->errors['
invalid_login']);

        // remove any reference to a password field
        $table->removeColumn($pass_field);
        $row = $table->current();
        unset($row->{$pass_field});
        $data = $row->export();
        
        // do we need to filter back the email field?
        if (isset($table->email))
            $data->email = $data->{$email_field};

        // do we have a lastlogin column?
        if (isset($row->lastlogin))
            $row->lastlogin = time();

        return $data;
    }

}

Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.