Registration sketch

This commit is contained in:
Marcin Kurczewski
2013-10-05 12:55:03 +02:00
parent eebd297a24
commit 3a77bb7c59
18 changed files with 558 additions and 0 deletions

View File

@ -0,0 +1,49 @@
<?php
abstract class AbstractController
{
protected function attachUser()
{
$this->context->loggedIn = false;
if (isset($_SESSION['user-id']))
{
$this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]);
if (!empty($this->context->user))
{
$this->context->loggedIn = true;
}
}
if (empty($this->context->user))
{
#todo: construct anonymous user
$this->context->user = null;
}
}
public function workWrapper($workCallback)
{
session_start();
$this->context->layoutName = isset($_GET['json'])
? 'layout-json'
: 'layout-normal';
$this->context->transport = new StdClass;
$this->context->transport->success = null;
$this->attachUser();
try
{
$workCallback();
}
catch (SimpleException $e)
{
$this->context->transport->errorMessage = rtrim($e->getMessage(), '.') . '.';
$this->context->transport->exception = $e;
$this->context->transport->success = false;
}
catch (Exception $e)
{
$this->context->exception = $e;
$this->context->viewName = 'error-exception';
}
}
}