Exemple #1
0
 public function login()
 {
     if (!$this->feather->user->is_guest) {
         Url::redirect($this->feather->urlFor('home'), 'Already logged in');
     }
     if ($this->feather->request->isPost()) {
         $this->feather->hooks->fire('login_start');
         $form_username = Utils::trim($this->feather->request->post('req_username'));
         $form_password = Utils::trim($this->feather->request->post('req_password'));
         $save_pass = (bool) $this->feather->request->post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == $this->feather->forum_env['FEATHER_UNVERIFIED']) {
                     ModelAuth::update_group($user->id, $this->feather->forum_settings['o_default_user_group']);
                     if (!$this->feather->cache->isCached('users_info')) {
                         $this->feather->cache->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip($this->feather->request->getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? $this->feather->now + 1209600 : $this->feather->now + $this->feather->forum_settings['o_timeout_visit'];
                 $expire = $this->feather->hooks->fire('expire_login', $expire);
                 ModelAuth::feather_setcookie($user->id, $form_password_hash, $expire);
                 Url::redirect($this->feather->urlFor('home'), __('Login redirect'));
             }
         }
         throw new Error(__('Wrong user/pass') . ' <a href="' . $this->feather->urlFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
     } else {
         $this->feather->template->setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape($this->feather->forum_settings['o_board_title']), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }
Exemple #2
0
 public function markforumread($id)
 {
     $tracked_topics = get_tracked_topics();
     $tracked_topics['forums'][$id] = time();
     Track::set_tracked_topics($tracked_topics);
     Url::redirect($this->feather->urlFor('Forum', array('id' => $id)), __('Mark forum read redirect'));
 }
Exemple #3
0
 public function display($req, $res, $args)
 {
     if (!isset($args['page'])) {
         $args['page'] = null;
     }
     if (!isset($args['pid'])) {
         $args['pid'] = null;
     }
     if (!isset($args['name'])) {
         $args['name'] = null;
     }
     Container::get('hooks')->fire('controller.topic.display', $args['id'], $args['name'], $args['page'], $args['pid']);
     // Antispam feature
     $lang_antispam_questions = (require ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/antispam.php');
     $index_questions = rand(0, count($lang_antispam_questions) - 1);
     // Fetch some informations about the topic
     $cur_topic = $this->model->get_info_topic($args['id']);
     // Sort out who the moderators are and if we are currently a moderator (or an admin)
     $mods_array = $cur_topic['moderators'] != '' ? unserialize($cur_topic['moderators']) : array();
     $is_admmod = User::get()->g_id == ForumEnv::get('FEATHER_ADMIN') || User::get()->g_moderator == '1' && array_key_exists(User::get()->username, $mods_array) ? true : false;
     // Can we or can we not post replies?
     $post_link = $this->model->get_post_link($args['id'], $cur_topic['closed'], $cur_topic['post_replies'], $is_admmod);
     // Add/update this topic in our list of tracked topics
     if (!User::get()->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$args['id']] = time();
         Track::set_tracked_topics($tracked_topics);
     }
     // Determine the post offset (based on $_GET['p'])
     $num_pages = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
     $p = !isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages ? 1 : intval($args['page']);
     $start_from = User::get()->disp_posts * ($p - 1);
     $url_topic = Url::url_friendly($cur_topic['subject']);
     $url_forum = Url::url_friendly($cur_topic['forum_name']);
     // Generate paging links
     $paging_links = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate($num_pages, $p, 'topic/' . $args['id'] . '/' . $url_topic . '/#');
     if (ForumSettings::get('o_censoring') == '1') {
         $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
     }
     $quickpost = $this->model->is_quickpost($cur_topic['post_replies'], $cur_topic['closed'], $is_admmod);
     $subscraction = $this->model->get_subscraction($cur_topic['is_subscribed'] == User::get()->id, $args['id']);
     View::addAsset('canonical', Router::pathFor('Forum', ['id' => $args['id'], 'name' => $url_forum]));
     if ($num_pages > 1) {
         if ($p > 1) {
             View::addAsset('prev', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p - 1)]));
         }
         if ($p < $num_pages) {
             View::addAsset('next', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p + 1)]));
         }
     }
     if (ForumSettings::get('o_feed_type') == '1') {
         View::addAsset('feed', 'extern.php?action=feed&amp;fid=' . $args['id'] . '&amp;type=rss', array('title' => __('RSS forum feed')));
     } elseif (ForumSettings::get('o_feed_type') == '2') {
         View::addAsset('feed', 'extern.php?action=feed&amp;fid=' . $args['id'] . '&amp;type=atom', array('title' => __('Atom forum feed')));
     }
     View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), Utils::escape($cur_topic['forum_name']), Utils::escape($cur_topic['subject'])), 'active_page' => 'Topic', 'page_number' => $p, 'paging_links' => $paging_links, 'is_indexed' => true, 'id' => $args['id'], 'pid' => $args['pid'], 'tid' => $args['id'], 'fid' => $cur_topic['forum_id'], 'post_data' => $this->model->print_posts($args['id'], $start_from, $cur_topic, $is_admmod), 'cur_topic' => $cur_topic, 'subscraction' => $subscraction, 'post_link' => $post_link, 'start_from' => $start_from, 'quickpost' => $quickpost, 'index_questions' => $index_questions, 'lang_antispam_questions' => $lang_antispam_questions, 'url_forum' => $url_forum, 'url_topic' => $url_topic))->addTemplate('topic.php')->display();
     // Increment "num_views" for topic
     $this->model->increment_views($args['id']);
 }
