Created
January 4, 2017 12:46
-
-
Save Tjoosten/6f21ed643cb27aefee5a0f093f664884 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ActivismBe\Controllers; | |
use Silex\Application; | |
use Silex\Api\ControllerProviderInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
use ActivismBe\Validators\LoginValidator; | |
class AuthController implements ControllerProviderInterface | |
{ | |
/** | |
* Variable used to put the app instance in. | |
* | |
* @var mixed | |
*/ | |
private $app; | |
/** | |
* IndexController instance. | |
* | |
* @return void. | |
*/ | |
public function __construct() | |
{ | |
$this->app = $app; | |
} | |
/** | |
* Factory routing instance. | |
* | |
* @param Application $app | |
* @return mixed | |
*/ | |
public function connect(Application $app) | |
{ | |
$factory = $app['controllers_factory']; | |
$factory->get('/login','ActivismBe\Controllers\AuthController::loginView')->bind('login.view'); | |
$factory->get('/register', 'ActivismBe\Controllers\AuthController::registerView')->bind('register.view'); | |
$factory->post('/login', 'ActivismBe\Controllers\AuthController::authenticate')->bind('login.authenticate'); | |
$factory->post('/register', 'ActivismBe\Controllers\AuthController::registerMethod')->bind('register.method'); | |
return $factory; | |
} | |
/** | |
* | |
*/ | |
public function loginView() | |
{ | |
return $app['twig']->render('auth/login.html.twig'); | |
} | |
/** | |
* @param Request $input | |
*/ | |
public function authenticate(Request $input, LoginValidator $validation) | |
{ | |
if ($validation->validate($input->all())) { | |
return 'no errors'; | |
} else { | |
return 'We got some problems here'; | |
} | |
} | |
/** | |
* | |
*/ | |
public function registerView() | |
{ | |
} | |
/** | |
* | |
*/ | |
public function registerMethod() | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the app instance | |
$app = new Silex\Application(); | |
// Application general config | |
$app['debug'] = true; | |
// Load the config for the service providers. | |
$dbConfig = new ActivismBe\Config\Database(); | |
$viewConfig = new ActivismBe\Config\View(); | |
// Register service providers. | |
$app->register(new Silex\Provider\ValidatorServiceProvider()); | |
$app->register(new \JG\Silex\Provider\CapsuleServiceProvider(), $dbConfig->bootConfig()); | |
$app->register(new Silex\Provider\TwigServiceProvider(), $viewConfig->bootConfig()); | |
// Routing | |
// $app->mount('/', new ActivismBe\Controllers\IndexController()); | |
$app->mount('/auth', new ActivismBe\Controllers\AuthController($app)); | |
// $app->mount('/users', new ActivismBe\Controllers\UsersController); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment