1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-16 15:01:09 +03:00

Password change task

This commit is contained in:
Alexander Yakovlev 2014-01-30 12:40:49 +07:00
parent 53647fe2d2
commit dce39db44f
9 changed files with 61 additions and 1 deletions

3
.gitmodules vendored
View file

@ -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

View file

@ -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.

View file

@ -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
));
/**

View file

@ -53,4 +53,10 @@ class Controller_User extends Controller_Layout {
}
}
}
public function action_logout()
{
Auth::instance()->logout();
$this->redirect('/');
}
}

View file

@ -0,0 +1,38 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* This is a task to change admin's password.
* It can accept -password option.
* @category Helpers
* @author Oreolek
* @license AGPL
**/
class Task_Password extends Minion_Task
{
protected $_options = array(
'user' => '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.');
}
}

View file

@ -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",

View file

@ -34,4 +34,5 @@ return array(
'Delete letter' => 'Удалить письмо',
'View' => 'Просмотреть',
'Message subject' => 'Тема письма',
'The password was successfully changed.' => 'Пароль был успешно изменён.'
);

View file

@ -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();
}

1
modules/config-writer Submodule

@ -0,0 +1 @@
Subproject commit 86791e97760a402c920a133f25dc1134f85aa371