Improve authentication on install, fix SQL installation

pull/25/head
root 3 years ago
parent 0b0b61a6dd
commit 3b5c4547a1

@ -1,12 +1,11 @@
<?php <?php
use Fuel\Core\Controller_Template;
use Fuel\Core\Lang; use Fuel\Core\Lang;
use Fuel\Core\Response; use Fuel\Core\Response;
use Fuel\Core\Session; use Fuel\Core\Session;
use Fuel\Core\View; use Fuel\Core\View;
class Controller_Admin extends Controller_Template class Controller_Admin extends Controller_Security
{ {
public $template = 'admin/body'; public $template = 'admin/body';

@ -1,13 +1,11 @@
<?php <?php
use Fuel\Core\Controller_Template;
use Fuel\Core\Debug;
use Fuel\Core\Lang; use Fuel\Core\Lang;
use Fuel\Core\Response; use Fuel\Core\Response;
use Fuel\Core\Session; use Fuel\Core\Session;
use Fuel\Core\View; use Fuel\Core\View;
class Controller_Home extends Controller_Template class Controller_Home extends Controller_Security
{ {
public $template = 'layout/index'; public $template = 'layout/index';
@ -71,7 +69,7 @@ class Controller_Home extends Controller_Template
$this->template->MenuLibraries = $this->template->MenuServer ? $this->template->MenuServer->getLibraries() : null; $this->template->MenuLibraries = $this->template->MenuServer ? $this->template->MenuServer->getLibraries() : null;
$watching_movies = Model_User_Watching::find_by([ $watching_movies = Model_User_History::find_by([
['user_id', '=', $this->_user->id], ['user_id', '=', $this->_user->id],
['is_ended', '=', 0] ['is_ended', '=', 0]
]); ]);

@ -8,7 +8,13 @@ class Controller_Index extends Controller
{ {
public function before() public function before()
{ {
$lock = Config::load('lock', true);
if(!$lock)
Response::redirect('/install');
$user = Session::get('user'); $user = Session::get('user');
if(!$user) if(!$user)
Response::redirect('/login'); Response::redirect('/login');
else else

@ -15,14 +15,15 @@ class Controller_Login extends Controller
{ {
parent::before(); parent::before();
$user = Session::get('user');
$lock = Config::load('lock', true); $lock = Config::load('lock', true);
if($user)
Response::redirect('/home');
if(!$lock) if(!$lock)
Response::redirect('/install'); Response::redirect('/install');
$user = Session::get('user');
if($user)
Response::redirect('/home');
} }
public function action_index() public function action_index()

@ -12,6 +12,12 @@ class Controller_Register extends Controller
public function before() public function before()
{ {
parent::before(); parent::before();
$lock = Config::load('lock', true);
if(!$lock)
Response::redirect('/install');
$user = Session::get('user'); $user = Session::get('user');
if($user) if($user)

@ -311,10 +311,10 @@ class Controller_Rest_Install extends Controller_Rest
* CREATE TABLE USER'S WATCHING * CREATE TABLE USER'S WATCHING
*/ */
DBUtil::create_table( DBUtil::create_table(
'user_watching', 'user_history',
array( array(
'id' => array('constraint' => 36, 'type' => 'varchar'), 'id' => array('constraint' => 36, 'type' => 'varchar'),
'user_id' => array('constraint' => 11, 'type' => 'int'), 'user_id' => array('constraint' => 36, 'type' => 'varchar'),
'movie_id' => array('constraint' => 36, 'type' => 'varchar'), 'movie_id' => array('constraint' => 36, 'type' => 'varchar'),
'watching_time' => array('constraint' => 11, 'type' => 'int'), 'watching_time' => array('constraint' => 11, 'type' => 'int'),
'ended_time' => array('constraint' => 11, 'type' => 'int', 'default' => 0), 'ended_time' => array('constraint' => 11, 'type' => 'int', 'default' => 0),
@ -437,8 +437,8 @@ class Controller_Rest_Install extends Controller_Rest
'on_update' => 'NO ACTION', 'on_update' => 'NO ACTION',
'on_delete' => 'NO ACTION', 'on_delete' => 'NO ACTION',
)); ));
/*DBUtil::add_foreign_key('user_watching', array( DBUtil::add_foreign_key('user_history', array(
'constraint' => 'constraintUserUserWatching', 'constraint' => 'constraintUserUserHistory',
'key' => 'user_id', 'key' => 'user_id',
'reference' => array( 'reference' => array(
'table' => 'user', 'table' => 'user',
@ -446,9 +446,9 @@ class Controller_Rest_Install extends Controller_Rest
), ),
'on_update' => 'NO ACTION', 'on_update' => 'NO ACTION',
'on_delete' => 'NO ACTION', 'on_delete' => 'NO ACTION',
));*/ ));
DBUtil::add_foreign_key('user_watching', array( DBUtil::add_foreign_key('user_history', array(
'constraint' => 'constraintMovieWatching', 'constraint' => 'constraintMovieHistory',
'key' => 'movie_id', 'key' => 'movie_id',
'reference' => array( 'reference' => array(
'table' => 'movie', 'table' => 'movie',
@ -514,18 +514,18 @@ class Controller_Rest_Install extends Controller_Rest
return $this->response(['error' => false, 'message' => $logs]); return $this->response(['error' => false, 'message' => $logs]);
} catch (FuelException $e) { } catch (FuelException $e) {
try { try {
DBUtil::drop_table('user_watching'); DBUtil::drop_table('user_history');
DBUtil::drop_table('user_permission'); DBUtil::drop_table('user_permission');
DBUtil::drop_table('user_settings'); DBUtil::drop_table('user_settings');
DBUtil::drop_table('library_permission'); DBUtil::drop_table('library_permission');
DBUtil::drop_table('movie'); DBUtil::drop_table('movie');
DBUtil::drop_table('season'); DBUtil::drop_table('season');
DBUtil::drop_table('tvshow'); DBUtil::drop_table('tvshow');
DBUtil::drop_table('library'); DBUtil::drop_table('library');
DBUtil::drop_table('server'); DBUtil::drop_table('server');
DBUtil::drop_table('configurations'); DBUtil::drop_table('configurations');
DBUtil::drop_table('user'); DBUtil::drop_table('user');
DBUtil::drop_table('permission'); DBUtil::drop_table('permission');
DBUtil::drop_table('library'); DBUtil::drop_table('library');
return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); return $this->response(array('error' => true, 'message' => $e->getMessage()), 400);

@ -8,9 +8,9 @@ use Fuel\Core\Session;
use Fuel\Core\View; use Fuel\Core\View;
use Fuel\Core\FuelException; use Fuel\Core\FuelException;
class Controller_Rest_Movie extends Controller_Rest_Index class Controller_Rest_Movie extends Controller_Rest
{ {
public function get_stream(): object public function get_stream()
{ {
try { try {
@ -30,10 +30,10 @@ class Controller_Rest_Movie extends Controller_Rest_Index
throw new FuelException('You dont have the permission to watch in this library!'); throw new FuelException('You dont have the permission to watch in this library!');
} }
$user_settings = Model_Setting::find_one_by('user_id', Session::get('user')->id); $user_settings = Model_User_Settings::find_one_by('user_id', Session::get('user')->id);
if ($movie->type !== 'movie') { if ($movie->type !== 'movie') {
$episodes = $movie->getSeason()?->getEpisodes(); $episodes = $movie->getSeason()->getEpisodes();
} }
else { else {
$episodes = [$movie]; $episodes = [$movie];
@ -60,10 +60,10 @@ class Controller_Rest_Movie extends Controller_Rest_Index
$timeplay = Input::post('timeplay'); $timeplay = Input::post('timeplay');
$isFinish = Input::post('isFinish'); $isFinish = Input::post('isFinish');
$watching = Model_User_Watching::find_one_by([ $watching = Model_User_History::find_one_by([
['movie_id', '=', $movie_id], ['movie_id', '=', $movie_id],
['user_id', '=', $user->id] ['user_id', '=', $user->id]
]) ?: new Model_User_Watching(); ]) ?: new Model_User_History();
$watching->set([ $watching->set([
'user_id' => $user->id, 'user_id' => $user->id,

@ -24,10 +24,10 @@ class Controller_Rest_Player extends Controller_Rest
if (!$movie) if (!$movie)
throw new FuelException('No movie found'); throw new FuelException('No movie found');
$user_watching = Model_User_Watching::find_one_by([ $user_watching = Model_User_History::find_one_by([
['movie_id', '=', $movie_id], ['movie_id', '=', $movie_id],
['movie_id', '=', $user->id] ['movie_id', '=', $user->id]
]) ?: new Model_User_Watching(); ]) ?: new Model_User_History();
return $this->response(['error' => false, 'message' => 'OK!'], 200); return $this->response(['error' => false, 'message' => 'OK!'], 200);
} catch (Exception $exception) { } catch (Exception $exception) {

@ -0,0 +1,26 @@
<?php
use Fuel\Core\Controller_Template;
use Fuel\Core\Response;
use Fuel\Core\Session;
class Controller_Security extends Controller_Template
{
public function before()
{
parent::before();
$lock = Config::load('lock', true);
if(!$lock)
Response::redirect('/install');
$user = Session::get('user');
if(!$user)
Response::redirect('/login');
}
public function action_index()
{
// DO NOTHING
}
}

@ -1,14 +1,13 @@
<?php <?php
use Fuel\Core\Config; use Fuel\Core\Config;
use Fuel\Core\Controller_Template;
use Fuel\Core\Input; use Fuel\Core\Input;
use Fuel\Core\Lang; use Fuel\Core\Lang;
use Fuel\Core\Response; use Fuel\Core\Response;
use Fuel\Core\Session; use Fuel\Core\Session;
use Fuel\Core\View; use Fuel\Core\View;
class Controller_Settings extends Controller_Template class Controller_Settings extends Controller_Security
{ {
public $template = 'settings/body'; public $template = 'settings/body';
@ -65,12 +64,12 @@ class Controller_Settings extends Controller_Template
$default_settings = Config::load('user_settings'); $default_settings = Config::load('user_settings');
$settings = Model_Setting::find_one_by('user_id', Session::get('user')->id); $settings = Model_User_Settings::find_one_by('user_id', Session::get('user')->id);
$is_submit = Input::post('submit'); $is_submit = Input::post('submit');
if(isset($is_submit)) { if(isset($is_submit)) {
$settings = !empty($settings) ? $settings : new Model_Setting(); $settings = !empty($settings) ? $settings : new Model_User_Settings();
$settings->set([ $settings->set([
'user_id' => $this->_user->id, 'user_id' => $this->_user->id,
'language' => Input::post('language'), 'language' => Input::post('language'),

@ -2,9 +2,9 @@
class Model_User_Watching extends Model_Overwrite class Model_User_History extends Model_Overwrite
{ {
protected static $_table_name = 'user_watching'; protected static $_table_name = 'user_history';
protected static $_primary_key = 'id'; protected static $_primary_key = 'id';
protected static $_properties = array( protected static $_properties = array(
'id', 'id',

@ -1,8 +1,8 @@
<?php <?php
class Model_Setting extends Model_Overwrite class Model_User_Settings extends Model_Overwrite
{ {
protected static $_table_name = 'user_setting'; protected static $_table_name = 'user_settings';
protected static $_primary_key = 'id'; protected static $_primary_key = 'id';
protected static $_rules = array( protected static $_rules = array(
'user_id' => 'required', 'user_id' => 'required',

@ -253,50 +253,34 @@
let number = 1; let number = 1;
$('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]').each(function (index, element) { $('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]:not(.hasBackground)').each(function (index, element) {
let movie_id = $(element).data('movie-id'); let movie_id = $(element).data('movie-id');
let position = element.getBoundingClientRect();
let movie = document.querySelector('[data-movie-id="' + movie_id + '"] > div');
if( position.top > 0 && position.top <= (window.innerHeight || document.documentElement.clientHeight) && !movie.classList.contains('hasBackground') ) { this.classList.add('hasBackground');
movie.classList.add('hasBackground'); /** IF USING CLOUDFLARE TOO MANY REQUEST **/
/** IF USING CLOUDFLARE TOO MANY REQUEST **/ setTimeout(function () {
setTimeout(function () { $('[data-movie-id="' + movie_id + '"] > div')
$('[data-movie-id="' + movie_id + '"] > div') .css('opacity', 0)
.css('opacity', 0) .css('background-image', 'url("/cover/movie?movie_id=' + movie_id + '&width=' + 175 + '&height=' + 263 + '")')
.css('background-image', 'url("/cover/movie?movie_id=' + movie_id + '&width=' + 175 + '&height=' + 263 + '")') .animate({opacity: 1}, 500);
.animate({opacity: 1}, 500); }, 50 +( 50 * number));
}, 50 +( 50 * number)); number++;
number++;
} else if( ( position.top < 0 || position.top > (window.innerHeight || document.documentElement.clientHeight) ) && movie.classList.contains('hasBackground') ) {
$('[data-movie-id="' + movie_id + '"] > div').css('background-image', '')
.removeClass('hasBackground')
.animate({opacity: 0}, 500);
}
}); });
$('.PosterCardImg-imageContainer-1Ar4M[data-tvshow-id]').each(function (index, element) { $('.PosterCardImg-imageContainer-1Ar4M[data-tvshow-id]:not(.hasBackground)').each(function (index, element) {
let tvshow_id = $(element).data('tvshow-id'); let tvshow_id = $(element).data('tvshow-id');
let position = element.getBoundingClientRect();
let tvshow = document.querySelector('[data-tvshow-id="' + tvshow_id + '"] > div');
if( position.top > 0 && position.top <= (window.innerHeight || document.documentElement.clientHeight) && !tvshow.classList.contains('hasBackground') ) { this.classList.add('hasBackground');
tvshow.classList.add('hasBackground'); /** IF USING CLOUDFLARE TOO MANY REQUEST **/
/** IF USING CLOUDFLARE TOO MANY REQUEST **/ setTimeout(function () {
setTimeout(function () { $('[data-tvshow-id="' + tvshow_id + '"] > div')
$('[data-tvshow-id="' + tvshow_id + '"] > div') .css('opacity', 0)
.css('opacity', 0) .css('background-image', 'url("/cover/tvshow?tvshow_id=' + tvshow_id + '&width=' + 175 + '&height=' + 263 + '")')
.css('background-image', 'url("/cover/tvshow?tvshow_id=' + tvshow_id + '&width=' + 175 + '&height=' + 263 + '")') .animate({opacity: 1}, 500);
.animate({opacity: 1}, 500); }, 50 +( 50 * number));
}, 50 +( 50 * number)); number++;
number++;
} else if( ( position.top < 0 || position.top > (window.innerHeight || document.documentElement.clientHeight) ) && tvshow.classList.contains('hasBackground') ) {
$('[data-tvshow-id="' + tvshow_id + '"] > div').css('background-image', '')
.removeClass('hasBackground')
.animate({opacity: 0}, 500);
}
}); });
}); });

@ -337,24 +337,16 @@
$('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]:not(.hasBackground)').each(function (index, element) { $('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]:not(.hasBackground)').each(function (index, element) {
let movie_id = $(element).data('movie-id'); let movie_id = $(element).data('movie-id');
let position = element.getBoundingClientRect();
let movie = document.querySelector('[data-movie-id="' + movie_id + '"] > div');
//if( position.top > 0 && position.top <= (window.innerHeight || document.documentElement.clientHeight) && !movie.classList.contains('hasBackground') ) { this.classList.add('hasBackground');
this.classList.add('hasBackground'); // IF USING CLOUDFLARE TOO MANY REQUEST
// IF USING CLOUDFLARE TOO MANY REQUEST setTimeout(function () {
setTimeout(function () { $('[data-movie-id="' + movie_id + '"] > div')
$('[data-movie-id="' + movie_id + '"] > div') .css('opacity', 0)
.css('opacity', 0) .css('background-image', 'url("/cover/movie?movie_id=' + movie_id + '&width=' + 175 + '&height=' + 263 + '")')
.css('background-image', 'url("/cover/movie?movie_id=' + movie_id + '&width=' + 175 + '&height=' + 263 + '")') .animate({opacity: 1}, 500);
.animate({opacity: 1}, 500); }, 100 +( 50 * number));
}, 100 +( 50 * number)); number++;
number++;
/*} else if( ( position.top < 0 || position.top > (window.innerHeight || document.documentElement.clientHeight) ) && movie.classList.contains('hasBackground') ) {
$('[data-movie-id="' + movie_id + '"] > div').css('background-image', '')
.removeClass('hasBackground')
.animate({opacity: 0}, 500);
}*/
}); });
}); });

Loading…
Cancel
Save