From dce39db44f6f487d7f83f69378421d2d67596947 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Thu, 30 Jan 2014 12:40:49 +0700 Subject: [PATCH] Password change task --- .gitmodules | 3 ++ README.md | 8 ++++++ application/bootstrap.php | 1 + application/classes/Controller/User.php | 6 ++++ application/classes/Task/Password.php | 38 +++++++++++++++++++++++++ application/config/auth.php.example | 3 +- application/i18n/ru.php | 1 + index.php | 1 + modules/config-writer | 1 + 9 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 application/classes/Task/Password.php create mode 160000 modules/config-writer diff --git a/.gitmodules b/.gitmodules index f0f7296..a933823 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "modules/minion"] path = modules/minion url = git@github.com:kohana/minion.git +[submodule "modules/config-writer"] + path = modules/config-writer + url = https://github.com/ppx17/kohana-config-file-writer.git diff --git a/README.md b/README.md index 282215a..9fa4ffc 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,11 @@ License is [AGPL 3.0](http://www.tldrlegal.com/l/AGPL3) Kohana 3.3 (I recommend using 3.4 unstable git branch, it has MySQLi driver) MySQL or MariaDB PHP 5 with enabled OpenSSL + +## Notes +### Config Writer + +* Writer still needs to be enabled: `Kohana::$config->attach(new Config_File_Writer);` +* All comments in config file are lost on write. +* Feature is highly unreliable. You can lose the file. You can have two users writing config simultaneously. +* Do not use in web environment. diff --git a/application/bootstrap.php b/application/bootstrap.php index 1de4a0e..600be5d 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -114,6 +114,7 @@ Kohana::modules(array( 'kostache' => MODPATH.'kostache', // Logic-less Mustache views 'email' => MODPATH.'email', // Electronic mail class 'minion' => MODPATH.'minion', // CLI framework + 'config-writer' => MODPATH.'config-writer', // Write to PHP configs )); /** diff --git a/application/classes/Controller/User.php b/application/classes/Controller/User.php index 59ae4b1..b1c4337 100644 --- a/application/classes/Controller/User.php +++ b/application/classes/Controller/User.php @@ -53,4 +53,10 @@ class Controller_User extends Controller_Layout { } } } + + public function action_logout() + { + Auth::instance()->logout(); + $this->redirect('/'); + } } diff --git a/application/classes/Task/Password.php b/application/classes/Task/Password.php new file mode 100644 index 0000000..610ca23 --- /dev/null +++ b/application/classes/Task/Password.php @@ -0,0 +1,38 @@ + 'admin', + 'password' => NULL, + ); + + public function build_validation(Validation $validation) + { + return parent::build_validation($validation) + ->rule('password', 'not_empty'); // Require this param + } + + /** + * This is an admin password task + * + * @return null + */ + protected function _execute(array $params) + { + $writer = new Config_File_Writer; + Kohana::$config->attach($writer); + $config = Kohana::$config->load('auth'); + $hashing_key = $config->get('hash_key'); + $hash = hash_hmac('sha256', $params['password'], $hashing_key); + $config->set('users', array($params['user'] => $hash)); + Kohana::$config->detach($writer); + echo __('The password was successfully changed.'); + } +} diff --git a/application/config/auth.php.example b/application/config/auth.php.example index 7f073e1..e129c4f 100644 --- a/application/config/auth.php.example +++ b/application/config/auth.php.example @@ -3,9 +3,10 @@ return array( 'driver' => 'File', + // you can set the user and his password using Password minion task. + // there can be only one user 'users' => array( 'admin' => 'password-hash' - // generate the hash using hash_hmac('sha256', $str, "hashing_key") ), 'hash_method' => 'sha256', 'hash_key' => "hashing_key", diff --git a/application/i18n/ru.php b/application/i18n/ru.php index 1150a66..0671b5f 100644 --- a/application/i18n/ru.php +++ b/application/i18n/ru.php @@ -34,4 +34,5 @@ return array( 'Delete letter' => 'Удалить письмо', 'View' => 'Просмотреть', 'Message subject' => 'Тема письма', + 'The password was successfully changed.' => 'Пароль был успешно изменён.' ); diff --git a/index.php b/index.php index cf9ee40..95a8735 100644 --- a/index.php +++ b/index.php @@ -106,6 +106,7 @@ if (PHP_SAPI == 'cli') // Try and load minion { class_exists('Minion_Task') OR die('Please enable the Minion module for CLI support.'); set_exception_handler(array('Minion_Exception', 'handler')); + Debugtoolbar::disable(); Minion_Task::factory(Minion_CLI::options())->execute(); } diff --git a/modules/config-writer b/modules/config-writer new file mode 160000 index 0000000..86791e9 --- /dev/null +++ b/modules/config-writer @@ -0,0 +1 @@ +Subproject commit 86791e97760a402c920a133f25dc1134f85aa371