add($GLOBALS['_LANG']['shop_register_closed']);
}
/* 检查username */
if (empty($username)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['username_empty']);
} else {
if (preg_match('/\'\/^\\s*$|^c:\\\\con\\\\con$|[%,\\*\\"\\s\\t\\<\\>\\&\'\\\\]/', $username)) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_invalid'], htmlspecialchars($username)));
}
}
/* 检查email */
if (empty($email)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['email_empty']);
} else {
if (!is_email($email)) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], htmlspecialchars($email)));
}
}
if ($GLOBALS['err']->error_no > 0) {
return false;
}
/* 检查是否和管理员重名 */
if (admin_registered($username)) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_exist'], $username));
return false;
}
if (!$GLOBALS['user']->add_user($username, $password, $email)) {
if ($GLOBALS['user']->error == ERR_INVALID_USERNAME) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_invalid'], $username));
} elseif ($GLOBALS['user']->error == ERR_USERNAME_NOT_ALLOW) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_not_allow'], $username));
} elseif ($GLOBALS['user']->error == ERR_USERNAME_EXISTS) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_exist'], $username));
} elseif ($GLOBALS['user']->error == ERR_INVALID_EMAIL) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], $email));
} elseif ($GLOBALS['user']->error == ERR_EMAIL_NOT_ALLOW) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_not_allow'], $email));
} elseif ($GLOBALS['user']->error == ERR_EMAIL_EXISTS) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_exist'], $email));
} else {
$GLOBALS['err']->add('UNKNOWN ERROR!');
}
//注册失败
return false;
} else {
/* 设置成登录状态 */
$GLOBALS['user']->set_session($username);
$GLOBALS['user']->set_cookie($username);
/* 注册送积分 */
if (!empty($GLOBALS['_CFG']['register_points'])) {
log_account_change($_SESSION['user_id'], 0, 0, $GLOBALS['_CFG']['register_points'], $GLOBALS['_CFG']['register_points'], $GLOBALS['_LANG']['register_points']);
}
/*推荐处理*/
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
if (isset($affiliate['on']) && $affiliate['on'] == 1) {
// 推荐开关开启
$up_uid = get_affiliate();
empty($affiliate) && $affiliate = array();
$affiliate['config']['level_register_all'] = intval($affiliate['config']['level_register_all']);
$affiliate['config']['level_register_up'] = intval($affiliate['config']['level_register_up']);
if ($up_uid) {
if (!empty($affiliate['config']['level_register_all'])) {
if (!empty($affiliate['config']['level_register_up'])) {
$rank_points = $GLOBALS['db']->getOne("SELECT rank_points FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$up_uid'");
if ($rank_points + $affiliate['config']['level_register_all'] <= $affiliate['config']['level_register_up']) {
log_account_change($up_uid, 0, 0, $affiliate['config']['level_register_all'], 0, sprintf($GLOBALS['_LANG']['register_affiliate'], $_SESSION['user_id'], $username));
}
} else {
log_account_change($up_uid, 0, 0, $affiliate['config']['level_register_all'], 0, $GLOBALS['_LANG']['register_affiliate']);
}
}
//设置推荐人
$sql = 'UPDATE ' . $GLOBALS['ecs']->table('users') . ' SET parent_id = ' . $up_uid . ' WHERE user_id = ' . $_SESSION['user_id'];
$GLOBALS['db']->query($sql);
}
}
//定义other合法的变量数组
$other_key_array = array('msn', 'qq', 'office_phone', 'home_phone', 'mobile_phone', 'parent_id');
$update_data['reg_time'] = local_strtotime(local_date('Y-m-d H:i:s'));
if ($other) {
foreach ($other as $key => $val) {
//删除非法key值
if (!in_array($key, $other_key_array)) {
unset($other[$key]);
} else {
$other[$key] = htmlspecialchars(trim($val)); //防止用户输入javascript代码
}
}
$update_data = array_merge($update_data, $other);
}
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('users'), $update_data, 'UPDATE', 'user_id = ' . $_SESSION['user_id']);
update_user_info(); // 更新用户信息
recalculate_price(); // 重新计算购物车中的商品价格
return true;
}
}
/**
*
*
* @access public
* @param
*
* @return void
*/
function logout()
{
/* todo */
}
/**
* 将指定user_id的密码修改为new_password。可以通过旧密码和验证字串验证修改。
*
* @access public
* @param int $user_id 用户ID
* @param string $new_password 用户新密码
* @param string $old_password 用户旧密码
* @param string $code 验证码(md5($user_id . md5($password)))
*
* @return boolen $bool
*/
function edit_password($user_id, $old_password, $new_password = '', $code = '')
{
if (empty($user_id)) $GLOBALS['err']->add($GLOBALS['_LANG']['not_login']);
if ($GLOBALS['user']->edit_password($user_id, $old_password, $new_password, $code)) {
return true;
} else {
$GLOBALS['err']->add($GLOBALS['_LANG']['edit_password_failure']);
return false;
}
}
/**
* 会员找回密码时,对输入的用户名和邮件地址匹配
*
* @access public
* @param string $user_name 用户帐号
* @param string $email 用户Email
*
* @return boolen
*/
function check_userinfo($user_name, $email)
{
if (empty($user_name) || empty($email)) {
ecs_header("Location: user.php?act=get_password\n");
exit;
}
/* 检测用户名和邮件地址是否匹配 */
$user_info = $GLOBALS['user']->check_pwd_info($user_name, $email);
if (!empty($user_info)) {
return $user_info;
} else {
return false;
}
}
/**
* 用户进行密码找回操作时,发送一封确认邮件
*
* @access public
* @param string $uid 用户ID
* @param string $user_name 用户帐号
* @param string $email 用户Email
* @param string $code key
*
* @return boolen $result;
*/
function send_pwd_email($uid, $user_name, $email, $code)
{
if (empty($uid) || empty($user_name) || empty($email) || empty($code)) {
ecs_header("Location: user.php?act=get_password\n");
exit;
}
/* 设置重置邮件模板所需要的内容信息 */
$code=rand(1000,9999);
session('maildata',array('email'=>$email,'code'=>md5($code)));
$template="{$user_name}您好!
您已经进行了密码重置的操作,请点认真保管您的验证码:
您的验证码是: