Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile-php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM php:7-fpm

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
24 changes: 18 additions & 6 deletions application/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,21 @@
* - boolean caching enable or disable internal caching FALSE
* - boolean expose set the X-Powered-By header FALSE
*/
Kohana::init([
$_settings = [
'base_url' => '/',
]);
'errors' => FALSE,
];
// Load the Profiler class when profiling is enabled
// otherwise I get the following error:
/*
Fatal error: Uncaught Error: Class 'Profiler' not found in /app/system/classes/Kohana/Core.php:598 Stack trace: #0 /app/system/classes/Kohana/Core.php(427): Kohana_Core::find_file('classes', 'Kohana/Profiler') #1 [internal function]: Kohana_Core::auto_load('Kohana_Profiler') #2 /app/system/classes/Profiler.php(3): spl_autoload_call('Kohana_Profiler') #3 /app/system/classes/Kohana/Core.php(430): require('/app/system/cla...') #4 [internal function]: Kohana_Core::auto_load('Profiler') #5 /app/system/classes/Kohana/Request/Client/Internal.php(60): spl_autoload_call('Profiler') #6 /app/system/classes/Kohana/Request/Client.php(114): Kohana_Request_Client_Internal->execute_request(Object(Request), Object(Response)) #7 /app/system/classes/Kohana/Request.php(1000): Kohana_Request_Client->execute(Object(Request)) #8 /app/index.php(118): Kohana_Request->execute() #9 {main} thrown in /app/system/classes/Kohana/Core.php on line 598
*/
if (!isset($_settings['profile']) || !empty($_settings['profile']))
{
require SYSPATH.'classes/Kohana/Profiler'.EXT;
require SYSPATH.'classes/Profiler'.EXT;
}
Kohana::init($_settings);

