|
@@ -4,11 +4,19 @@ require_once(dirname(__FILE__) . '/classes/Controller.php');
|
|
|
require_once(dirname(__FILE__) . '/classes/SecretRandomizer.class.php');
|
|
require_once(dirname(__FILE__) . '/classes/SecretRandomizer.class.php');
|
|
|
require_once(__DIR__.'/classes/Secret.Entity.php');
|
|
require_once(__DIR__.'/classes/Secret.Entity.php');
|
|
|
|
|
|
|
|
|
|
+class UserError extends Exception { }
|
|
|
|
|
+class RandomError extends Exception { }
|
|
|
|
|
+
|
|
|
class CreateController extends Controller
|
|
class CreateController extends Controller
|
|
|
{
|
|
{
|
|
|
private $campain = null;
|
|
private $campain = null;
|
|
|
private $users = array();
|
|
private $users = array();
|
|
|
private $constraints = array();
|
|
private $constraints = array();
|
|
|
|
|
+ private $adminPanel = false;
|
|
|
|
|
+ private $publink = null;
|
|
|
|
|
+
|
|
|
|
|
+ private $randomError = false;
|
|
|
|
|
+ private $userError = false;
|
|
|
|
|
|
|
|
public function __construct($request)
|
|
public function __construct($request)
|
|
|
{
|
|
{
|
|
@@ -19,15 +27,44 @@ class CreateController extends Controller
|
|
|
$this->render("404");
|
|
$this->render("404");
|
|
|
die;
|
|
die;
|
|
|
}
|
|
}
|
|
|
|
|
+ $this->publink = $_SERVER['REQUEST_SCHEME']
|
|
|
|
|
+ .'://'
|
|
|
|
|
+ .$_SERVER['HTTP_HOST']
|
|
|
|
|
+ .$GLOBALS['baseUri']
|
|
|
|
|
+ .$this->getCampain()->getId();
|
|
|
|
|
+ $this->adminPanel = hash::isLong($request);
|
|
|
$this->users = $this->campain->getUsers();
|
|
$this->users = $this->campain->getUsers();
|
|
|
$this->constraints = $this->campain->getConstraints();
|
|
$this->constraints = $this->campain->getConstraints();
|
|
|
if (!empty($_POST) && !$this->campain->isFinished())
|
|
if (!empty($_POST) && !$this->campain->isFinished())
|
|
|
- $this->managePost();
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->managePost();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (RandomError $e)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->randomError = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (UserError $e)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->userError = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!$this->randomError && !$this->userError)
|
|
|
|
|
+ {
|
|
|
|
|
+ header("HTTP/1.0 302 Found");
|
|
|
|
|
+ header("Location: ".$_SERVER['HTTP_REQUEST']);
|
|
|
|
|
+ die();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
$this->render('hash');
|
|
$this->render('hash');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getCampain() { return $this->campain; }
|
|
public function getCampain() { return $this->campain; }
|
|
|
public function getUsers() { return $this->users; }
|
|
public function getUsers() { return $this->users; }
|
|
|
|
|
+ public function isAdmin() { return $this->adminPanel; }
|
|
|
|
|
+ public function getPublink() { return $this->publink; }
|
|
|
|
|
+ public function hasError() { return $this->randomError; }
|
|
|
|
|
+ public function hasUsererror() { return $this->userError; }
|
|
|
|
|
|
|
|
public function hasConstraint($userA, $userB)
|
|
public function hasConstraint($userA, $userB)
|
|
|
{
|
|
{
|
|
@@ -38,15 +75,24 @@ class CreateController extends Controller
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @return Boolean false on random fail
|
|
|
|
|
+ **/
|
|
|
public function managePost()
|
|
public function managePost()
|
|
|
{
|
|
{
|
|
|
if (!empty($_POST['launch']))
|
|
if (!empty($_POST['launch']))
|
|
|
{
|
|
{
|
|
|
|
|
+ if (!$this->adminPanel)
|
|
|
|
|
+ return true;
|
|
|
|
|
+ if (count($this->users) < 2)
|
|
|
|
|
+ throw new RandomError();
|
|
|
$s = new SecretRandomizer($this->campain, $this->users, $this->constraints);
|
|
$s = new SecretRandomizer($this->campain, $this->users, $this->constraints);
|
|
|
$result = $s->getResult();
|
|
$result = $s->getResult();
|
|
|
|
|
+ if ($result->getResult() == null)
|
|
|
|
|
+ throw new RandomError();
|
|
|
$result->sendMails();
|
|
$result->sendMails();
|
|
|
$this->campain->setResult($result->getResult());
|
|
$this->campain->setResult($result->getResult());
|
|
|
- return;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
$this->campain->removeConstraints();
|
|
$this->campain->removeConstraints();
|
|
|
$groups = array();
|
|
$groups = array();
|
|
@@ -62,9 +108,11 @@ class CreateController extends Controller
|
|
|
$this->constraints = $this->campain->getConstraints();
|
|
$this->constraints = $this->campain->getConstraints();
|
|
|
if (!empty($_POST['cemail']))
|
|
if (!empty($_POST['cemail']))
|
|
|
{
|
|
{
|
|
|
- $this->campain->addUser($_POST['cemail'], $_POST['cname']);
|
|
|
|
|
|
|
+ if (!($this->campain->addUser($_POST['cemail'], $_POST['cname'])))
|
|
|
|
|
+ throw new UserError();
|
|
|
$this->users = $this->campain->getUsers();
|
|
$this->users = $this->campain->getUsers();
|
|
|
}
|
|
}
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|