Exemple #4
0
 public function markread()
 {
     Container::get('hooks')->fire('controller.index.markread');
     Auth::set_last_visit(User::get()->id, User::get()->logged);
     // Reset tracked topics
     Track::set_tracked_topics(null);
     return Router::redirect(Router::pathFor('home'), __('Mark read redirect'));
 }
Exemple #5
0
 public function display($id = null, $name = null, $page = null, $pid = null)
 {
     // Antispam feature
     require $this->feather->forum_env['FEATHER_ROOT'] . 'featherbb/lang/' . $this->feather->user->language . '/antispam.php';
     $index_questions = rand(0, count($lang_antispam_questions) - 1);
     // Fetch some informations about the topic
     $cur_topic = $this->model->get_info_topic($id);
     // Sort out who the moderators are and if we are currently a moderator (or an admin)
     $mods_array = $cur_topic['moderators'] != '' ? unserialize($cur_topic['moderators']) : array();
     $is_admmod = $this->feather->user->g_id == $this->feather->forum_env['FEATHER_ADMIN'] || $this->feather->user->g_moderator == '1' && array_key_exists($this->feather->user->username, $mods_array) ? true : false;
     if ($is_admmod) {
         $admin_ids = Utils::get_admin_ids();
     }
     // Can we or can we not post replies?
     $post_link = $this->model->get_post_link($id, $cur_topic['closed'], $cur_topic['post_replies'], $is_admmod);
     // Add/update this topic in our list of tracked topics
     if (!$this->feather->user->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$id] = time();
         Track::set_tracked_topics($tracked_topics);
     }
     // Determine the post offset (based on $_GET['p'])
     $num_pages = ceil(($cur_topic['num_replies'] + 1) / $this->feather->user->disp_posts);
     $p = !isset($page) || $page <= 1 || $page > $num_pages ? 1 : intval($page);
     $start_from = $this->feather->user->disp_posts * ($p - 1);
     $url_topic = Url::url_friendly($cur_topic['subject']);
     $url_forum = Url::url_friendly($cur_topic['forum_name']);
     // Generate paging links
     $paging_links = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate($num_pages, $p, 'topic/' . $id . '/' . $url_topic . '/#');
     if ($this->feather->forum_settings['o_censoring'] == '1') {
         $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
     }
     $quickpost = $this->model->is_quickpost($cur_topic['post_replies'], $cur_topic['closed'], $is_admmod);
     $subscraction = $this->model->get_subscraction($cur_topic['is_subscribed'], $id);
     $lang_bbeditor = array('btnBold' => __('btnBold'), 'btnItalic' => __('btnItalic'), 'btnUnderline' => __('btnUnderline'), 'btnColor' => __('btnColor'), 'btnLeft' => __('btnLeft'), 'btnRight' => __('btnRight'), 'btnJustify' => __('btnJustify'), 'btnCenter' => __('btnCenter'), 'btnLink' => __('btnLink'), 'btnPicture' => __('btnPicture'), 'btnList' => __('btnList'), 'btnQuote' => __('btnQuote'), 'btnCode' => __('btnCode'), 'promptImage' => __('promptImage'), 'promptUrl' => __('promptUrl'), 'promptQuote' => __('promptQuote'));
     $this->feather->template->addAsset('canonical', $this->feather->urlFor('Forum', ['id' => $id, 'name' => $url_forum]));
     if ($num_pages > 1) {
         if ($p > 1) {
             $this->feather->template->addAsset('prev', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p - 1)]));
         }
         if ($p < $num_pages) {
             $this->feather->template->addAsset('next', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p + 1)]));
         }
     }
     if ($this->feather->forum_settings['o_feed_type'] == '1') {
         $this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid=' . $id . '&amp;type=rss', array('title' => __('RSS forum feed')));
     } elseif ($this->feather->forum_settings['o_feed_type'] == '2') {
         $this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid=' . $id . '&amp;type=atom', array('title' => __('Atom forum feed')));
     }
     $this->feather->template->setPageInfo(array('title' => array(Utils::escape($this->feather->forum_settings['o_board_title']), Utils::escape($cur_topic['forum_name']), Utils::escape($cur_topic['subject'])), 'active_page' => 'Topic', 'page_number' => $p, 'paging_links' => $paging_links, 'is_indexed' => true, 'id' => $id, 'pid' => $pid, 'tid' => $id, 'fid' => $cur_topic['forum_id'], 'post_data' => $this->model->print_posts($id, $start_from, $cur_topic, $is_admmod), 'cur_topic' => $cur_topic, 'subscraction' => $subscraction, 'post_link' => $post_link, 'start_from' => $start_from, 'lang_antispam' => $lang_antispam, 'quickpost' => $quickpost, 'index_questions' => $index_questions, 'lang_antispam_questions' => $lang_antispam_questions, 'lang_bbeditor' => $lang_bbeditor, 'url_forum' => $url_forum, 'url_topic' => $url_topic))->addTemplate('Topic.php')->display();
     // Increment "num_views" for topic
     $this->model->increment_views($id);
 }
