?? ecshop.php
字號:
<?php
/**
* ECSHOP 會員數據處理類
* ============================================================================
* 版權所有 (C) 2005-2008 康盛創想(北京)科技有限公司,并保留所有權利。
* 網站地址: http://www.ecshop.com;http://www.comsenz.com
* ----------------------------------------------------------------------------
* 這不是一個自由軟件!您只能在不用于商業目的的前提下對程序代碼進行修改和
* 使用;不允許對程序代碼以任何形式任何目的的再發布。
* ============================================================================
* $Author: testyang $
* $Id: ecshop.php 14724 2008-07-14 06:36:29Z testyang $
*/
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
class ecshop
{
var $db;
function __construct()
{
$this->ecshop();
}
/**
* ECSHOP初始化
*
* @access public
*
* @return void
*/
function ecshop()
{
/*$this->user_table = 'users';
$this->field_id = 'user_id';
$this->field_name = 'user_name';
$this->field_pass = 'password';
$this->field_email = 'email';
$this->field_gender = 'sex';
$this->field_bday = 'birthday';
$this->field_reg_date = 'reg_time';
$this->need_sync = true;
$this->is_ecshop = 1;
$this->charset = EC_CHARSET;*/
$this->db = $GLOBALS['db'];
}
/**
* 用戶登錄函數
*
* @access public
* @param string $username
* @param string $password
*
* @return void
*/
function login($username, $password)
{
list($uid, $uname, $pwd, $email, $repeat) = uc_call("uc_user_login", array($username, $password));
$uname = addslashes($uname);
if($uid > 0)
{
//檢查用戶是否存在,不存在直接放入用戶表
$user_exist = $this->db->getOne("SELECT user_id FROM " . $GLOBALS['ecs']->table("users") . " WHERE user_name='$username'");
if (empty($user_exist))
{
$reg_date = time();
$ip = real_ip();
$this->db->query('INSERT INTO ' . $GLOBALS['ecs']->table("users") . "(`user_id`, `email`, `user_name`, `reg_time`, `last_login`, `last_ip`) VALUES ('$uid', '$email', '$uname', '$reg_date', '$reg_date', '$ip')");
}
$this->set_session($uname);
$this->set_cookie($uname);
$this->ucdata = uc_call("uc_user_synlogin", array($uid));
return true;
}
elseif($uid == -1)
{
$this->error = ERR_INVALID_USERNAME;
return false;
}
elseif ($uid == -2)
{
$this->error = ERR_INVALID_PASSWORD;
return false;
}
else
{
return false;
}
}
/**
* 用戶退出
*
* @access public
* @param
*
* @return void
*/
function logout()
{
$this->set_cookie(); //清除cookie
$this->set_session(); //清除session
$this->ucdata = uc_call("uc_user_synlogout"); //同步退出
return true;
}
/*添加用戶*/
function add_user($username, $password, $email)
{
/* 檢測用戶名 */
if ($this->check_user($username))
{
$this->error = ERR_USERNAME_EXISTS;
return false;
}
/* email檢查取消
if ($this->check_email($email))
{
$this->error = ERR_EMAIL_EXISTS;
return false;
}*/
$uid = uc_call("uc_user_register", array($username, $password, $email));
if ($uid <= 0)
{
if($uid == -1)
{
$this->error = ERR_INVALID_USERNAME;
return false;
}
elseif($uid == -2)
{
$this->error = ERR_USERNAME_NOT_ALLOW;
return false;
}
elseif($uid == -3)
{
$this->error = ERR_USERNAME_EXISTS;
return false;
}
elseif($uid == -4)
{
$this->error = ERR_INVALID_EMAIL;
return false;
}
elseif($uid == -5)
{
$this->error = ERR_EMAIL_NOT_ALLOW;
return false;
}
elseif($uid == -6)
{
$this->error = ERR_EMAIL_EXISTS;
return false;
}
else
{
return false;
}
}
else
{
//注冊成功,插入用戶表
$reg_date = time();
$ip = real_ip();
$this->db->query('INSERT INTO ' . $GLOBALS['ecs']->table("users") . "(`user_id`, `email`, `user_name`, `reg_time`, `last_login`, `last_ip`) VALUES ('$uid', '$email', '$username', '$reg_date', '$reg_date', '$ip')");
return true;
}
}
/**
* 檢查指定用戶是否存在及密碼是否正確
*
* @access public
* @param string $username 用戶名
*
* @return int
*/
function check_user($username)
{
$userdata = uc_call("uc_user_checkname", array($username));
if ($userdata == 1)
{
return false;
}
else
{
return true;
}
}
/**
* 檢測Email是否合法
*
* @access public
* @param string $email 郵箱
*
* @return blob
*/
function check_email($email)
{
if (!empty($email))
{
/* 檢查email是否重復 */
$sql = "SELECT user_id FROM " . $GLOBALS['ecs']->table('users') . " WHERE email = '$email' ";
if ($this->db->getOne($sql, true) > 0)
{
$this->error = ERR_EMAIL_EXISTS;
return true;
}
return false;
}
return true;
}
/* 編輯用戶信息 */
function edit_user($cfg, $forget_pwd = '0')
{
$real_username = $cfg['username'];
$cfg['username'] = addslashes($cfg['username']);
$set_str = '';
$valarr =array('email'=>'email', 'gender'=>'sex', 'bday'=>'birthday');
foreach ($cfg as $key => $val)
{
if ($key == 'username' || $key == 'password' || $key == 'old_password')
{
continue;
}
$set_str .= $valarr[$key] . '=' . "'$val',";
}
$set_str = substr($set_str, 0, -1);
if (!empty($set_str))
{
$sql = "UPDATE " . $GLOBALS['ecs']->table('users') . " SET $set_str WHERE user_name = '$cfg[username]'";
$GLOBALS['db']->query($sql);
$flag = true;
}
if (!empty($cfg['email']))
{
$ucresult = uc_call("uc_user_edit", array($cfg['username'], '', '', $cfg['email'], 1));
if ($ucresult > 0 )
{
$flag = true;
}
elseif($ucresult == -4)
{
//echo 'Email 格式有誤';
$this->error = ERR_INVALID_EMAIL;
return false;
}
elseif($ucresult == -5)
{
//echo 'Email 不允許注冊';
$this->error = ERR_INVALID_EMAIL;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -