Ejemplo n.º 1
0
 /**
  * 根据账户名获取用户
  * @param string $account
  */
 private function GetAccountUser($account)
 {
     $ar = [];
     $account = trim($account);
     if (is_numeric($account)) {
         $ar['id'] = abs(intval($account));
     } else {
         if (filter_var($account, FILTER_VALIDATE_EMAIL)) {
             $ar['user_email'] = $account;
         } else {
             lib()->load('UserCheck');
             if (!UserCheck::CheckUsernameChar($account)) {
                 $this->throwMsg(-1);
             } else {
                 $ar['user_name'] = $account;
             }
         }
     }
     lib()->load('User');
     try {
         $this->user = new User($ar);
     } catch (\Exception $ex) {
         $this->throwMsg(-2);
     }
 }
Ejemplo n.º 2
0
c_lib()->load('sql');
$sql = new \CLib\Sql(cfg()->get('sql', 'write'), cfg()->get('sql', 'read'));
c_lib()->add("sql", $sql);
$option_setting = "INSERT INTO `options` (`option_name`,`option_value`,`option_autoload`)\nVALUES\n('site_title', '{title}', '1'),\n('site_desc', '{desc}', '1'),\n('site_url', '{url}', '1'),\n('admin_email', '{email}', '1'),\n('allowed_register', 'yes', '1'),\n('allowed_comment', 'yes', '1'),\n('default_avatar', 'default', '1'),\n('email_notice', 'yes', '1'),\n('site_style', 'default', '1'),\n('login_captcha', 'no', '1'),\n('picture_server', 'local', '1'),\n('image_thumbnail_width', '400', '1'),\n('image_thumbnail_height', '300', '1'),\n('image_hd_width', '1600', '1'),\n('image_display_width', '900', '1'),\n('comment_one_page', '5', '1'),\n('comment_order_desc', 'yes', '1'),\n('comment_deep', '8', '1'),\n('router_list', 'a:0:{}', '1'),\n('site_static_url', '{static_url}', '1'),\n('cdn', '', '1');";
$req = req()->_escape();
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$post = $req->post('s');
foreach (['title', 'desc', 'url', 'email', 'static_url'] as $v) {
    if (!isset($post[$v]) || empty($post[$v])) {
        die("系统设置有空字段:" . $v);
    }
}
$user = $req->post('u');
lib()->load('UserCheck');
if (!\ULib\UserCheck::CheckUsernameChar($user['name'])) {
    die("用户名称检测错误");
}
$user['pwd'] = \ULib\UserCheck::MakeHashChar($user['pwd']);
$user['email'] = $post['email'];
if (!\ULib\UserCheck::CheckEmailChar($user['email'])) {
    die("管理员邮箱格式不正确");
}
$option_setting = str_replace(['{title}', '{desc}', '{url}', '{email}', '{static_url}'], [$post['title'], $post['desc'], $post['url'], $post['email'], $post['static_url']], $option_setting);
$pdo = $sql->getWriter();
$pdo->exec("delete from `options` where `id` > 0");
$pdo->exec("alter table `options` auto_increment=1;");
$pdo->exec($option_setting);
lib()->load('UserRegister', 'UserCheck', 'User');
hook()->add('UserRegister_Captcha', function () {
    //通过钩子去掉用户注册验证码
Ejemplo n.º 3
0
 /**
  * @param $list array
  * @throws \Exception
  */
 public function set($list)
 {
     $data = [];
     $update = [];
     foreach ($list as $name => $value) {
         $name = trim($name);
         if ($name !== 'id' && in_array($name, self::$column_list)) {
             $data[$name] = $value;
             $update["user_" . $name] = $value;
             if (substr($name, -3) === '_ip') {
                 $update["user_" . $name] = Ip::getInstance()->ip2bin($value);
             }
         }
     }
     lib()->load('UserCheck');
     if (isset($update['user_aliases']) && empty($update['user_aliases'])) {
         throw new \Exception(_("Aliases can't set empty."));
     }
     if (isset($update['user_email']) && !UserCheck::CheckEmailChar($update['user_email'])) {
         throw new \Exception(_("Email verify check Error"));
     }
     if (isset($update['user_name']) && !UserCheck::CheckUsernameChar($update['user_name'])) {
         throw new \Exception(_("Username verify check Error"));
     }
     if (isset($update['user_password']) && !UserCheck::CheckPasswordChar($update['user_password'])) {
         throw new \Exception(_("Password verify check Error"));
     }
     if (isset($update['user_url']) && $update['user_url'] != "" && !filter_var($update['user_url'], FILTER_VALIDATE_URL)) {
         throw new \Exception(_("Url check error"));
     }
     if (count($update) > 0) {
         if (db()->update("users", $update, ['id' => $this->id]) === false) {
             throw new \Exception(_("Can't update User info.") . debug("SQL msg:" . implode(",", db()->error()['write'])));
         }
         foreach ($data as $n => $v) {
             $this->{$n} = $v;
         }
     }
 }