sporz

PHP implementation of the board game "sporz"
git clone https://0x1A4.1337.cx/code2/sporz.git
Log | Files | Refs

commit e3623fb8196bd391b0abcb301e7e71062c6167dc
parent 89121f665feed5b37a672aaba1229fa30d9e8f46
Author: gitus <git@shroomrider.com>
Date:   Tue Nov 15 20:44:28 +0100

Merge pull request #4 from pips-/master

Keep hacking
Diffstat:
.gitignore | 7+++++++
app/Views/game/detail.tpl.php | 4++--
app/Views/game/form.tpl.php | 2+-
app/Views/layout.tpl.php | 12++++++++++++
app/Views/session/login-form.tpl.php | 8++++++++
composer.lock | 8++++----
db/migrations/20161112174748_add_field_default_values.php | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/migrations/20161112175819_rename_game_turn_field.php | 36++++++++++++++++++++++++++++++++++++
public/index.php | 28++++++++++++++++++++++++++++
9 files changed, 159 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -1,3 +1,10 @@ .DS_Store vendor config.php + +# vim files +*.swp +*~ + +# db files +*.db diff --git a/app/Views/game/detail.tpl.php b/app/Views/game/detail.tpl.php @@ -1,5 +1,5 @@ -<h2><?= $this->get('game')->name; ?> -<a href="<?= $this->get('edit-link'); ?>">Edit</a></h2> +<h2><?= $this->get('game')->name; ?></h2> +<a href="<?= $this->get('edit-link'); ?>">Edit</a> <div> Created at: <?= $this->get('game')->created; ?><br> Last modified: <?= $this->get('game')->updated; ?> diff --git a/app/Views/game/form.tpl.php b/app/Views/game/form.tpl.php @@ -1,7 +1,7 @@ <form method="post" action="<?= $this->get('form-action'); ?>"> <h2><?= $this->get('game')->is_new() ? 'Create' : 'Edit'; ?></h2> <div class="form-group"> - <label for="name">Name</label> + <label for="name">Name:</label> <input type="text" name="name" id="name" value="<?= $this->get('game')->name; ?>"> </div> <button type="submit" class="btn btn-default">Submit</button> diff --git a/app/Views/layout.tpl.php b/app/Views/layout.tpl.php @@ -7,11 +7,23 @@ </head> <body> <h1>Sporz</h1> + <?php + foreach ($this->flushFlash() as $flash) { + ?> + <div class="alert alert-<?= $flash['class']; ?>"> + <?= $flash['message']; ?> + </div> + <?php + } + ?> <ul class="nav nav-tabs"> <li role="presentation"> <a href="/">Home</a> </li> <li role="presentation"> + <a href="/login">Sign in</a> + </li> + <li role="presentation"> <a href="/game/add">Create Game</a> </li> </ul> diff --git a/app/Views/session/login-form.tpl.php b/app/Views/session/login-form.tpl.php @@ -0,0 +1,8 @@ +<form method="post" action="/login"> + <h2>Sign in</h2> + <div class="form-group"> + <label for="email">Email:</label> + <input type="email" name="email" id="email" placeholder="email@example.net"> + </div> + <button type="submit" class="btn btn-default">Login</button> +</form> diff --git a/composer.lock b/composer.lock @@ -13,12 +13,12 @@ "source": { "type": "git", "url": "https://github.com/pragma-framework/core.git", - "reference": "925d2de92cdb50b133d66941ec8aaddac1fa54d0" + "reference": "a6181d643a6ae04bd1e17ce9c880b8457851aa7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pragma-framework/core/zipball/925d2de92cdb50b133d66941ec8aaddac1fa54d0", - "reference": "925d2de92cdb50b133d66941ec8aaddac1fa54d0", + "url": "https://api.github.com/repos/pragma-framework/core/zipball/a6181d643a6ae04bd1e17ce9c880b8457851aa7f", + "reference": "a6181d643a6ae04bd1e17ce9c880b8457851aa7f", "shasum": "" }, "require": { @@ -50,7 +50,7 @@ "router", "view" ], - "time": "2016-11-10 17:26:37" + "time": "2016-11-11 09:20:20" }, { "name": "psr/log", diff --git a/db/migrations/20161112174748_add_field_default_values.php b/db/migrations/20161112174748_add_field_default_values.php @@ -0,0 +1,61 @@ +<?php + +use Phinx\Migration\AbstractMigration; + +class AddFieldDefaultValues extends AbstractMigration +{ + /** + * Change Method. + * + * Write your reversible migrations using this method. + * + * More information on writing migrations is available here: + * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class + * + * The following commands can be used in this method and Phinx will + * automatically reverse them when rolling back: + * + * createTable + * renameTable + * addColumn + * renameColumn + * addIndex + * addForeignKey + * + * Remember to call "create()" or "update()" and NOT "save()" when working + * with the Table class. + */ + public function up() + { + $game = $this->table('game'); + + $game->changeColumn('phase', 'integer', array('default' => 0, 'null' => false)); + $game->changeColumn('turn_number', 'integer', array('default' => 0, 'null' => false)); + $game->changeColumn('started', 'integer', array('default' => 0, 'null' => false)); + + $game->save(); + + $player = $this->table('player'); + + $player->changeColumn('alive', 'integer', array('default' => 1, 'null' => false)); + + $player->save(); + } + + public function down() + { + $game = $this->table('game'); + + $game->changeColumn('phase', 'integer', array('null' => true, 'default' => null)); + $game->changeColumn('turn_number', 'integer', array('null' => true, 'default' => null)); + $game->changeColumn('started', 'integer', array('null' => true, 'default' => null)); + + $game->save(); + + $player = $this->table('player'); + + $player->changeColumn('alive', 'integer', array('null' => true, 'default' => null)); + + $player->save(); + } +} diff --git a/db/migrations/20161112175819_rename_game_turn_field.php b/db/migrations/20161112175819_rename_game_turn_field.php @@ -0,0 +1,36 @@ +<?php + +use Phinx\Migration\AbstractMigration; + +class RenameGameTurnField extends AbstractMigration +{ + /** + * Change Method. + * + * Write your reversible migrations using this method. + * + * More information on writing migrations is available here: + * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class + * + * The following commands can be used in this method and Phinx will + * automatically reverse them when rolling back: + * + * createTable + * renameTable + * addColumn + * renameColumn + * addIndex + * addForeignKey + * + * Remember to call "create()" or "update()" and NOT "save()" when working + * with the Table class. + */ + public function change() + { + $game = $this->table('game'); + + $game->renameColumn('turn_number', 'turn'); + + $game->update(); + } +} diff --git a/public/index.php b/public/index.php @@ -10,10 +10,18 @@ use App\Models\Game; use App\Helpers\Redirect; +session_start(); + $view = View::getInstance(); $view->set_tpl_path(APP_PATH.'/Views/'); $view->setLayout('layout.tpl.php'); +if (!isset($_SESSION['view']['flash-messages'])) { + $_SESSION['view']['flash-messages'] = array(); +} + +$view->initFlashStructure($_SESSION['view']['flash-messages']); + $app = Router::getInstance(); //define your routes here @@ -24,6 +32,26 @@ $app->get('/', function () use ($app) { View::getInstance()->render('index.tpl.php'); }); +$app->get('/login', function () use ($app) { + $view = View::getInstance(); + + $view->assign('form-action', $app->url_for('login-post')); + + $view->render('session/login-form.tpl.php'); +})->alias('login-form'); + +$app->post('/login', function() use ($app) { + $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); + + if ($email == null) { + View::getInstance()->flash('Invalid email address', 'danger'); + Redirect::to($app->url_for('login-form')); + } + + // TODO: Find use by email (or create?) & send authentication link to address + //$player = player::forge()->where('started', '=', 0)->get_objects(); +})->alias('login-post'); + $app->group('/game', function () use ($app) { $app->post('', function () use ($app) { $game = new Game();