From cd1a0115c2a3651109b3b87b0932d7566fbc7448 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 17 Jan 2015 18:53:40 -0500 Subject: [PATCH] Minor cleanups --- assets/css/app.css | 9 ++++++++- controllers/common.php | 7 +++++-- controllers/console.php | 1 - controllers/user.php | 5 ++--- fever/index.php | 2 +- models/auto_update.php | 19 ++++++++++--------- models/config.php | 5 +++-- models/database.php | 13 ++++++++----- models/remember_me.php | 5 ++--- models/user.php | 8 +++++--- templates/login.php | 34 ++++++++++++++++++---------------- templates/new_db.php | 16 ++++++++++------ 12 files changed, 72 insertions(+), 52 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index ce003ee..59900b9 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -212,7 +212,7 @@ select { } .form-actions { - margin-top: 40px; + margin-top: 30px; } input.form-error, @@ -728,6 +728,13 @@ iframe { margin-bottom: 45px; } +#database-selector h4 { + margin: 0; + margin-bottom: 10px; + padding: 0; + font-weight: normal; +} + .bookmarklet { font-size: 0.9em; font-weight: bold; diff --git a/controllers/common.php b/controllers/common.php index d0e5bd2..053a2a2 100644 --- a/controllers/common.php +++ b/controllers/common.php @@ -23,7 +23,7 @@ Router\before(function($action) { // These actions are considered to be safe even for unauthenticated users $safe_actions = array('login', 'bookmark-feed', 'select-db', 'logout', 'notfound'); - if ( ! Model\User\is_loggedin() && ! in_array($action, $safe_actions)) { + if (! Model\User\is_loggedin() && ! in_array($action, $safe_actions)) { if (! Model\RememberMe\authenticate()) { Model\User\logout(); Response\redirect('?action=login'); @@ -35,7 +35,10 @@ Router\before(function($action) { // Load translations $language = Model\Config\get('language') ?: 'en_US'; - if ($language !== 'en_US') Translator\load($language); + + if ($language !== 'en_US') { + Translator\load($language); + } // Set timezone date_default_timezone_set(Model\Config\get('timezone') ?: 'UTC'); diff --git a/controllers/console.php b/controllers/console.php index 6881547..ea040c8 100644 --- a/controllers/console.php +++ b/controllers/console.php @@ -13,7 +13,6 @@ Router\get_action('flush-console', function() { Response\redirect('?action=console'); }); - // Display console Router\get_action('console', function() { diff --git a/controllers/user.php b/controllers/user.php index afdcdca..5d653cd 100644 --- a/controllers/user.php +++ b/controllers/user.php @@ -9,15 +9,14 @@ use PicoFarad\Template; // Logout and destroy session Router\get_action('logout', function() { - Model\RememberMe\destroy(); - Session\close(); + Model\User\logout(); Response\redirect('?action=login'); }); // Display form login Router\get_action('login', function() { - if (isset($_SESSION['user'])) { + if (Model\User\is_loggedin()) { Response\redirect('?action=unread'); } diff --git a/fever/index.php b/fever/index.php index f6e24e0..b43173c 100644 --- a/fever/index.php +++ b/fever/index.php @@ -30,8 +30,8 @@ function response(array $response) function auth() { if (! empty($_GET['database'])) { + // Return unauthorized if the requested database could not be found if (! Model\Database\select($_GET['database'])) { - // return unauthorized if the requested database could not be found return array( 'api_version' => 3, 'auth' => 0, diff --git a/models/auto_update.php b/models/auto_update.php index 565e637..7cd2314 100644 --- a/models/auto_update.php +++ b/models/auto_update.php @@ -7,6 +7,7 @@ use DirectoryIterator; use RecursiveIterator; use RecursiveIteratorIterator; use RecursiveDirectoryIterator; +use Model\Config; // Get all files of a given directory function get_files_list($directory) @@ -49,7 +50,7 @@ function is_excluded_path($path, array $exclude_list) // Synchronize 2 directories (copy/remove files) function synchronize($source_directory, $destination_directory) { - \Model\Config\debug('[SYNCHRONIZE] '.$source_directory.' to '.$destination_directory); + Config\debug('[SYNCHRONIZE] '.$source_directory.' to '.$destination_directory); $src_files = get_files_list($source_directory); $dst_files = get_files_list($destination_directory); @@ -62,7 +63,7 @@ function synchronize($source_directory, $destination_directory) if ($file !== '.htaccess') { $destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file; - \Model\Config\debug('[REMOVE] '.$destination_file); + Config\debug('[REMOVE] '.$destination_file); if (! @unlink($destination_file)) { return false; @@ -77,7 +78,7 @@ function synchronize($source_directory, $destination_directory) if (! is_dir($directory)) { - \Model\Config\debug('[MKDIR] '.$directory); + Config\debug('[MKDIR] '.$directory); if (! @mkdir($directory, 0755, true)) { return false; @@ -87,7 +88,7 @@ function synchronize($source_directory, $destination_directory) $source_file = $source_directory.DIRECTORY_SEPARATOR.$file; $destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file; - \Model\Config\debug('[COPY] '.$source_file.' to '.$destination_file); + Config\debug('[COPY] '.$source_file.' to '.$destination_file); if (! @copy($source_file, $destination_file)) { return false; @@ -102,7 +103,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR { $archive_file = $download_directory.DIRECTORY_SEPARATOR.'update.zip'; - \Model\Config\debug('[DOWNLOAD] '.$url); + Config\debug('[DOWNLOAD] '.$url); if (($data = @file_get_contents($url)) === false) { return false; @@ -112,7 +113,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR return false; } - \Model\Config\debug('[UNZIP] '.$archive_file); + Config\debug('[UNZIP] '.$archive_file); $zip = new ZipArchive; @@ -129,7 +130,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR // Remove all files for a given directory function cleanup_directory($directory) { - \Model\Config\debug('[CLEANUP] '.$directory); + Config\debug('[CLEANUP] '.$directory); $dir = new DirectoryIterator($directory); @@ -173,12 +174,12 @@ function find_archive_root($base_directory = AUTO_UPDATE_ARCHIVE_DIRECTORY) } if (empty($directory)) { - \Model\Config\debug('[FIND ARCHIVE] No directory found'); + Config\debug('[FIND ARCHIVE] No directory found'); return false; } $path = $base_directory.DIRECTORY_SEPARATOR.$directory; - \Model\Config\debug('[FIND ARCHIVE] '.$path); + Config\debug('[FIND ARCHIVE] '.$path); return $path; } diff --git a/models/config.php b/models/config.php index 03698c0..bfbe939 100644 --- a/models/config.php +++ b/models/config.php @@ -2,6 +2,7 @@ namespace Model\Config; +use Translator; use DirectoryIterator; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -309,7 +310,7 @@ function save(array $values) { // Update the password if needed if (! empty($values['password'])) { - $values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT); + $values['password'] = password_hash($values['password'], PASSWORD_BCRYPT); } else { unset($values['password']); } @@ -333,7 +334,7 @@ function save(array $values) function reload() { $_SESSION['config'] = get_all(); - \Translator\load(get('language')); + Translator\load(get('language')); } // Get the user agent of the connected user diff --git a/models/database.php b/models/database.php index e19e0f3..c345aeb 100644 --- a/models/database.php +++ b/models/database.php @@ -2,6 +2,9 @@ namespace Model\Database; +use Schema; +use DirectoryIterator; +use Model\Config; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -17,11 +20,11 @@ function create($filename, $username, $password) 'filename' => $filename, )); - if ($db->schema()->check(\Model\Config\DB_VERSION)) { + if ($db->schema()->check(Schema\VERSION)) { $db->table('config')->update(array( 'username' => $username, - 'password' => \password_hash($password, PASSWORD_BCRYPT) + 'password' => password_hash($password, PASSWORD_BCRYPT) )); return true; @@ -49,7 +52,7 @@ function select($filename = '') } $_SESSION['database'] = $filename; - $_SESSION['config'] = \Model\Config\get_all(); + $_SESSION['config'] = Config\get_all(); } } else { @@ -63,7 +66,7 @@ function select($filename = '') // Get database path function get_path() { - return DATA_DIRECTORY.DIRECTORY_SEPARATOR.\Model\Database\select(); + return DATA_DIRECTORY.DIRECTORY_SEPARATOR.select(); } // Get the list of available databases @@ -71,7 +74,7 @@ function get_all() { $listing = array(); - $dir = new \DirectoryIterator(DATA_DIRECTORY); + $dir = new DirectoryIterator(DATA_DIRECTORY); foreach ($dir as $fileinfo) { if ($fileinfo->getExtension() === 'sqlite') { diff --git a/models/remember_me.php b/models/remember_me.php index 2591778..5a86b02 100644 --- a/models/remember_me.php +++ b/models/remember_me.php @@ -123,9 +123,6 @@ function remove($session_id) */ function destroy() { - // delete the cookie without any conditions! - delete_cookie(); - $credentials = read_cookie(); if ($credentials !== false) { @@ -135,6 +132,8 @@ function destroy() ->eq('token', $credentials['token']) ->remove(); } + + delete_cookie(); } /** diff --git a/models/user.php b/models/user.php index 6b197bd..af25ef7 100644 --- a/models/user.php +++ b/models/user.php @@ -5,6 +5,7 @@ namespace Model\User; use SimpleValidator\Validator; use SimpleValidator\Validators; use PicoDb\Database; +use PicoFarad\Session; use Model\Config; use Model\RememberMe; use Model\Database as DatabaseModel; @@ -15,10 +16,11 @@ function is_loggedin() return ! empty($_SESSION['user']); } +// Destroy the session and the rememberMe cookie function logout() { - \Model\RememberMe\destroy(); - \PicoFarad\Session\close(); + RememberMe\destroy(); + Session\close(); } // Get a user by username @@ -47,7 +49,7 @@ function validate_login(array $values) $user = get($values['username']); - if ($user && \password_verify($values['password'], $user['password'])) { + if ($user && password_verify($values['password'], $user['password'])) { unset($user['password']); diff --git a/templates/login.php b/templates/login.php index 2d1480e..f129b0e 100644 --- a/templates/login.php +++ b/templates/login.php @@ -31,27 +31,29 @@
+ 1): ?> +
+

+ +
+ + +
- 1): ?> -
-

- -
- diff --git a/templates/new_db.php b/templates/new_db.php index 3a80fcd..0c899d0 100644 --- a/templates/new_db.php +++ b/templates/new_db.php @@ -1,11 +1,15 @@