public static function do_register_action() { self::method('post'); try { $checker = new lazy_checker(p()); $checker->check('name', array('change_to' => 'string', 'cannot_be' => array('', '用户名不能为空'), 'char_size' => array(3, user_model::name_len, '用户名的长度为%d-%d个字符'), 'callback' => function ($name) { if (user_model::get_one(array('name' => $name)) !== null) { return '该用户已被注册'; } })); $checker->check('pass', array('change_to' => 'string', 'cannot_be' => array('', '密码不能为空'), 'char_size' => array(6, -1, '密码长度必须大于等于%d个字符'))); if (p_str('re_pass') !== $checker->pass) { $checker->failed('pass', '两次输入的密码不一致'); } $salt = random_sha1(); $pass = user_model::get_crypted_pass($checker->pass, $salt); $user = array('name' => $checker->name, 'pass' => $pass, 'salt' => $salt, 'register_time' => clock::get_stamp()); $user_id = user_model::add($user); visitor::set_role('user', $user_id, 0, array('name' => $user['name'])); online_service::refresh_online_count(); self::json_result(true, '', 0, url('site/index')); } catch (check_failed $e) { self::json_result(false, $e->get_reasons()); } }
public static function new_action() { // 拦截 self::method('post'); $post_id = g_int('post_id'); $post = post_model::get_by_id($post_id); self::forward_404_if($post === null, '文章不存在,无法评论'); try { // 校验 $checker = new lazy_checker(p()); $checker->check('captcha', array('should_be' => array(setting_model::get_by_id(setting_model::id_captcha_answer)->value, '验证码不正确'))); $checker->del('captcha'); $checker->check_model_rules('comment'); $comment = $checker->get_all(); if (!visitor::has_role('member') && member_model::get_one(array('name' => $comment['author'])) !== null) { $checker->failed('author', '您不能使用管理员的昵称'); } // 执行 $comment['post_id'] = $post_id; $comment['pub_time'] = clock::get_stamp(); comment_model::add($comment); post_model::inc_by_id(array('comment_count' => 1), $post_id); setting_model::inc_by_id(array('value' => 1), setting_model::id_comment_count); // 成功 self::json_result(true, '评论成功', 0, url('post/show?id=' . $post_id)); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } }
public function clean() { $current_time = clock::get_stamp(); $sql = "DELETE FROM `{$this->table_name}` WHERE `expire_time` <= " . $current_time; $this->conn->query($sql); if (kernel::is_debug()) { debug::save('session', $sql); } }
public function set($key, $value, $seconds = self::forever) { $cache_file = $this->get_cache_file_from_key($key); if ($seconds === self::forever) { $expire = self::max_expire; } else { $expire = clock::get_stamp() + $seconds; if ($expire > self::max_expire) { $expire = self::max_expire; } } $data = $this->build_data($value, $expire); if (kernel::is_debug()) { debug::save('cache', 'filesys set: file -> ' . $cache_file . ', data -> ' . var_export($data, true)); } return @file_put_contents($cache_file, $data, LOCK_EX) !== false; }
public static function do_new_action() { self::method('post'); self::role('user'); self::csrf('user'); $board_id = g_int('board_id', 1); $board = board_model::get_by_id($board_id); try { $checker = new lazy_checker(p()); $checker->check('title', array('change_to' => 'string', 'char_size' => array(3, topic_model::title_len, '标题长度为%d到%d个字符'))); $checker->check('content', array('change_to' => 'string', 'char_size' => array(6, topic_model::content_len, '内容长度为%d到%d个字符'))); $user_id = visitor::get_role_id('user'); $topic = array('board_id' => $board_id, 'user_id' => $user_id, 'pub_time' => clock::get_stamp(), 'title' => $checker->title, 'content' => $checker->content); $topic_id = topic_service::new_topic($topic); self::json_result(true, '', 0, url('topic/show?id=' . $topic_id)); } catch (check_failed $e) { self::json_result(false, $e->get_reasons()); } }
public static function new_action() { self::method('post'); self::role('user', 'forward_to', 'site/login'); self::csrf('user'); $topic_id = g_int('topic_id'); $topic = topic_model::get_by_id($topic_id); self::forward_404_if($topic === null, '主题不存在。'); try { $checker = new lazy_checker(p()); $checker->check('content', array('change_to' => 'string', 'char_size' => array(6, reply_model::content_len, '内容长度为%d到%d个字符'))); $pub_time = clock::get_stamp(); $user_id = visitor::get_role_id('user'); $reply = array('board_id' => $topic->board_id, 'topic_id' => $topic_id, 'user_id' => $user_id, 'pub_time' => $pub_time, 'content' => $checker->content); reply_service::new_reply($reply); self::json_result(true, '', 0, url('topic/show?id=' . $topic_id)); } catch (check_failed $e) { self::json_result(false, $e->get_reasons()); } }
public static function new_action() { // 拦截 self::method('post'); try { // 校验 $checker = new lazy_checker(p()); $checker->check('captcha', array('should_be' => array(setting_model::get_by_id(setting_model::id_captcha_answer)->value, '验证码不正确'))); $checker->del('captcha'); $checker->check_model_rules('message'); // 执行 $message = $checker->get_all(); $message['pub_time'] = clock::get_stamp(); message_model::add($message); // 成功 self::json_result(true, '留言成功。', 0, url('site/about')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } }
public static function do_new_action() { // 拦截 self::method('post'); self::role('member'); self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('post'); // 执行 $props = $checker->get_all(); $tags = $props['tags']; unset($props['tags']); $props['member_id'] = visitor::get_role_id('member'); $props['pub_time'] = clock::get_stamp(); $post = new post_model(); $post->set_props($props); publish_service::publish($post, $tags); // 成功 self::json_result(true, '文章发表成功', 0, url('post/show?id=' . $post->id)); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } }