Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #44 from PHPSP/develop
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
rogeriopradoj committed Oct 29, 2013
2 parents 624169f + 600138f commit 70c28f7
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
# Project Files

config/config.ini
phpunit.xml
public/uploads/*
tests/_reports/*
20 changes: 20 additions & 0 deletions Boxfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
web1:
name: liga-solidaria-storage
shared_writable_dirs:
- public/uploads
document_root: public
php_version: 5.4.14
php_default_locale: "pt_BR"
php_date_timezone: "America/Sao_Paulo"
php_error_reporting: -1
php_display_errors: "1"
php_extensions:
- zip
after_build:
- "if [ ! -f composer.phar ]; then curl -s http://getcomposer.org/installer | php; fi"
- "php composer.phar install --no-dev --optimize-autoloader"
- "cp config/config.ini.dist config/config.ini"

db1:
name: liga-solidaria-storage
type: mysql
Binary file added Layout Liga 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 76 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/config.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ default_charset = 'UTF-8'

view_path = '../templates/'

; Login credentials

user = 'admin'
pass = '123456'

; Database parameteres

db_driver = "mysql"
Expand Down
19 changes: 19 additions & 0 deletions data/db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Database: Liga Solidaria Storage

CREATE DATABASE `liga`;

CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`password` varchar(40) NOT NULL,
`email` varchar(100) NOT NULL,
`group_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `group` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSE=utf8;
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<log type="tap" target="tests/_reports/logfile.tap"/>
<log type="junit" target="tests/_reports/logfile.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
</phpunit>
14 changes: 11 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

use Respect\Rest\Router;

$auth = new LigaSolidariaStorage\Routine\Auth;
$authenticated = function() use($auth) {return $auth();};
$r = new Router;
$r->isAutoDispatched = false;

$r->any('/', 'LigaSolidariaStorage\Storage\Controller\HomeController');
$r->any('/login', 'LigaSolidariaStorage\Storage\Controller\Login');
$r->get('/logout', 'LigaSolidariaStorage\Storage\Controller\Logout');

$r->get('/list/*', 'LigaSolidariaStorage\Storage\Controller\ArtefatoListController' );
$r->any('/', 'LigaSolidariaStorage\Storage\Controller\HomeController')
->by($authenticated);

$r->any('/upload', 'LigaSolidariaStorage\Storage\Controller\ArtefatoUploadController');
$r->get('/list/*', 'LigaSolidariaStorage\Storage\Controller\ArtefatoListController' )
->by($authenticated);

$r->any('/upload', 'LigaSolidariaStorage\Storage\Controller\ArtefatoUploadController')
->by($authenticated);

$r->any('/contact', 'LigaSolidariaStorage\Storage\Controller\ContactController', array($c->mailer));

Expand Down
23 changes: 23 additions & 0 deletions src/LigaSolidariaStorage/Routine/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace LigaSolidariaStorage\Routine;

use \PHP_SESSION_ACTIVE;

class Auth
{
public function __construct()
{
session_start();
}

public function __invoke()
{
if (isset($_SESSION['email']))
return true;

header('HTTP/1.1 403 Permission denied');
header('Location: /login');
return false;
}
}
35 changes: 35 additions & 0 deletions src/LigaSolidariaStorage/Storage/Controller/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace LigaSolidariaStorage\Storage\Controller;

use Respect\Rest\Routable;
use \InvalidArgumentException as Argument;

class Login implements Routable
{
public function get()
{
return array('_view' => 'login.html.twig');
}

public function post()
{
try {
$vars = array('_view'=>'index.html.twig');
$email = filter_input(INPUT_POST, 'email');
$pass = filter_input(INPUT_POST, 'password');

if (empty($email) || empty($pass)) {
throw new Argument('Email ou senha inválidos');
}

$_SESSION['email'] = $_POST['email'];

header('Location: /');

} catch(Argument $e) {
$vars['message'] = $e->getMessage();
return $vars;
}
}
}
14 changes: 14 additions & 0 deletions src/LigaSolidariaStorage/Storage/Controller/Logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LigaSolidariaStorage\Storage\Controller;

use Respect\Rest\Routable;

class Logout implements Routable
{
public function get()
{
session_destroy();
header('Location: /');
}
}
3 changes: 3 additions & 0 deletions templates/elements/navbar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<li>
<a href="/contact/">Contato</a>
</li>
<li>
<a href="/logout">Logout</a>
</li>
</ul>
</div><!--/.nav -->
</div>
Expand Down
Loading

0 comments on commit 70c28f7

Please sign in to comment.