/**
* Attach the file write to logging. Multiple writers are supported.
Expand All @@ -129,13 +141,13 @@
*/
Kohana::modules([
// 'encrypt' => MODPATH.'encrypt', // Encryption supprt
// 'auth' => MODPATH.'auth', // Basic authentication
'auth' => MODPATH.'auth', // Basic authentication
// 'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
// 'database' => MODPATH.'database', // Database access
'database' => MODPATH.'database', // Database access
// 'image' => MODPATH.'image', // Image manipulation
// 'minion' => MODPATH.'minion', // CLI Tasks
// 'orm' => MODPATH.'orm', // Object Relationship Mapping
'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'pagination' => MODPATH.'pagination', // Pagination
// 'unittest' => MODPATH.'unittest', // Unit testing
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
Expand All @@ -148,7 +160,7 @@
* If you have not defined a cookie salt in your Cookie class then
* uncomment the line below and define a preferrably long salt.
*/
// Cookie::$salt = NULL;
Cookie::$salt = '2139821639u2yhrd3912u';
/**
* Cookie HttpOnly directive
* If set to true, disallows cookies to be accessed from JavaScript
Expand Down
53 changes: 52 additions & 1 deletion application/classes/Controller/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,60 @@

class Controller_Welcome extends Controller {

public function action_login()
{
$status = Auth::instance()->login('newadmin' ,'somepass', true);
if ($status) {
$this->redirect('welcome/index');
} else {
$this->response->body('login failed!');
}
}

public function action_logout()
{
Auth::instance()->logout(TRUE);
$this->redirect('welcome/index');
}

public function action_index()
{
$this->response->body('hello, world!');
$user = null;
try {
$user = Auth::instance()->get_user();
} catch (Exception $e) {
echo $e."<br/>";
}
if (!$user) {
$this->response->body('hello, anon user!<br/><a href="/welcome/login">login</a><br/><a href="/welcome/register">register user</a>');
} else {
$this->response->body('hello, ' . $user->username . '.<br/><a href="/welcome/logout">logout</a>');
}
}

public function action_register()
{
$user = ORM::factory('User');
$user->where('username', '=', 'newadmin')->find();
if (!$user->loaded()) {
$user = ORM::factory('user');
$user->username = 'newadmin';
$user->password = 'somepass';
$user->email = 'foor@bar.org';
try{
$user->save();
$user->add('roles', ORM::factory('Role')->where('name', '=', 'login')->find());
$user->save();
$this->response->body('user created');
}
catch(ORM_Validation_Exception $e){
var_dump($e->errors());
die();
}
} else {
$this->response->body('user exists');

}
}

} // End Welcome
12 changes: 12 additions & 0 deletions application/config/auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

return array
(
'driver' => 'ORM',
'hash_method' => 'sha256',
'hash_key' => '123598123568612638',
'lifetime' => 1209600,
'session_type' => Session::$default, // native
'session_key' => 'auth_user',
'users' => []
);
53 changes: 53 additions & 0 deletions application/config/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

return array
(
'default' => array
(
'type' => 'MySQLi',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname
* string username
* string password
* boolean persistent
* string database
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'mysql',
'username' => 'root',
'password' => 'somepass',
'persistent' => FALSE,
'database' => 'koseven',
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
'alternate' => array(
'type' => 'pdo',
'connection' => array(
/**
* The following options are available for PDO:
*
* string dsn
* string username
* string password
* boolean persistent
* string identifier
*/
'dsn' => 'mysql:host=mysql;dbname=koseven',
'username' => 'root',
'password' => 'somepass',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
);
8 changes: 8 additions & 0 deletions application/config/url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [

'trusted_hosts' => [
'localhost:8080',
],
];
53 changes: 53 additions & 0 deletions db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
CREATE DATABASE IF NOT EXISTS `koseven` DEFAULT CHARACTER SET utf8 COLLATE utf8_polish_ci;
USE `koseven`;

CREATE TABLE IF NOT EXISTS `roles` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `roles` (`id`, `name`, `description`) VALUES(1, 'login', 'Login privileges, granted after account confirmation');
INSERT INTO `roles` (`id`, `name`, `description`) VALUES(2, 'admin', 'Administrative user, has access to everything.');

CREATE TABLE IF NOT EXISTS `roles_users` (
`user_id` int(10) UNSIGNED NOT NULL,
`role_id` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`user_id`,`role_id`),
KEY `fk_role_id` (`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`email` varchar(254) NOT NULL,
`username` varchar(32) NOT NULL DEFAULT '',
`password` varchar(64) NOT NULL,
`logins` int(10) UNSIGNED NOT NULL DEFAULT '0',
`last_login` int(10) UNSIGNED,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_username` (`username`),
UNIQUE KEY `uniq_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `user_tokens` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` int(11) UNSIGNED NOT NULL,
`user_agent` varchar(40) NOT NULL,
`token` varchar(40) NOT NULL,
`created` int(10) UNSIGNED NOT NULL,
`expires` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_token` (`token`),
KEY `fk_user_id` (`user_id`),
KEY `expires` (`expires`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `roles_users`
ADD CONSTRAINT `roles_users_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `roles_users_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE;

ALTER TABLE `user_tokens`
ADD CONSTRAINT `user_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '2'

services:
mysql:
image: mysql:5.6.45
ports:
- "3306:3306"
volumes:
- ./db.sql:/docker-entrypoint-initdb.d/dump.sql
environment:
- MYSQL_ROOT_PASSWORD=somepass
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- .:/app
- ./site.conf:/etc/nginx/conf.d/default.conf:ro
php:
image: custom-php
build:
context: .
dockerfile: Dockerfile-php
volumes:
- .:/app
121 changes: 121 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

/**
* The directory in which your application specific resources are located.
* The application directory must contain the bootstrap.php file.
*
* @link http://kohanaframework.org/guide/about.install#application
*/
$application = 'application';

/**
* The directory in which your modules are located.
*
* @link http://kohanaframework.org/guide/about.install#modules
*/
$modules = 'modules';

/**
* The directory in which the Kohana resources are located. The system
* directory must contain the classes/kohana.php file.
*
* @link http://kohanaframework.org/guide/about.install#system
*/
$system = 'system';

/**
* The default extension of resource files. If you change this, all resources
* must be renamed to use the new extension.
*
* @link http://kohanaframework.org/guide/about.install#ext
*/
define('EXT', '.php');

/**
* Set the PHP error reporting level. If you set this in php.ini, you remove this.
* @link http://www.php.net/manual/errorfunc.configuration#ini.error-reporting
*
* When developing your application, it is highly recommended to enable notices
* and warnings. Enable them by using: E_ALL
*
* In a production environment, it is safe to ignore notices. Disable them by
* using: E_ALL & ~E_NOTICE
*
* When using a legacy application, it is recommended to disable deprecated
* notices. Disable with: E_ALL & ~E_DEPRECATED
*/
error_reporting(E_ALL);

/**
* End of standard configuration! Changing any of the code below should only be
* attempted by those with a working knowledge of Kohana internals.
*
* @link http://kohanaframework.org/guide/using.configuration
*/

// Set the full path to the docroot
define('DOCROOT', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR);

// Make the application relative to the docroot, for symlink'd index.php
if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
$application = DOCROOT.$application;

// Make the modules relative to the docroot, for symlink'd index.php
if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
$modules = DOCROOT.$modules;

// Make the system relative to the docroot, for symlink'd index.php
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
$system = DOCROOT.$system;

// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);

// Clean up the configuration vars
unset($application, $modules, $system);

if (file_exists('install'.EXT))
{
// Load the installation check
return include 'install'.EXT;
}

/**
* Define the start time of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_TIME'))
{
define('KOHANA_START_TIME', microtime(TRUE));
}

/**
* Define the memory usage at the start of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_MEMORY'))
{
define('KOHANA_START_MEMORY', memory_get_usage());
}

// Bootstrap the application
require APPPATH.'bootstrap'.EXT;

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(['Minion_Exception', 'handler']);

Minion_Task::factory(Minion_CLI::options())->execute();
}
else
{
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
echo Request::factory(TRUE, [], FALSE)
->execute()
->send_headers(TRUE)
->body();
}
Loading