Exemple #6
0
 public function login()
 {
     $this->hook->fire('login_start');
     $form_username = Utils::trim($this->request->post('req_username'));
     $form_password = Utils::trim($this->request->post('req_password'));
     $save_pass = $this->request->post('save_pass');
     $user = DB::for_table('users')->where('username', $form_username);
     $user = $this->hook->fireDB('find_user_login', $user);
     $user = $user->find_one();
     $authorized = false;
     if (!empty($user->password)) {
         $form_password_hash = Random::hash($form_password);
         // Will result in a SHA-1 hash
         $authorized = $user->password == $form_password_hash;
     }
     $authorized = $this->hook->fire('authorized_login', $authorized);
     if (!$authorized) {
         throw new Error(__('Wrong user/pass') . ' <a href="' . $this->feather->urlFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
     }
     // Update the status if this is the first time the user logged in
     if ($user->group_id == $this->feather->forum_env['FEATHER_UNVERIFIED']) {
         $update_usergroup = DB::for_table('users')->where('id', $user->id)->find_one()->set('group_id', $this->config['o_default_user_group']);
         $update_usergroup = $this->hook->fireDB('update_usergroup_login', $update_usergroup);
         $update_usergroup = $update_usergroup->save();
         // Regenerate the users info cache
         if (!$this->feather->cache->isCached('users_info')) {
             $this->feather->cache->store('users_info', Cache::get_users_info());
         }
         $stats = $this->feather->cache->retrieve('users_info');
     }
     // Remove this user's guest entry from the online list
     $delete_online = DB::for_table('online')->where('ident', $this->request->getIp());
     $delete_online = $this->hook->fireDB('delete_online_login', $delete_online);
     $delete_online = $delete_online->delete_many();
     $expire = $save_pass == '1' ? time() + 1209600 : time() + $this->config['o_timeout_visit'];
     $expire = $this->hook->fire('expire_login', $expire);
     $this->auth->feather_setcookie($user->id, $form_password_hash, $expire);
     // Reset tracked topics
     Track::set_tracked_topics(null);
     // Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login)
     $redirect_url = $this->request->post('redirect_url');
     $redirect_url = $this->hook->fire('redirect_url_login', $redirect_url);
     Url::redirect(Utils::escape($redirect_url), __('Login redirect'));
 }
Exemple #7
0
 public function update_online()
 {
     // Define this if you want this visit to affect the online list and the users last visit data
     if (!defined('FEATHER_QUIET_VISIT')) {
         // Update the online list
         if (!$this->app->user->logged) {
             $this->app->user->logged = $this->app->now;
             // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table
             switch ($this->app->forum_settings['db_type']) {
                 case 'mysql':
                 case 'mysqli':
                 case 'mysql_innodb':
                 case 'mysqli_innodb':
                 case 'sqlite':
                 case 'sqlite3':
                     DB::for_table('online')->raw_execute('REPLACE INTO ' . $this->app->forum_settings['db_prefix'] . 'online (user_id, ident, logged) VALUES(:user_id, :ident, :logged)', array(':user_id' => $this->app->user->id, ':ident' => $this->app->user->username, ':logged' => $this->app->user->logged));
                     break;
                 default:
                     DB::for_table('online')->raw_execute('INSERT INTO ' . $this->app->forum_settings['db_prefix'] . 'online (user_id, ident, logged) SELECT :user_id, :ident, :logged WHERE NOT EXISTS (SELECT 1 FROM ' . $this->app->db->prefix . 'online WHERE user_id=:user_id)', array(':user_id' => $this->app->user->id, ':ident' => $this->app->user->username, ':logged' => $this->app->user->logged));
                     break;
             }
             // Reset tracked topics
             Track::set_tracked_topics(null);
         } else {
             // Special case: We've timed out, but no other user has browsed the forums since we timed out
             if ($this->app->user->logged < $this->app->now - $this->app->forum_settings['o_timeout_visit']) {
                 DB::for_table('users')->where('id', $this->app->user->id)->find_one()->set('last_visit', $this->app->user->logged)->save();
                 $this->app->user->last_visit = $this->app->user->logged;
             }
             $idle_sql = $this->app->user->idle == '1' ? ', idle=0' : '';
             DB::for_table('online')->raw_execute('UPDATE ' . $this->app->forum_settings['db_prefix'] . 'online SET logged=' . $this->app->now . $idle_sql . ' WHERE user_id=:user_id', array(':user_id' => $this->app->user->id));
             // Update tracked topics with the current expire time
             $cookie_tracked_topics = $this->app->getCookie($this->app->forum_settings['cookie_name'] . '_track');
             if (isset($cookie_tracked_topics)) {
                 Track::set_tracked_topics(json_decode($cookie_tracked_topics, true));
             }
         }
     } else {
         if (!$this->app->user->logged) {
             $this->app->user->logged = $this->app->user->last_visit;
         }
     }
 }
Exemple #8
0
 public function login($req, $res, $args)
 {
     if (!User::get()->is_guest) {
         return Router::redirect(Router::pathFor('home'), 'Already logged in');
     }
     if (Request::isPost()) {
         Container::get('hooks')->fire('controller.login');
         $form_username = Input::post('req_username');
         $form_password = Input::post('req_password');
         $save_pass = (bool) Input::post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == ForumEnv::get('FEATHER_UNVERIFIED')) {
                     ModelAuth::update_group($user->id, ForumSettings::get('o_default_user_group'));
                     if (!Container::get('cache')->isCached('users_info')) {
                         Container::get('cache')->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip(Utils::getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit');
                 $expire = Container::get('hooks')->fire('controller.expire_login', $expire);
                 $jwt = ModelAuth::generate_jwt($user, $expire);
                 ModelAuth::feather_setcookie('Bearer ' . $jwt, $expire);
                 return Router::redirect(Router::pathFor('home'), __('Login redirect'));
             } else {
                 throw new Error(__('Wrong user/pass') . ' <a href="' . Router::pathFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
             }
         }
     } else {
         View::setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }
Exemple #9
0
 public function increment_post_count($post, $new_tid)
 {
     Container::get('hooks')->fire('model.post.increment_post_count_start', $post, $new_tid);
     if (!User::get()->is_guest) {
         $increment = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('last_post', $post['time'])->set_expr('num_posts', 'num_posts+1');
         $increment = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $increment);
         $increment = $increment->save();
         // Promote this user to a new group if enabled
         if (User::get()->g_promote_next_group != 0 && User::get()->num_posts + 1 >= User::get()->g_promote_min_posts) {
             $new_group_id = User::get()->g_promote_next_group;
             $promote = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('group_id', $new_group_id);
             $promote = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $promote);
             $promote = $promote->save();
         }
         // Topic tracking stuff...
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$new_tid] = time();
         Track::set_tracked_topics($tracked_topics);
     } else {
         // Update the last_post field for guests
         $last_post = DB::for_table('online')->where('ident', Utils::getIp())->find_one()->set('last_post', $post['time']);
         $last_post = Container::get('hooks')->fireDB('model.post.increment_post_count_last_post', $last_post);
         $last_post = $last_post->save();
     }
     Container::get('hooks')->fire('model.post.increment_post_count');
 }
Exemple #10
0
 public function markread($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.forum.markread');
     $tracked_topics = Track::get_tracked_topics();
     $tracked_topics['forums'][$args['id']] = time();
     Track::set_tracked_topics($tracked_topics);
     return Router::redirect(Router::pathFor('Forum', ['id' => $args['id']]), __('Mark forum read redirect'));
 }