Merge pull request #8 from EaterOfCode/master

Update release to new version with new fancy features
master
Corné Oppelaar 9 years ago committed by GitHub
commit 6498a21b56

@ -1,15 +0,0 @@
#!/usr/bin/env php
<?php
$basedir = realpath(__DIR__ . '/../');
# All calls are now relative to the root directory
chdir($basedir);
include $basedir . '/vendor/autoload.php';
$core = new \Eater\Glim\Core();
$core->startTimer(["total"]);
$core->boot($basedir);
echo $core->get('user')->createInvite();
$core->endTimer(["total"]);

@ -0,0 +1,11 @@
#!/usr/bin/env bash
cd "$(realpath "$(dirname "$0")/..")";
composer install;
mkdir storage;
touch storage/db.sqlite;
./vendor/bin/propel sql:build
./vendor/bin/propel sql:insert;
echo "Done setting up web environment"

@ -17,7 +17,8 @@
"hassankhan/config": "0.10.0",
"monolog/monolog": "1.18.1",
"aura/session": "2.0.1",
"guzzlehttp/guzzle": "^6.2"
"guzzlehttp/guzzle": "^6.2",
"tedivm/stash": "^0.14.1"
},
"autoload": {
"psr-4": {

110
composer.lock generated

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "95b6dc2302dd6086dbc2b7248a1f5768",
"content-hash": "61847eefe53610226629206b81b6f8b5",
"hash": "7f7a5098d89b4841741255592bee1890",
"content-hash": "045408fd26a025036d65a2e00bb8a369",
"packages": [
{
"name": "aura/session",
@ -558,6 +558,52 @@
],
"time": "2015-06-27 11:58:48"
},
{
"name": "psr/cache",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/9e66031f41fbbdda45ee11e93c45d480ccba3eb3",
"reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"time": "2015-12-11 02:52:07"
},
{
"name": "psr/http-message",
"version": "1.0",
@ -1167,6 +1213,66 @@
"homepage": "https://symfony.com",
"time": "2016-03-04 07:54:35"
},
{
"name": "tedivm/stash",
"version": "v0.14.1",
"source": {
"type": "git",
"url": "https://github.com/tedious/Stash.git",
"reference": "bcb739b08b22571e35589ebe5403af9b89a33394"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tedious/Stash/zipball/bcb739b08b22571e35589ebe5403af9b89a33394",
"reference": "bcb739b08b22571e35589ebe5403af9b89a33394",
"shasum": ""
},
"require": {
"php": "^5.4|^7.0",
"psr/cache": "~1.0"
},
"provide": {
"psr/cache-implementation": "1.0.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "^1.9",
"phpunit/phpunit": "4.8.*",
"satooshi/php-coveralls": "1.0.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Stash\\": "src/Stash/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Robert Hafner",
"email": "tedivm@tedivm.com"
},
{
"name": "Josh Hall-Bachner",
"email": "charlequin@gmail.com"
}
],
"description": "The place to keep your cache.",
"homepage": "http://github.com/tedious/Stash",
"keywords": [
"apc",
"cache",
"caching",
"memcached",
"psr-6",
"psr6",
"redis",
"sessions"
],
"time": "2016-02-10 22:23:16"
},
{
"name": "twig/twig",
"version": "v1.24.0",

@ -3,9 +3,10 @@ core:
level: debug
debug: true
container:
name: "Glim"
author: "Corné Oppelaar <hello@eaterofco.de>"
name: "Zer.ooo"
author: "EaterOfCode"
sessionName: '0sess'
github-repo: 'EaterOfCode/zer.ooo'
services:
slim: Eater\Glim\Service\Slim
user: Eater\Glim\Service\User
@ -13,4 +14,6 @@ core:
twig: Eater\Glim\Service\Twig
twig-vars: Eater\Glim\Service\TwigVars
ca: Eater\Glim\Service\CA
server: Eater\Glim\Service\Server
server: Eater\Glim\Service\Server
stash: Eater\Glim\Service\Stash
github: Eater\Glim\Service\GitHub

@ -32,6 +32,10 @@ routes:
post: Panel\Servers\Edit\Action
/{fingerprint}/config: Panel\Servers\Config
/{fingerprint}/config/{cert}: Panel\Servers\Config
/invites:
get: Panel\Invites
/create:
post: Panel\Invites\Create
/server:
/register:
post: Server\Register

@ -9,6 +9,8 @@
<column name="username" type="varchar" size="64" />
<column name="password" type="varchar" size="64" />
<column name="superuser" type="boolean" default="false" />
<column name="max_invites" type="integer" default="0" />
<column name="used_invites" type="integer" default="0" />
<unique>
<unique-column name="username" />
@ -46,6 +48,11 @@
<table name="Invite">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="invite" type="varchar" size="64" />
<column name="owner" type="integer" />
<foreign-key foreignTable="User">
<reference local="owner" foreign="id" />
</foreign-key>
</table>
<table name="Server">

@ -151,18 +151,27 @@ body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 20vh; }
align-items: center; }
.footer-page a {
color: black; }
.footer-page h1 {
.footer-page-title, .footer-page h1, .footer-page h2 {
font-family: 'Inconsolata';
font-size: 1.5em;
color: #E08E79;
letter-spacing: 3pt;
font-weight: lighter; }
font-weight: lighter;
text-transform: lowercase; }
.footer-page h1 {
font-size: 1.5em; }
.footer-page h2 {
font-size: 1.2em;
font-weight: bold; }
.footer-page h2 a {
margin-right: -3pt; }
.login-page {
background: linear-gradient(#070a15, #252b46);

@ -1,6 +1,6 @@
{
"version": 3,
"mappings": "AAAQ,0BAAe;AACf,yBAAc;AAGd,uBAAY;AAGZ,6IAAqI;AACrI,6GAAqG;ACR7G,SAAS;EACP,eAAe,EAAE,IAAI;EACrB,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,QAAQ,EAAE,MA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column;
justify-content: center;
align-items: center;
height: 20vh;
}
.footer-page a {
color: black
}
.footer-page h1 {
.footer-page-title {
font-family: 'Inconsolata';
font-size: 1.5em;
color: #E08E79;
letter-spacing: 3pt;
font-weight: lighter;
text-transform: lowercase;
}
.footer-page h1 {
@extend .footer-page-title;
font-size: 1.5em;
}
.footer-page h2 {
@extend .footer-page-title;
font-size: 1.2em;
font-weight: bold;
}
.footer-page h2 a {
margin-right: -3pt;
}
// login page

@ -1,6 +1,6 @@
<?php
if (is_file(__DIR__ . $_SERVER["REQUEST_URI"]) && preg_match('/\.(?:png|jpg|jpeg|gif|css|js|eot|svg|ttf|woff|woff2)$/', $_SERVER["REQUEST_URI"])) {
if (is_file(__DIR__ . $_SERVER["REQUEST_URI"]) && preg_match('/\.(?:png|jpg|jpeg|gif|css|js|eot|svg|ttf|woff|woff2|map)$/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is.
}

@ -362,5 +362,4 @@ class Core implements ContainerInterface
{
$this->getSlim()->run();
}
}

@ -2,10 +2,31 @@
namespace Eater\Glim\Handler;
use Eater\Glim\Service\GitHub;
class Home extends Session
{
function handle()
{
return $this->render("home.html.twig");
/** @var GitHub $github */
$github = $this->get('github');
/** @var string $repo */
$repo = $this->get('github-repo');
/** @var string $author */
$author = $this->get('author');
$info = $github->getRepoInfo();
if ($info !== false) {
$author = $info['owner']['login'];
}
return $this->render("home.html.twig", [
'author' => $author,
'contributors' => $github->getContributors(),
'githubRepo' => $repo
]);
}
}

@ -25,16 +25,23 @@ class Action extends Main
$session = $this->get('session');
$segment = $session->getSegment('main');
$user = $user->login($username, $password);
$loggedUser = $user->login($username, $password);
if ($user === null) {
if ($loggedUser === null) {
$segment->setFlash("error", "Login failed, username or password are incorrect");
return $this->redirect('/login');
}
$segment->set('user', $user);
$segment->set('userId', $loggedUser->getId());
$afterLogin = $segment->get('afterLogin');
$segment->set('afterLogin', null);
if ($afterLogin !== null) {
return $this->redirect($afterLogin);
}
return $this->redirect('/panel');
}
}

@ -17,7 +17,7 @@ class Logout extends Main
$session = $this->get('session');
$segment = $session->getSegment('main');
$segment->set('user', null);
$segment->set('userId', null);
return $this->redirect('/login');
}

@ -0,0 +1,29 @@
<?php
namespace Eater\Glim\Handler\Panel;
use Aura\Session\Segment;
use Eater\Glim\Handler\Session;
class Invites extends Session
{
protected $shouldHaveUser = true;
public function handle()
{
$user = $this->getUser();
$invites = $user->getInvites();
/** @var Segment $segment */
$segment = $this->get('session')->getSegment('main');
return $this->render('panel/invites.html.twig', [
'invites' => $invites,
'error' => $segment->getFlash('error'),
'used_invites' => $user->getUsedInvites(),
'max_invites' => $user->getMaxInvites()
]);
}
}

@ -0,0 +1,29 @@
<?php
namespace Eater\Glim\Handler\Panel\Invites;
use Eater\Glim\Handler\Session;
use Eater\Glim\Service\User;
use Aura\Session\Segment;
class Create extends Session
{
public function handle()
{
/** @var User $user */
$user = $this->get('user');
$userModel = $this->getUser();
if ($userModel->getUsedInvites() < $userModel->getMaxInvites() || $userModel->getMaxInvites() === -1) {
$user->createInvite($userModel);
} else {
/** @var Segment $segment */
$segment = $this->get('session')->getSegment('main');
$segment->setFlash('error', 'You dont have any invites anymore');
}
return $this->redirect('/panel/invites');
}
}

@ -9,7 +9,7 @@
namespace Eater\Glim\Handler;
use Aura\Session\Segment;
use Eater\Glim\Model\Base\UserQuery;
use Eater\Glim\Model\UserQuery;
use Eater\Glim\Model\User;
use Eater\Glim\Service\TwigVars;
@ -18,7 +18,7 @@ class Session extends Main
/**
* @var bool
*/
protected $shouldHaveUser = false;
protected $shouldHaveUser = true;
/**
* @var bool
@ -60,12 +60,16 @@ class Session extends Main
/** @var Segment $segment */
$segment = $session->getSegment('main');
/** @var User $user */
$user = $segment->get('user');
$userId = $segment->get('userId');
$user = UserQuery::create()->findOneById($userId);
$twigVar->def('user', $user);
$this->setUser($user);
if ($user === null && ($this->shouldHaveUser || $this->shouldHaveSuperuser)) {
$segment->set('afterLogin', $this->getRequest()->getUri());
return $this->redirect('/login');
} elseif ($this->shouldHaveSuperuser && !$user->getSuperuser()) {
return $this->redirect('/panel');

@ -5,6 +5,8 @@ namespace Eater\Glim\Model\Base;
use \Exception;
use \PDO;
use Eater\Glim\Model\InviteQuery as ChildInviteQuery;
use Eater\Glim\Model\User as ChildUser;
use Eater\Glim\Model\UserQuery as ChildUserQuery;
use Eater\Glim\Model\Map\InviteTableMap;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
@ -71,6 +73,17 @@ abstract class Invite implements ActiveRecordInterface
*/
protected $invite;
/**
* The value for the owner field.
* @var int
*/
protected $owner;
/**
* @var ChildUser
*/
protected $aUser;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@ -316,6 +329,16 @@ abstract class Invite implements ActiveRecordInterface
return $this->invite;
}
/**
* Get the [owner] column value.
*
* @return int
*/
public function getOwner()
{
return $this->owner;
}
/**
* Set the value of [id] column.
*
@ -356,6 +379,30 @@ abstract class Invite implements ActiveRecordInterface
return $this;
} // setInvite()
/**
* Set the value of [owner] column.
*
* @param int $v new value
* @return $this|\Eater\Glim\Model\Invite The current object (for fluent API support)
*/
public function setOwner($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->owner !== $v) {
$this->owner = $v;
$this->modifiedColumns[InviteTableMap::COL_OWNER] = true;
}
if ($this->aUser !== null && $this->aUser->getId() !== $v) {
$this->aUser = null;
}
return $this;
} // setOwner()
/**
* Indicates whether the columns in this object are only set to default values.
*
@ -397,6 +444,9 @@ abstract class Invite implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : InviteTableMap::translateFieldName('Invite', TableMap::TYPE_PHPNAME, $indexType)];
$this->invite = (null !== $col) ? (string) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : InviteTableMap::translateFieldName('Owner', TableMap::TYPE_PHPNAME, $indexType)];
$this->owner = (null !== $col) ? (int) $col : null;
$this->resetModified();
$this->setNew(false);
@ -405,7 +455,7 @@ abstract class Invite implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 2; // 2 = InviteTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 3; // 3 = InviteTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException(sprintf('Error populating %s object', '\\Eater\\Glim\\Model\\Invite'), 0, $e);
@ -427,6 +477,9 @@ abstract class Invite implements ActiveRecordInterface
*/
public function ensureConsistency()
{
if ($this->aUser !== null && $this->owner !== $this->aUser->getId()) {
$this->aUser = null;
}
} // ensureConsistency
/**
@ -466,6 +519,7 @@ abstract class Invite implements ActiveRecordInterface
if ($deep) { // also de-associate any related objects?
$this->aUser = null;
} // if (deep)
}
@ -565,6 +619,18 @@ abstract class Invite implements ActiveRecordInterface
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their corresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aUser !== null) {
if ($this->aUser->isModified() || $this->aUser->isNew()) {
$affectedRows += $this->aUser->save($con);
}
$this->setUser($this->aUser);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
@ -608,6 +674,9 @@ abstract class Invite implements ActiveRecordInterface
if ($this->isColumnModified(InviteTableMap::COL_INVITE)) {
$modifiedColumns[':p' . $index++] = 'invite';
}
if ($this->isColumnModified(InviteTableMap::COL_OWNER)) {
$modifiedColumns[':p' . $index++] = 'owner';
}
$sql = sprintf(
'INSERT INTO Invite (%s) VALUES (%s)',
@ -625,6 +694,9 @@ abstract class Invite implements ActiveRecordInterface
case 'invite':
$stmt->bindValue($identifier, $this->invite, PDO::PARAM_STR);
break;
case 'owner':
$stmt->bindValue($identifier, $this->owner, PDO::PARAM_INT);
break;
}
}
$stmt->execute();
@ -693,6 +765,9 @@ abstract class Invite implements ActiveRecordInterface
case 1:
return $this->getInvite();
break;
case 2:
return $this->getOwner();
break;
default:
return null;
break;
@ -710,10 +785,11 @@ abstract class Invite implements ActiveRecordInterface
* Defaults to TableMap::TYPE_PHPNAME.
* @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
* @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
* @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
*
* @return array an associative array containing the field names (as keys) and field values
*/
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
{
if (isset($alreadyDumpedObjects['Invite'][$this->hashCode()])) {
@ -724,12 +800,30 @@ abstract class Invite implements ActiveRecordInterface
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getInvite(),
$keys[2] => $this->getOwner(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
$result[$key] = $virtualColumn;
}
if ($includeForeignObjects) {
if (null !== $this->aUser) {
switch ($keyType) {
case TableMap::TYPE_CAMELNAME:
$key = 'user';
break;
case TableMap::TYPE_FIELDNAME:
$key = 'User';
break;
default:
$key = 'User';
}
$result[$key] = $this->aUser->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
}
}
return $result;
}
@ -769,6 +863,9 @@ abstract class Invite implements ActiveRecordInterface
case 1:
$this->setInvite($value);
break;
case 2:
$this->setOwner($value);
break;
} // switch()
return $this;
@ -801,6 +898,9 @@ abstract class Invite implements ActiveRecordInterface
if (array_key_exists($keys[1], $arr)) {
$this->setInvite($arr[$keys[1]]);
}
if (array_key_exists($keys[2], $arr)) {
$this->setOwner($arr[$keys[2]]);
}
}
/**
@ -848,6 +948,9 @@ abstract class Invite implements ActiveRecordInterface
if ($this->isColumnModified(InviteTableMap::COL_INVITE)) {
$criteria->add(InviteTableMap::COL_INVITE, $this->invite);
}
if ($this->isColumnModified(InviteTableMap::COL_OWNER)) {
$criteria->add(InviteTableMap::COL_OWNER, $this->owner);
}
return $criteria;
}
@ -935,6 +1038,7 @@ abstract class Invite implements ActiveRecordInterface
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
$copyObj->setInvite($this->getInvite());
$copyObj->setOwner($this->getOwner());
if ($makeNew) {
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
@ -963,6 +1067,57 @@ abstract class Invite implements ActiveRecordInterface
return $copyObj;
}
/**
* Declares an association between this object and a ChildUser object.
*
* @param ChildUser $v
* @return $this|\Eater\Glim\Model\Invite The current object (for fluent API support)
* @throws PropelException
*/
public function setUser(ChildUser $v = null)
{
if ($v === null) {
$this->setOwner(NULL);
} else {
$this->setOwner($v->getId());
}
$this->aUser = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the ChildUser object, it will not be re-added.
if ($v !== null) {
$v->addInvite($this);
}
return $this;
}
/**
* Get the associated ChildUser object
*
* @param ConnectionInterface $con Optional Connection object.
* @return ChildUser The associated ChildUser object.
* @throws PropelException
*/
public function getUser(ConnectionInterface $con = null)
{
if ($this->aUser === null && ($this->owner !== null)) {
$this->aUser = ChildUserQuery::create()->findPk($this->owner, $con);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aUser->addInvites($this);
*/
}
return $this->aUser;
}
/**
* Clears the current object, sets all attributes to their default values and removes
* outgoing references as well as back-references (from other objects to this one. Results probably in a database
@ -970,8 +1125,12 @@ abstract class Invite implements ActiveRecordInterface
*/
public function clear()
{
if (null !== $this->aUser) {
$this->aUser->removeInvite($this);
}
$this->id = null;
$this->invite = null;
$this->owner = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
$this->resetModified();
@ -992,6 +1151,7 @@ abstract class Invite implements ActiveRecordInterface
if ($deep) {
} // if ($deep)
$this->aUser = null;
}
/**

@ -10,6 +10,7 @@ use Eater\Glim\Model\Map\InviteTableMap;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
@ -21,29 +22,40 @@ use Propel\Runtime\Exception\PropelException;
*
* @method ChildInviteQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildInviteQuery orderByInvite($order = Criteria::ASC) Order by the invite column
* @method ChildInviteQuery orderByOwner($order = Criteria::ASC) Order by the owner column
*
* @method ChildInviteQuery groupById() Group by the id column
* @method ChildInviteQuery groupByInvite() Group by the invite column
* @method ChildInviteQuery groupByOwner() Group by the owner column
*
* @method ChildInviteQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildInviteQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildInviteQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildInviteQuery leftJoinUser($relationAlias = null) Adds a LEFT JOIN clause to the query using the User relation
* @method ChildInviteQuery rightJoinUser($relationAlias = null) Adds a RIGHT JOIN clause to the query using the User relation
* @method ChildInviteQuery innerJoinUser($relationAlias = null) Adds a INNER JOIN clause to the query using the User relation
*
* @method \Eater\Glim\Model\UserQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
*
* @method ChildInvite findOne(ConnectionInterface $con = null) Return the first ChildInvite matching the query
* @method ChildInvite findOneOrCreate(ConnectionInterface $con = null) Return the first ChildInvite matching the query, or a new ChildInvite object populated from the query conditions when no match is found
*
* @method ChildInvite findOneById(int $id) Return the first ChildInvite filtered by the id column
* @method ChildInvite findOneByInvite(string $invite) Return the first ChildInvite filtered by the invite column *
* @method ChildInvite findOneByInvite(string $invite) Return the first ChildInvite filtered by the invite column
* @method ChildInvite findOneByOwner(int $owner) Return the first ChildInvite filtered by the owner column *
* @method ChildInvite requirePk($key, ConnectionInterface $con = null) Return the ChildInvite by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildInvite requireOne(ConnectionInterface $con = null) Return the first ChildInvite matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
*
* @method ChildInvite requireOneById(int $id) Return the first ChildInvite filtered by the id column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildInvite requireOneByInvite(string $invite) Return the first ChildInvite filtered by the invite column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildInvite requireOneByOwner(int $owner) Return the first ChildInvite filtered by the owner column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
*
* @method ChildInvite[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildInvite objects based on current ModelCriteria
* @method ChildInvite[]|ObjectCollection findById(int $id) Return ChildInvite objects filtered by the id column
* @method ChildInvite[]|ObjectCollection findByInvite(string $invite) Return ChildInvite objects filtered by the invite column
* @method ChildInvite[]|ObjectCollection findByOwner(int $owner) Return ChildInvite objects filtered by the owner column
* @method ChildInvite[]|\Propel\Runtime\Util\PropelModelPager paginate($page = 1, $maxPerPage = 10, ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
*
*/
@ -136,7 +148,7 @@ abstract class InviteQuery extends ModelCriteria
*/
protected function findPkSimple($key, ConnectionInterface $con)
{
$sql = 'SELECT id, invite FROM Invite WHERE id = :p0';
$sql = 'SELECT id, invite, owner FROM Invite WHERE id = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@ -296,6 +308,126 @@ abstract class InviteQuery extends ModelCriteria
return $this->addUsingAlias(InviteTableMap::COL_INVITE, $invite, $comparison);
}
/**
* Filter the query on the owner column
*
* Example usage:
* <code>
* $query->filterByOwner(1234); // WHERE owner = 1234
* $query->filterByOwner(array(12, 34)); // WHERE owner IN (12, 34)
* $query->filterByOwner(array('min' => 12)); // WHERE owner > 12
* </code>
*
* @see filterByUser()
*
* @param mixed $owner The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return $this|ChildInviteQuery The current query, for fluid interface
*/
public function filterByOwner($owner = null, $comparison = null)
{
if (is_array($owner)) {
$useMinMax = false;
if (isset($owner['min'])) {
$this->addUsingAlias(InviteTableMap::COL_OWNER, $owner['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($owner['max'])) {
$this->addUsingAlias(InviteTableMap::COL_OWNER, $owner['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(InviteTableMap::COL_OWNER, $owner, $comparison);
}
/**
* Filter the query by a related \Eater\Glim\Model\User object
*
* @param \Eater\Glim\Model\User|ObjectCollection $user The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @throws \Propel\Runtime\Exception\PropelException
*
* @return ChildInviteQuery The current query, for fluid interface
*/
public function filterByUser($user, $comparison = null)
{
if ($user instanceof \Eater\Glim\Model\User) {
return $this
->addUsingAlias(InviteTableMap::COL_OWNER, $user->getId(), $comparison);
} elseif ($user instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(InviteTableMap::COL_OWNER, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByUser() only accepts arguments of type \Eater\Glim\Model\User or Collection');
}
}
/**
* Adds a JOIN clause to the query using the User relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return $this|ChildInviteQuery The current query, for fluid interface
*/
public function joinUser($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('User');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'User');
}
return $this;
}
/**
* Use the User relation User object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Eater\Glim\Model\UserQuery A secondary query class using the current class as primary query
*/
public function useUserQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinUser($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'User', '\Eater\Glim\Model\UserQuery');
}
/**
* Exclude object from result
*

@ -6,6 +6,8 @@ use \Exception;
use \PDO;
use Eater\Glim\Model\Certificate as ChildCertificate;
use Eater\Glim\Model\CertificateQuery as ChildCertificateQuery;
use Eater\Glim\Model\Invite as ChildInvite;
use Eater\Glim\Model\InviteQuery as ChildInviteQuery;
use Eater\Glim\Model\User as ChildUser;
use Eater\Glim\Model\UserQuery as ChildUserQuery;
use Eater\Glim\Model\Map\UserTableMap;
@ -95,12 +97,32 @@ abstract class User implements ActiveRecordInterface
*/
protected $superuser;
/**
* The value for the max_invites field.
* Note: this column has a database default value of: 0
* @var int
*/
protected $max_invites;
/**
* The value for the used_invites field.
* Note: this column has a database default value of: 0
* @var int
*/
protected $used_invites;
/**
* @var ObjectCollection|ChildCertificate[] Collection to store aggregation of ChildCertificate objects.
*/
protected $collCertificates;
protected $collCertificatesPartial;
/**
* @var ObjectCollection|ChildInvite[] Collection to store aggregation of ChildInvite objects.
*/
protected $collInvites;
protected $collInvitesPartial;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@ -115,6 +137,12 @@ abstract class User implements ActiveRecordInterface
*/
protected $certificatesScheduledForDeletion = null;
/**
* An array of objects scheduled for deletion.
* @var ObjectCollection|ChildInvite[]
*/
protected $invitesScheduledForDeletion = null;
/**
* Applies default values to this object.
* This method should be called from the object's constructor (or
@ -125,6 +153,8 @@ abstract class User implements ActiveRecordInterface
{
$this->max_keys = 5;
$this->superuser = false;
$this->max_invites = 0;
$this->used_invites = 0;
}
/**
@ -406,6 +436,26 @@ abstract class User implements ActiveRecordInterface
return $this->getSuperuser();
}
/**
* Get the [max_invites] column value.
*
* @return int
*/
public function getMaxInvites()
{
return $this->max_invites;
}
/**
* Get the [used_invites] column value.
*
* @return int
*/
public function getUsedInvites()
{
return $this->used_invites;
}
/**
* Set the value of [id] column.
*
@ -514,6 +564,46 @@ abstract class User implements ActiveRecordInterface
return $this;
} // setSuperuser()
/**
* Set the value of [max_invites] column.
*
* @param int $v new value
* @return $this|\Eater\Glim\Model\User The current object (for fluent API support)
*/
public function setMaxInvites($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->max_invites !== $v) {
$this->max_invites = $v;
$this->modifiedColumns[UserTableMap::COL_MAX_INVITES] = true;
}
return $this;
} // setMaxInvites()
/**
* Set the value of [used_invites] column.
*
* @param int $v new value
* @return $this|\Eater\Glim\Model\User The current object (for fluent API support)
*/
public function setUsedInvites($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->used_invites !== $v) {
$this->used_invites = $v;
$this->modifiedColumns[UserTableMap::COL_USED_INVITES] = true;
}
return $this;
} // setUsedInvites()
/**
* Indicates whether the columns in this object are only set to default values.
*
@ -532,6 +622,14 @@ abstract class User implements ActiveRecordInterface
return false;
}
if ($this->max_invites !== 0) {
return false;
}
if ($this->used_invites !== 0) {
return false;
}
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@ -572,6 +670,12 @@ abstract class User implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : UserTableMap::translateFieldName('Superuser', TableMap::TYPE_PHPNAME, $indexType)];
$this->superuser = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : UserTableMap::translateFieldName('MaxInvites', TableMap::TYPE_PHPNAME, $indexType)];
$this->max_invites = (null !== $col) ? (int) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : UserTableMap::translateFieldName('UsedInvites', TableMap::TYPE_PHPNAME, $indexType)];
$this->used_invites = (null !== $col) ? (int) $col : null;
$this->resetModified();
$this->setNew(false);
@ -580,7 +684,7 @@ abstract class User implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 5; // 5 = UserTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 7; // 7 = UserTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException(sprintf('Error populating %s object', '\\Eater\\Glim\\Model\\User'), 0, $e);
@ -643,6 +747,8 @@ abstract class User implements ActiveRecordInterface
$this->collCertificates = null;
$this->collInvites = null;
} // if (deep)
}
@ -771,6 +877,24 @@ abstract class User implements ActiveRecordInterface
}
}
if ($this->invitesScheduledForDeletion !== null) {
if (!$this->invitesScheduledForDeletion->isEmpty()) {
foreach ($this->invitesScheduledForDeletion as $invite) {
// need to save related object because we set the relation to null
$invite->save($con);
}
$this->invitesScheduledForDeletion = null;
}
}
if ($this->collInvites !== null) {
foreach ($this->collInvites as $referrerFK) {
if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
@ -812,6 +936,12 @@ abstract class User implements ActiveRecordInterface
if ($this->isColumnModified(UserTableMap::COL_SUPERUSER)) {
$modifiedColumns[':p' . $index++] = 'superuser';
}
if ($this->isColumnModified(UserTableMap::COL_MAX_INVITES)) {
$modifiedColumns[':p' . $index++] = 'max_invites';
}
if ($this->isColumnModified(UserTableMap::COL_USED_INVITES)) {
$modifiedColumns[':p' . $index++] = 'used_invites';
}
$sql = sprintf(
'INSERT INTO User (%s) VALUES (%s)',
@ -838,6 +968,12 @@ abstract class User implements ActiveRecordInterface
case 'superuser':
$stmt->bindValue($identifier, $this->superuser, PDO::PARAM_BOOL);
break;
case 'max_invites':
$stmt->bindValue($identifier, $this->max_invites, PDO::PARAM_INT);
break;
case 'used_invites':
$stmt->bindValue($identifier, $this->used_invites, PDO::PARAM_INT);
break;
}
}
$stmt->execute();
@ -915,6 +1051,12 @@ abstract class User implements ActiveRecordInterface
case 4:
return $this->getSuperuser();
break;
case 5:
return $this->getMaxInvites();
break;
case 6:
return $this->getUsedInvites();
break;
default:
return null;
break;
@ -950,6 +1092,8 @@ abstract class User implements ActiveRecordInterface
$keys[2] => $this->getUsername(),
$keys[3] => $this->getPassword(),
$keys[4] => $this->getSuperuser(),
$keys[5] => $this->getMaxInvites(),
$keys[6] => $this->getUsedInvites(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@ -972,6 +1116,21 @@ abstract class User implements ActiveRecordInterface
$result[$key] = $this->collCertificates->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
if (null !== $this->collInvites) {
switch ($keyType) {
case TableMap::TYPE_CAMELNAME:
$key = 'invites';
break;
case TableMap::TYPE_FIELDNAME:
$key = 'Invites';
break;
default:
$key = 'Invites';
}
$result[$key] = $this->collInvites->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
}
}
return $result;
@ -1021,6 +1180,12 @@ abstract class User implements ActiveRecordInterface
case 4:
$this->setSuperuser($value);
break;
case 5:
$this->setMaxInvites($value);
break;
case 6:
$this->setUsedInvites($value);
break;
} // switch()
return $this;
@ -1062,6 +1227,12 @@ abstract class User implements ActiveRecordInterface
if (array_key_exists($keys[4], $arr)) {
$this->setSuperuser($arr[$keys[4]]);
}
if (array_key_exists($keys[5], $arr)) {
$this->setMaxInvites($arr[$keys[5]]);
}
if (array_key_exists($keys[6], $arr)) {
$this->setUsedInvites($arr[$keys[6]]);
}
}
/**
@ -1118,6 +1289,12 @@ abstract class User implements ActiveRecordInterface
if ($this->isColumnModified(UserTableMap::COL_SUPERUSER)) {
$criteria->add(UserTableMap::COL_SUPERUSER, $this->superuser);
}
if ($this->isColumnModified(UserTableMap::COL_MAX_INVITES)) {
$criteria->add(UserTableMap::COL_MAX_INVITES, $this->max_invites);
}
if ($this->isColumnModified(UserTableMap::COL_USED_INVITES)) {
$criteria->add(UserTableMap::COL_USED_INVITES, $this->used_invites);
}
return $criteria;
}
@ -1208,6 +1385,8 @@ abstract class User implements ActiveRecordInterface
$copyObj->setUsername($this->getUsername());
$copyObj->setPassword($this->getPassword());
$copyObj->setSuperuser($this->getSuperuser());
$copyObj->setMaxInvites($this->getMaxInvites());
$copyObj->setUsedInvites($this->getUsedInvites());
if ($deepCopy) {
// important: temporarily setNew(false) because this affects the behavior of
@ -1220,6 +1399,12 @@ abstract class User implements ActiveRecordInterface
}
}
foreach ($this->getInvites() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addInvite($relObj->copy($deepCopy));
}
}
} // if ($deepCopy)
if ($makeNew) {
@ -1264,6 +1449,9 @@ abstract class User implements ActiveRecordInterface
if ('Certificate' == $relationName) {
return $this->initCertificates();
}
if ('Invite' == $relationName) {
return $this->initInvites();
}
}
/**
@ -1484,6 +1672,224 @@ abstract class User implements ActiveRecordInterface
return $this;
}
/**
* Clears out the collInvites collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addInvites()
*/
public function clearInvites()
{
$this->collInvites = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Reset is the collInvites collection loaded partially.
*/
public function resetPartialInvites($v = true)
{
$this->collInvitesPartial = $v;
}
/**
* Initializes the collInvites collection.
*
* By default this just sets the collInvites collection to an empty array (like clearcollInvites());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @param boolean $overrideExisting If set to true, the method call initializes
* the collection even if it is not empty
*
* @return void
*/
public function initInvites($overrideExisting = true)
{
if (null !== $this->collInvites && !$overrideExisting) {
return;
}
$this->collInvites = new ObjectCollection();
$this->collInvites->setModel('\Eater\Glim\Model\Invite');
}
/**
* Gets an array of ChildInvite objects which contain a foreign key that references this object.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this ChildUser is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria optional Criteria object to narrow the query
* @param ConnectionInterface $con optional connection object
* @return ObjectCollection|ChildInvite[] List of ChildInvite objects
* @throws PropelException
*/
public function getInvites(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collInvitesPartial && !$this->isNew();
if (null === $this->collInvites || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collInvites) {
// return empty collection
$this->initInvites();
} else {
$collInvites = ChildInviteQuery::create(null, $criteria)
->filterByUser($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collInvitesPartial && count($collInvites)) {
$this->initInvites(false);
foreach ($collInvites as $obj) {
if (false == $this->collInvites->contains($obj)) {
$this->collInvites->append($obj);
}
}
$this->collInvitesPartial = true;
}
return $collInvites;
}
if ($partial && $this->collInvites) {
foreach ($this->collInvites as $obj) {
if ($obj->isNew()) {
$collInvites[] = $obj;
}
}
}
$this->collInvites = $collInvites;
$this->collInvitesPartial = false;
}
}
return $this->collInvites;
}
/**
* Sets a collection of ChildInvite objects related by a one-to-many relationship
* to the current object.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
*
* @param Collection $invites A Propel collection.
* @param ConnectionInterface $con Optional connection object
* @return $this|ChildUser The current object (for fluent API support)
*/
public function setInvites(Collection $invites, ConnectionInterface $con = null)
{
/** @var ChildInvite[] $invitesToDelete */
$invitesToDelete = $this->getInvites(new Criteria(), $con)->diff($invites);
$this->invitesScheduledForDeletion = $invitesToDelete;
foreach ($invitesToDelete as $inviteRemoved) {
$inviteRemoved->setUser(null);
}
$this->collInvites = null;
foreach ($invites as $invite) {
$this->addInvite($invite);
}
$this->collInvites = $invites;
$this->collInvitesPartial = false;
return $this;
}
/**
* Returns the number of related Invite objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param ConnectionInterface $con
* @return int Count of related Invite objects.
* @throws PropelException
*/
public function countInvites(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collInvitesPartial && !$this->isNew();
if (null === $this->collInvites || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collInvites) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getInvites());
}
$query = ChildInviteQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByUser($this)
->count($con);
}
return count($this->collInvites);
}
/**
* Method called to associate a ChildInvite object to this object
* through the ChildInvite foreign key attribute.
*
* @param ChildInvite $l ChildInvite
* @return $this|\Eater\Glim\Model\User The current object (for fluent API support)
*/
public function addInvite(ChildInvite $l)
{
if ($this->collInvites === null) {
$this->initInvites();
$this->collInvitesPartial = true;
}
if (!$this->collInvites->contains($l)) {
$this->doAddInvite($l);
}
return $this;
}
/**
* @param ChildInvite $invite The ChildInvite object to add.
*/
protected function doAddInvite(ChildInvite $invite)
{
$this->collInvites[]= $invite;
$invite->setUser($this);
}
/**
* @param ChildInvite $invite The ChildInvite object to remove.
* @return $this|ChildUser The current object (for fluent API support)
*/
public function removeInvite(ChildInvite $invite)
{
if ($this->getInvites()->contains($invite)) {
$pos = $this->collInvites->search($invite);
$this->collInvites->remove($pos);
if (null === $this->invitesScheduledForDeletion) {
$this->invitesScheduledForDeletion = clone $this->collInvites;
$this->invitesScheduledForDeletion->clear();
}
$this->invitesScheduledForDeletion[]= $invite;
$invite->setUser(null);
}
return $this;
}
/**
* Clears the current object, sets all attributes to their default values and removes
* outgoing references as well as back-references (from other objects to this one. Results probably in a database
@ -1496,6 +1902,8 @@ abstract class User implements ActiveRecordInterface
$this->username = null;
$this->password = null;
$this->superuser = null;
$this->max_invites = null;
$this->used_invites = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
$this->applyDefaultValues();
@ -1520,9 +1928,15 @@ abstract class User implements ActiveRecordInterface
$o->clearAllReferences($deep);
}
}
if ($this->collInvites) {
foreach ($this->collInvites as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
$this->collCertificates = null;
$this->collInvites = null;
}
/**

@ -25,12 +25,16 @@ use Propel\Runtime\Exception\PropelException;
* @method ChildUserQuery orderByUsername($order = Criteria::ASC) Order by the username column
* @method ChildUserQuery orderByPassword($order = Criteria::ASC) Order by the password column
* @method ChildUserQuery orderBySuperuser($order = Criteria::ASC) Order by the superuser column
* @method ChildUserQuery orderByMaxInvites($order = Criteria::ASC) Order by the max_invites column
* @method ChildUserQuery orderByUsedInvites($order = Criteria::ASC) Order by the used_invites column
*
* @method ChildUserQuery groupById() Group by the id column
* @method ChildUserQuery groupByMaxKeys() Group by the max_keys column
* @method ChildUserQuery groupByUsername() Group by the username column
* @method ChildUserQuery groupByPassword() Group by the password column
* @method ChildUserQuery groupBySuperuser() Group by the superuser column
* @method ChildUserQuery groupByMaxInvites() Group by the max_invites column
* @method ChildUserQuery groupByUsedInvites() Group by the used_invites column
*
* @method ChildUserQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildUserQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
@ -40,7 +44,11 @@ use Propel\Runtime\Exception\PropelException;
* @method ChildUserQuery rightJoinCertificate($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Certificate relation
* @method ChildUserQuery innerJoinCertificate($relationAlias = null) Adds a INNER JOIN clause to the query using the Certificate relation
*
* @method \Eater\Glim\Model\CertificateQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
* @method ChildUserQuery leftJoinInvite($relationAlias = null) Adds a LEFT JOIN clause to the query using the Invite relation
* @method ChildUserQuery rightJoinInvite($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Invite relation
* @method ChildUserQuery innerJoinInvite($relationAlias = null) Adds a INNER JOIN clause to the query using the Invite relation
*
* @method \Eater\Glim\Model\CertificateQuery|\Eater\Glim\Model\InviteQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
*
* @method ChildUser findOne(ConnectionInterface $con = null) Return the first ChildUser matching the query
* @method ChildUser findOneOrCreate(ConnectionInterface $con = null) Return the first ChildUser matching the query, or a new ChildUser object populated from the query conditions when no match is found
@ -49,7 +57,9 @@ use Propel\Runtime\Exception\PropelException;
* @method ChildUser findOneByMaxKeys(int $max_keys) Return the first ChildUser filtered by the max_keys column
* @method ChildUser findOneByUsername(string $username) Return the first ChildUser filtered by the username column
* @method ChildUser findOneByPassword(string $password) Return the first ChildUser filtered by the password column
* @method ChildUser findOneBySuperuser(boolean $superuser) Return the first ChildUser filtered by the superuser column *
* @method ChildUser findOneBySuperuser(boolean $superuser) Return the first ChildUser filtered by the superuser column
* @method ChildUser findOneByMaxInvites(int $max_invites) Return the first ChildUser filtered by the max_invites column
* @method ChildUser findOneByUsedInvites(int $used_invites) Return the first ChildUser filtered by the used_invites column *
* @method ChildUser requirePk($key, ConnectionInterface $con = null) Return the ChildUser by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildUser requireOne(ConnectionInterface $con = null) Return the first ChildUser matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
@ -59,6 +69,8 @@ use Propel\Runtime\Exception\PropelException;
* @method ChildUser requireOneByUsername(string $username) Return the first ChildUser filtered by the username column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildUser requireOneByPassword(string $password) Return the first ChildUser filtered by the password column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildUser requireOneBySuperuser(boolean $superuser) Return the first ChildUser filtered by the superuser column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildUser requireOneByMaxInvites(int $max_invites) Return the first ChildUser filtered by the max_invites column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
* @method ChildUser requireOneByUsedInvites(int $used_invites) Return the first ChildUser filtered by the used_invites column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
*
* @method ChildUser[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildUser objects based on current ModelCriteria
* @method ChildUser[]|ObjectCollection findById(int $id) Return ChildUser objects filtered by the id column
@ -66,6 +78,8 @@ use Propel\Runtime\Exception\PropelException;
* @method ChildUser[]|ObjectCollection findByUsername(string $username) Return ChildUser objects filtered by the username column
* @method ChildUser[]|ObjectCollection findByPassword(string $password) Return ChildUser objects filtered by the password column
* @method ChildUser[]|ObjectCollection findBySuperuser(boolean $superuser) Return ChildUser objects filtered by the superuser column
* @method ChildUser[]|ObjectCollection findByMaxInvites(int $max_invites) Return ChildUser objects filtered by the max_invites column
* @method ChildUser[]|ObjectCollection findByUsedInvites(int $used_invites) Return ChildUser objects filtered by the used_invites column
* @method ChildUser[]|\Propel\Runtime\Util\PropelModelPager paginate($page = 1, $maxPerPage = 10, ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
*
*/
@ -158,7 +172,7 @@ abstract class UserQuery extends ModelCriteria
*/
protected function findPkSimple($key, ConnectionInterface $con)
{
$sql = 'SELECT id, max_keys, username, password, superuser FROM User WHERE id = :p0';
$sql = 'SELECT id, max_keys, username, password, superuser, max_invites, used_invites FROM User WHERE id = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@ -415,6 +429,88 @@ abstract class UserQuery extends ModelCriteria
return $this->addUsingAlias(UserTableMap::COL_SUPERUSER, $superuser, $comparison);
}
/**
* Filter the query on the max_invites column
*
* Example usage:
* <code>
* $query->filterByMaxInvites(1234); // WHERE max_invites = 1234
* $query->filterByMaxInvites(array(12, 34)); // WHERE max_invites IN (12, 34)
* $query->filterByMaxInvites(array('min' => 12)); // WHERE max_invites > 12
* </code>
*
* @param mixed $maxInvites The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return $this|ChildUserQuery The current query, for fluid interface
*/
public function filterByMaxInvites($maxInvites = null, $comparison = null)
{
if (is_array($maxInvites)) {
$useMinMax = false;
if (isset($maxInvites['min'])) {
$this->addUsingAlias(UserTableMap::COL_MAX_INVITES, $maxInvites['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($maxInvites['max'])) {
$this->addUsingAlias(UserTableMap::COL_MAX_INVITES, $maxInvites['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(UserTableMap::COL_MAX_INVITES, $maxInvites, $comparison);
}
/**
* Filter the query on the used_invites column
*
* Example usage:
* <code>
* $query->filterByUsedInvites(1234); // WHERE used_invites = 1234
* $query->filterByUsedInvites(array(12, 34)); // WHERE used_invites IN (12, 34)
* $query->filterByUsedInvites(array('min' => 12)); // WHERE used_invites > 12
* </code>
*
* @param mixed $usedInvites The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return $this|ChildUserQuery The current query, for fluid interface
*/
public function filterByUsedInvites($usedInvites = null, $comparison = null)
{
if (is_array($usedInvites)) {
$useMinMax = false;
if (isset($usedInvites['min'])) {
$this->addUsingAlias(UserTableMap::COL_USED_INVITES, $usedInvites['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($usedInvites['max'])) {
$this->addUsingAlias(UserTableMap::COL_USED_INVITES, $usedInvites['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(UserTableMap::COL_USED_INVITES, $usedInvites, $comparison);
}
/**
* Filter the query by a related \Eater\Glim\Model\Certificate object
*
@ -488,6 +584,79 @@ abstract class UserQuery extends ModelCriteria
->useQuery($relationAlias ? $relationAlias : 'Certificate', '\Eater\Glim\Model\CertificateQuery');
}
/**
* Filter the query by a related \Eater\Glim\Model\Invite object
*
* @param \Eater\Glim\Model\Invite|ObjectCollection $invite the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildUserQuery The current query, for fluid interface
*/
public function filterByInvite($invite, $comparison = null)
{
if ($invite instanceof \Eater\Glim\Model\Invite) {
return $this
->addUsingAlias(UserTableMap::COL_ID, $invite->getOwner(), $comparison);
} elseif ($invite instanceof ObjectCollection) {
return $this
->useInviteQuery()
->filterByPrimaryKeys($invite->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByInvite() only accepts arguments of type \Eater\Glim\Model\Invite or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Invite relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return $this|ChildUserQuery The current query, for fluid interface
*/
public function joinInvite($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Invite');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Invite');
}
return $this;
}
/**
* Use the Invite relation Invite object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Eater\Glim\Model\InviteQuery A secondary query class using the current class as primary query
*/
public function useInviteQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinInvite($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Invite', '\Eater\Glim\Model\InviteQuery');
}
/**
* Exclude object from result
*

@ -59,7 +59,7 @@ class InviteTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 2;
const NUM_COLUMNS = 3;
/**
* The number of lazy-loaded columns
@ -69,7 +69,7 @@ class InviteTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 2;
const NUM_HYDRATE_COLUMNS = 3;
/**
* the column name for the id field
@ -81,6 +81,11 @@ class InviteTableMap extends TableMap
*/
const COL_INVITE = 'Invite.invite';
/**
* the column name for the owner field
*/
const COL_OWNER = 'Invite.owner';
/**
* The default string format for model objects of the related table
*/
@ -93,11 +98,11 @@ class InviteTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'Invite', ),
self::TYPE_CAMELNAME => array('id', 'invite', ),
self::TYPE_COLNAME => array(InviteTableMap::COL_ID, InviteTableMap::COL_INVITE, ),
self::TYPE_FIELDNAME => array('id', 'invite', ),
self::TYPE_NUM => array(0, 1, )
self::TYPE_PHPNAME => array('Id', 'Invite', 'Owner', ),
self::TYPE_CAMELNAME => array('id', 'invite', 'owner', ),
self::TYPE_COLNAME => array(InviteTableMap::COL_ID, InviteTableMap::COL_INVITE, InviteTableMap::COL_OWNER, ),
self::TYPE_FIELDNAME => array('id', 'invite', 'owner', ),
self::TYPE_NUM => array(0, 1, 2, )
);
/**
@ -107,11 +112,11 @@ class InviteTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'Invite' => 1, ),
self::TYPE_CAMELNAME => array('id' => 0, 'invite' => 1, ),
self::TYPE_COLNAME => array(InviteTableMap::COL_ID => 0, InviteTableMap::COL_INVITE => 1, ),
self::TYPE_FIELDNAME => array('id' => 0, 'invite' => 1, ),
self::TYPE_NUM => array(0, 1, )
self::TYPE_PHPNAME => array('Id' => 0, 'Invite' => 1, 'Owner' => 2, ),
self::TYPE_CAMELNAME => array('id' => 0, 'invite' => 1, 'owner' => 2, ),
self::TYPE_COLNAME => array(InviteTableMap::COL_ID => 0, InviteTableMap::COL_INVITE => 1, InviteTableMap::COL_OWNER => 2, ),
self::TYPE_FIELDNAME => array('id' => 0, 'invite' => 1, 'owner' => 2, ),
self::TYPE_NUM => array(0, 1, 2, )
);
/**
@ -133,6 +138,7 @@ class InviteTableMap extends TableMap
// columns
$this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null);
$this->addColumn('invite', 'Invite', 'VARCHAR', false, 64, null);
$this->addForeignKey('owner', 'Owner', 'INTEGER', 'User', 'id', false, null, null);
} // initialize()
/**
@ -140,6 +146,13 @@ class InviteTableMap extends TableMap
*/
public function buildRelations()
{
$this->addRelation('User', '\\Eater\\Glim\\Model\\User', RelationMap::MANY_TO_ONE, array (
0 =>
array (
0 => ':owner',
1 => ':id',
),
), null, null, null, false);
} // buildRelations()
/**
@ -285,9 +298,11 @@ class InviteTableMap extends TableMap
if (null === $alias) {
$criteria->addSelectColumn(InviteTableMap::COL_ID);
$criteria->addSelectColumn(InviteTableMap::COL_INVITE);
$criteria->addSelectColumn(InviteTableMap::COL_OWNER);
} else {
$criteria->addSelectColumn($alias . '.id');
$criteria->addSelectColumn($alias . '.invite');
$criteria->addSelectColumn($alias . '.owner');
}
}

@ -59,7 +59,7 @@ class UserTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 5;
const NUM_COLUMNS = 7;
/**
* The number of lazy-loaded columns
@ -69,7 +69,7 @@ class UserTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 5;
const NUM_HYDRATE_COLUMNS = 7;
/**
* the column name for the id field
@ -96,6 +96,16 @@ class UserTableMap extends TableMap
*/
const COL_SUPERUSER = 'User.superuser';
/**
* the column name for the max_invites field
*/
const COL_MAX_INVITES = 'User.max_invites';
/**
* the column name for the used_invites field
*/
const COL_USED_INVITES = 'User.used_invites';
/**
* The default string format for model objects of the related table
*/
@ -108,11 +118,11 @@ class UserTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'MaxKeys', 'Username', 'Password', 'Superuser', ),
self::TYPE_CAMELNAME => array('id', 'maxKeys', 'username', 'password', 'superuser', ),
self::TYPE_COLNAME => array(UserTableMap::COL_ID, UserTableMap::COL_MAX_KEYS, UserTableMap::COL_USERNAME, UserTableMap::COL_PASSWORD, UserTableMap::COL_SUPERUSER, ),
self::TYPE_FIELDNAME => array('id', 'max_keys', 'username', 'password', 'superuser', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, )
self::TYPE_PHPNAME => array('Id', 'MaxKeys', 'Username', 'Password', 'Superuser', 'MaxInvites', 'UsedInvites', ),
self::TYPE_CAMELNAME => array('id', 'maxKeys', 'username', 'password', 'superuser', 'maxInvites', 'usedInvites', ),
self::TYPE_COLNAME => array(UserTableMap::COL_ID, UserTableMap::COL_MAX_KEYS, UserTableMap::COL_USERNAME, UserTableMap::COL_PASSWORD, UserTableMap::COL_SUPERUSER, UserTableMap::COL_MAX_INVITES, UserTableMap::COL_USED_INVITES, ),
self::TYPE_FIELDNAME => array('id', 'max_keys', 'username', 'password', 'superuser', 'max_invites', 'used_invites', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@ -122,11 +132,11 @@ class UserTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'MaxKeys' => 1, 'Username' => 2, 'Password' => 3, 'Superuser' => 4, ),
self::TYPE_CAMELNAME => array('id' => 0, 'maxKeys' => 1, 'username' => 2, 'password' => 3, 'superuser' => 4, ),
self::TYPE_COLNAME => array(UserTableMap::COL_ID => 0, UserTableMap::COL_MAX_KEYS => 1, UserTableMap::COL_USERNAME => 2, UserTableMap::COL_PASSWORD => 3, UserTableMap::COL_SUPERUSER => 4, ),
self::TYPE_FIELDNAME => array('id' => 0, 'max_keys' => 1, 'username' => 2, 'password' => 3, 'superuser' => 4, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, )
self::TYPE_PHPNAME => array('Id' => 0, 'MaxKeys' => 1, 'Username' => 2, 'Password' => 3, 'Superuser' => 4, 'MaxInvites' => 5, 'UsedInvites' => 6, ),
self::TYPE_CAMELNAME => array('id' => 0, 'maxKeys' => 1, 'username' => 2, 'password' => 3, 'superuser' => 4, 'maxInvites' => 5, 'usedInvites' => 6, ),
self::TYPE_COLNAME => array(UserTableMap::COL_ID => 0, UserTableMap::COL_MAX_KEYS => 1, UserTableMap::COL_USERNAME => 2, UserTableMap::COL_PASSWORD => 3, UserTableMap::COL_SUPERUSER => 4, UserTableMap::COL_MAX_INVITES => 5, UserTableMap::COL_USED_INVITES => 6, ),
self::TYPE_FIELDNAME => array('id' => 0, 'max_keys' => 1, 'username' => 2, 'password' => 3, 'superuser' => 4, 'max_invites' => 5, 'used_invites' => 6, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@ -151,6 +161,8 @@ class UserTableMap extends TableMap
$this->addColumn('username', 'Username', 'VARCHAR', false, 64, null);
$this->addColumn('password', 'Password', 'VARCHAR', false, 64, null);
$this->addColumn('superuser', 'Superuser', 'BOOLEAN', false, null, false);
$this->addColumn('max_invites', 'MaxInvites', 'INTEGER', false, null, 0);
$this->addColumn('used_invites', 'UsedInvites', 'INTEGER', false, null, 0);
} // initialize()
/**
@ -165,6 +177,13 @@ class UserTableMap extends TableMap
1 => ':id',
),
), null, null, 'Certificates', false);
$this->addRelation('Invite', '\\Eater\\Glim\\Model\\Invite', RelationMap::ONE_TO_MANY, array (
0 =>
array (
0 => ':owner',
1 => ':id',
),
), null, null, 'Invites', false);
} // buildRelations()
/**
@ -313,12 +332,16 @@ class UserTableMap extends TableMap
$criteria->addSelectColumn(UserTableMap::COL_USERNAME);
$criteria->addSelectColumn(UserTableMap::COL_PASSWORD);
$criteria->addSelectColumn(UserTableMap::COL_SUPERUSER);
$criteria->addSelectColumn(UserTableMap::COL_MAX_INVITES);
$criteria->addSelectColumn(UserTableMap::COL_USED_INVITES);
} else {
$criteria->addSelectColumn($alias . '.id');
$criteria->addSelectColumn($alias . '.max_keys');
$criteria->addSelectColumn($alias . '.username');
$criteria->addSelectColumn($alias . '.password');
$criteria->addSelectColumn($alias . '.superuser');
$criteria->addSelectColumn($alias . '.max_invites');
$criteria->addSelectColumn($alias . '.used_invites');
}
}

@ -0,0 +1,85 @@
<?php
namespace Eater\Glim\Service;
use Stash\Pool;
class GitHub extends Main
{
public function getContributors() {
/** @var Pool $pool */
$pool = $this->get('stash');
$contributors = $pool->getItem('github/contributors');
if ($contributors->isMiss()) {
$contributorsData = [];
try {
$contributorsJson = @$this->fetch('/repos/' . $this->get('github-repo') . '/contributors');
$contributorsNewData = json_decode($contributorsJson, true);
if ($contributorsNewData !== null) {
$contributorsData = $contributorsNewData;
}
} catch (\Exception $e) {
}
$info = $this->getRepoInfo();
if ($info !== false) {
$ownerId = $info['owner']['id'];
$contributorsNewData = [];
foreach ($contributorsData as $contributor) {
if ($contributor['id'] !== $ownerId) {
$contributorsNewData[] = $contributor;
}
}
$contributorsData = $contributorsNewData;
}
$contributors->expiresAfter(3600);
$contributors->set($contributorsData);
$contributors->save();
}
return $contributors->get();
}
public function getRepoInfo() {
/** @var Pool $pool */
$pool = $this->get('stash');
$info = $pool->getItem('github/info');
if ($info->isMiss()) {
$infoData = false;
try {
$infoJson = @$this->fetch('/repos/' . $this->get('github-repo'));
$infoNewData = json_decode($infoJson, true);
if ($infoNewData !== null) {
$infoData = $infoNewData;
}
} catch (\Exception $e) {
}
$info->expiresAfter(3600);
$info->set($infoData);
$info->save();
}
return $info->get();
}
private function fetch($path)
{
$options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
$context = stream_context_create($options);
return file_get_contents('https://api.github.com' . $path, false, $context);
}
}

@ -0,0 +1,15 @@
<?php
namespace Eater\Glim\Service;
use Stash\Pool;
use Stash\Driver\FileSystem;
class Stash
{
static public function init() {
$driver = new FileSystem();
$pool = new Pool($driver);
return $pool;
}
}

@ -13,7 +13,7 @@ class User extends Main
* @param string $invite
* @param string $username
* @param string $password
* @return Eater\Glim\Model\User
* @return UserModel
* @throws \Exception
*/
public function register($invite, $username, $password)
@ -26,9 +26,20 @@ class User extends Main
$this->validateUserParams($username, $password);
$inviteUser = $invite->getUser();
$user = new UserModel();
$user->setUsername($username);
$user->setPassword(\password_hash($password, PASSWORD_DEFAULT));
if ($inviteUser === null || $inviteUser->getMaxInvites() === -1) {
$user->setMaxInvites(5);
} elseif ($inviteUser->getMaxInvites() > 0) {
$user->setMaxInvites($inviteUser->getMaxInvites() - 1);
} else {
$user->setMaxInvites(0);
}
$user->save();
$invite->delete();
@ -66,6 +77,7 @@ class User extends Main
$user->setUsername($username);
$user->setPassword(\password_hash($password, PASSWORD_DEFAULT));
$user->setSuperuser(true);
$user->setMaxInvites(-1);
$user->save();
return $user;
@ -94,14 +106,19 @@ class User extends Main
}
/**
* @param UserModel $user
* @return string
*/
public function createInvite()
public function createInvite(UserModel $user)
{
$invite = new Invite();
$invite->setInvite(bin2hex(openssl_random_pseudo_bytes(20)));
$invite->setUser($user);
$invite->save();
$user->setUsedInvites($user->getUsedInvites() + 1);
$user->save();
return $invite->getInvite();
}
}

@ -20,6 +20,7 @@
<div class="pull-right">
{% if user %}
<a href="/panel" class="user navbar-brand">{{ user.username }}</a>
<a href="/panel/invites" class="navbar-brand">Invites</a>
<a href="/logout" class="navbar-brand">Logout</a>
{% else %}
<a class="navbar-brand" href="/login">Login</a>

@ -36,7 +36,15 @@
</div>
</div>
<div class="footer-page">
<h1>an eaterofcode production</h1>
<a href="/"><i class="fa fa-github fa-4x" aria-hidden="true"></i></a>
<h1>an {{ author }} production</h1>
<a href="https://github.com/{{ githubRepo }}"><i class="fa fa-github fa-4x" aria-hidden="true"></i></a>
{% if contributors|length > 0 %}
<h2>with the help of
{% for contributor in contributors %}
{% if loop.index0 < (loop.length - 1) and loop.index0 > 0 %}, {% elseif loop.index0 == (loop.length - 1) %} and {% endif %}
<a href="{{ contributor.html_url }}">{{ contributor.login }}</a>
{% endfor %}
</h2>
{% endif %}
</div>
{% endblock %}

@ -0,0 +1,48 @@
{% extends "base_bootstrap.html.twig" %}
{% block content %}
<div class="container">
<div class="row">
<h2 id="certificates">Invites <small>You used {{ used_invites }} from your {{ max_invites == -1 ? 'infinite' : max_invites }} invites</small></h2>
</div>
{% if error %}
<div class="row">
<div class="alert alert-warning" role="alert">
{{ error }}
</div>
</div>
{% endif %}
<div class="row">
<table class="table">
<thead>
<tr>
<th>Invite</th>
<th>
{% if max_invites > used_invites or max_invites == -1 %}
<form action="/panel/invites/create" method="post">
<button class="btn btn-default pull-right" type="submit">Create new invite</button>
</form>
{% endif %}
</th>
</tr>
</thead>
<tbody>
{% for invite in invites %}
<tr>
<td>
<kbd>{{ invite.getInvite() }}</kbd>
</td>
<td>
<button class="btn btn-default">Copy</button>
</td>
</tr>
{% else %}
<tr>
<td colspan="2">You don't have any invites :(</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
Loading…
Cancel
Save