diff --git a/app/Classes/Frame.php b/app/Classes/Frame.php index 3ac15aa..9b4ed63 100644 --- a/app/Classes/Frame.php +++ b/app/Classes/Frame.php @@ -2,8 +2,12 @@ namespace App\Classes; +use App\Models\Mode; use Illuminate\Support\Facades\Log; +use App\User; +use App\Models\CUG; + /** * Handles all aspects of frame * @@ -100,12 +104,15 @@ abstract class Frame /** * Return a list of alternative versions of this frame. + * + * @todo: Need to adjust to not include access=0 frames unless owner */ - public function alts() + public function alts(Mode $o) { return \App\Models\Frame::where('frame',$this->frame()) ->where('index',$this->index()) ->where('id','<>',$this->frame->id) + ->where('mode_id',$o->id) ->limit(9); } @@ -133,6 +140,34 @@ abstract class Frame return $this->frame->frame; } + /** + * Get the CUG for a frame + * + * Frame CUG are derived from their frame number. + * EG: Frame 642 is a member of 642, or 64, or 6, or 0, whichever matches first. + * + * @return CUG + */ + public function getCUG() + { + $co = NULL; + $frame = $this->frame->frame; + + while (! $co) + { + $co = CUG::find($frame); + + if (! $co) { + $frame = substr($frame,0,strlen($frame)-1); + + if (! $frame) + $frame = 0; + } + } + + return $co; + } + /** * Return the current field configuration */ @@ -197,6 +232,21 @@ abstract class Frame return chr(ord($this->frame->index)+1); } + public function isAccessible():bool + { + return $this->frame->access ? TRUE : FALSE; + } + + /** + * Determine if the frame is a particular CUG + * @param int $cug + * @return bool + */ + public function isCUG(int $cug): bool + { + return ($this->getCUG()->id == $cug); + } + /** * Determine if a field is editable * @@ -208,6 +258,22 @@ abstract class Frame return array_get(array_get($this->fieldoptions,$field),'edit',FALSE); } + /** + * Is this frame Public + * + * @return bool + */ + public function isFramePublic(): bool + { + return $this->frame->closed ? FALSE : TRUE; + } + // @todo To implement + + public function isOwner(User $o):bool + { + return FALSE; + } + /** * Return the Page Number */ @@ -312,6 +378,8 @@ abstract class Frame $o->type = 'a'; $o->frame = 999; $o->index = 'a'; + $o->access = 1; + $o->closed = 0; // Header $sid = R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T'; diff --git a/app/Classes/Server.php b/app/Classes/Server.php index d2081cc..2e5e43c 100644 --- a/app/Classes/Server.php +++ b/app/Classes/Server.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Sock\{SocketClient,SocketException}; +use App\User; use App\Classes\Frame as FrameClass; use App\Models\Frame as FrameModel; use App\Models\Mode; @@ -20,6 +21,50 @@ abstract class Server { { $this->mo = $o; + define('MODE_BL',1); // Typing a * command on the baseline + define('MODE_FIELD',2); // typing into an imput field + define('MODE_WARPTO',3); // awaiting selection of a timewarp + define('MODE_COMPLETE',4); // Entry of data is complete .. + define('MODE_SUBMITRF',5); // asking if should send or not. + define('MODE_RFSENT',6); + define('MODE_RFERROR',7); + define('MODE_RFNOTSENT',8); + + define('ACTION_RELOAD',1); + define('ACTION_GOTO',2); + define('ACTION_BACKUP',3); + define('ACTION_NEXT',4); + define('ACTION_INFO',5); + define('ACTION_TERMINATE',6); + define('ACTION_SUBMITRF',7); // Offer to submit a response frame + define('ACTION_STAR',8); + + define('FRAMETYPE_INFO','i'); + define('FRAMETYPE_ACTION','a'); + define('FRAMETYPE_LOGIN','l'); + + // Keyboard presses + define('KEY_LEFT',chr(136)); + define('KEY_RIGHT',chr(137)); + define('KEY_DOWN',chr(138)); + define('KEY_UP',chr(139)); + + define('TCP_IAC',chr(255)); + define('TCP_DONT',chr(254)); + define('TCP_DO',chr(253)); + define('TCP_WONT',chr(252)); + define('TCP_WILL',chr(251)); + define('TCP_SB',chr(250)); + define('TCP_AYT',chr(246)); + define('TCP_SE',chr(240)); + + define('TCP_BINARY',chr(0)); + define('TCP_OPT_ECHO',chr(1)); + define('TCP_OPT_SUP_GOAHEAD',chr(3)); + define('TCP_OPT_TERMTYPE',chr(24)); + define('TCP_OPT_WINDOWSIZE',chr(31)); + define('TCP_OPT_LINEMODE',chr(34)); + define('MSG_SENDORNOT', GREEN.'KEY 1 TO SEND, 2 NOT TO SEND'); define('MSG_SENT', GREEN.'MESSAGE SENT - KEY _ TO CONTINUE'); define('MSG_NOTSENT', GREEN.'MESSAGE NOT SENT - KEY _ TO CONTINUE'); @@ -29,6 +74,7 @@ abstract class Server { define('ERR_PRIVATE', WHITE.'PRIVATE PAGE'.GREEN.'- FOR EXPLANATION *37_..'); define('ERR_ROUTE', WHITE.'MISTAKE?'.GREEN.'TRY AGAIN OR TELL US ON *08'); define('ERR_PAGE',ERR_ROUTE); + define('ERR_USER_ALREADYMEMBER', RED.'ALREADY MEMBER OF CUG'); define('MSG_TIMEWARP_ON', WHITE.'TIMEWARP ON'.GREEN.'VIEW INFO WITH *02'); define('MSG_TIMEWARP_OFF', WHITE.'TIMEWARP OFF'.GREEN.'VIEWING DATE IS FIXED'); @@ -82,6 +128,7 @@ abstract class Server { $action = ACTION_GOTO; // Initial action. $cmd = ''; // Current *command being typed in $mode = FALSE; // Current mode. + $user = User::find(1); // The logged in user $current = []; // Attributes about the current page // field/fieldnum indexes are for fields on the active page @@ -199,6 +246,8 @@ abstract class Server { $action = FALSE; switch ($fo->type()) { + // Login frame. + case 'l': // Response frame. case 'a': switch ($read) { @@ -213,13 +262,11 @@ abstract class Server { if ($current['fieldnum'] !== FALSE) { $current['field'] = $fo->getField($current['fieldnum']); - $fielddata[$current['fieldnum']] = ''; $client->send($this->outputPosition($current['field']->x,$current['field']->y).CON); $mode = MODE_FIELD; - $fielddate[$current['fieldnum']] = ''; - // There were no (more) editable fields. + // There were no (more) editable fields. } else { $action = ACTION_SUBMITRF; } @@ -286,6 +333,9 @@ abstract class Server { // Record Data Entry default: if (ord($read) > 31 && $current['fieldpos'] < $current['field']->length) { + if (! array_get($fielddata,$current['fieldnum'])) + $fielddata[$current['fieldnum']] = ''; + $fielddata[$current['fieldnum']]{$current['fieldpos']} = $read; $current['fieldpos']++; $client->send($read); @@ -309,7 +359,7 @@ abstract class Server { switch ($read) { // @todo Input received, process it. case '1': - // dump(['line'=>__LINE__,'s' => $service, 'f' => $fielddata]); + // dump(['line'=>__LINE__,'f' => $fielddata]); // @todo if send successful or not if (TRUE) { $this->sendBaseline($client,MSG_SENT); @@ -621,32 +671,53 @@ abstract class Server { break; } - // validate if we have access top it - /* if (isset($m['access']) && $m['access'] == 'n') { - $this->sendBaseline($client,ERR_PAGE); - $mode = $action = false; - break; - } - if (isset($m['cug']) && is_numeric($m['cug']) && $m['cug'] && !in_array($m['cug'],$usercugs)) { - $this->sendBaseline($client,ERR_PRIVATE); - $mode = $action = false; - break; - } - */ + // Is there a user logged in + if ($user) + { + if ($fo->isFramePublic() AND $fo->isAccessible()) + { + if ($fo->type() == FRAMETYPE_LOGIN AND $user->isMemberCUG($fo->getCUG())) + { + $this->sendBaseline($client,ERR_USER_ALREADYMEMBER); + $mode = $action = FALSE; - // we have access... - //if ($r['varient_id'] != $varient['varient_id']) { - /* if ($timewarpalt) { - if (empty($v['varient_date'])) { - $this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO, 'unknown date')); - } else { - $this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO, date('j f Y', strtotime($v['varient_date'])))); + break; + } + + // If this is a login frame and the user is already a member. + } else { + + if (! $fo->isOwner($user)) + { + if (! $fo->isAccessible()) + { + $this->sendBaseline($client,ERR_PAGE); + $mode = $action = FALSE; + + break; + } + + if (! $user->isMemberCUG($fo->getCUG())) + { + $this->sendBaseline($client, ERR_PRIVATE); + $mode = $action = FALSE; + + break; + } } - //$varient = array_merge($varient, array_intersect_key($r, $varient)); - $msg = "TIMEWARP"; - dump(['line'=>__LINE__,'write'=>'TIMEWARP MESSAGE']); } - */ + + } else { + // Is this a public frame in CUG 0? + if (! $fo->isCUG(0) OR ! $fo->isFramePublic()) + { + $this->sendBaseline($client,ERR_PAGE); + $mode = $action = FALSE; + + break; + } + } + $current['page'] = $fo->page(TRUE); $current['fieldpos'] = 0; @@ -678,13 +749,15 @@ abstract class Server { switch ($fo->type()) { default: - // Standard Frame + // Standard Frame case 'i': $client->send($output); $mode = $action = false; break; + // Login Frame. + case 'l': // Active Frame. Prestel uses this for a Response Frame. case 'a': $client->send($output); diff --git a/app/Models/CUG.php b/app/Models/CUG.php new file mode 100644 index 0000000..ec5347d --- /dev/null +++ b/app/Models/CUG.php @@ -0,0 +1,21 @@ +parent_id OR $o->id == $this->parent_id) + return TRUE; + + $o = $this::findOrFail($o->parent_id); + } + } +} \ No newline at end of file diff --git a/app/Models/Frame.php b/app/Models/Frame.php index 185fa71..5127eb3 100644 --- a/app/Models/Frame.php +++ b/app/Models/Frame.php @@ -7,6 +7,11 @@ use Illuminate\Database\Eloquent\Model; class Frame extends Model { + public function cug() + { + return $this->belongsTo(CUG::class); + } + protected static function boot() { parent::boot(); diff --git a/app/User.php b/app/User.php new file mode 100644 index 0000000..77ec348 --- /dev/null +++ b/app/User.php @@ -0,0 +1,43 @@ +belongsToMany(Models\CUG::class,'cug_users','user_id','cug_id'); + } + + public function isMemberCUG(CUG $o) + { + // @todo This doesnt include parent CUGs + return $this->cugs->contains($o); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index d88db76..811f848 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^7.1.3", + "doctrine/dbal": "^2.9", "fideloper/proxy": "^4.0", "laravel/framework": "5.7.*", "laravel/tinker": "^1.0", @@ -39,9 +40,6 @@ "psr-4": { "App\\": "app/" }, - "files": [ - "config/constants.php" - ], "classmap": [ "database/seeds", "database/factories" diff --git a/composer.lock b/composer.lock index c33b929..314246a 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2bcfe8e78cb84d91841e72dec65770f9", + "content-hash": "ff208b67c5f938a92c08bec4d362e0b4", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -39,6 +39,237 @@ "description": "implementation of xdg base directory specification for php", "time": "2014-10-24T07:27:01+00:00" }, + { + "name": "doctrine/cache", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/d768d58baee9a4862ca783840eca1b9add7a7f57", + "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57", + "shasum": "" + }, + "require": { + "php": "~7.1" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/coding-standard": "^4.0", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^7.0", + "predis/predis": "~1.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2018-08-21T18:01:43+00:00" + }, + { + "name": "doctrine/dbal", + "version": "v2.9.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "21fdabe2fc01e004e1966f200d900554876bc63c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/21fdabe2fc01e004e1966f200d900554876bc63c", + "reference": "21fdabe2fc01e004e1966f200d900554876bc63c", + "shasum": "" + }, + "require": { + "doctrine/cache": "^1.0", + "doctrine/event-manager": "^1.0", + "ext-pdo": "*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^5.0", + "jetbrains/phpstorm-stubs": "^2018.1.2", + "phpstan/phpstan": "^0.10.1", + "phpunit/phpunit": "^7.4", + "symfony/console": "^2.0.5|^3.0|^4.0", + "symfony/phpunit-bridge": "^3.4.5|^4.0.5" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.9.x-dev", + "dev-develop": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\DBAL\\": "lib/Doctrine/DBAL" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.", + "homepage": "https://www.doctrine-project.org/projects/dbal.html", + "keywords": [ + "abstraction", + "database", + "dbal", + "mysql", + "persistence", + "pgsql", + "php", + "queryobject" + ], + "time": "2018-12-04T04:39:48+00:00" + }, + { + "name": "doctrine/event-manager", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/event-manager.git", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "conflict": { + "doctrine/common": "<2.9@dev" + }, + "require-dev": { + "doctrine/coding-standard": "^4.0", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "Doctrine Event Manager component", + "homepage": "https://www.doctrine-project.org/projects/event-manager.html", + "keywords": [ + "event", + "eventdispatcher", + "eventmanager" + ], + "time": "2018-06-11T11:59:03+00:00" + }, { "name": "doctrine/inflector", "version": "v1.3.0", diff --git a/config/constants.php b/config/constants.php deleted file mode 100644 index 52c26e5..0000000 --- a/config/constants.php +++ /dev/null @@ -1,41 +0,0 @@ - env('LOG_CHANNEL', 'stack'), + + /* + |-------------------------------------------------------------------------- + | Log Channels + |-------------------------------------------------------------------------- + | + | Here you may configure the log channels for your application. Out of + | the box, Laravel uses the Monolog PHP logging library. This gives + | you a variety of powerful log handlers / formatters to utilize. + | + | Available Drivers: "single", "daily", "slack", "syslog", + | "errorlog", "monolog", + | "custom", "stack" + | + */ + + 'channels' => [ + 'stack' => [ + 'driver' => 'stack', + 'channels' => ['daily'], + ], + + 'single' => [ + 'driver' => 'single', + 'path' => storage_path('logs/laravel.log'), + 'level' => 'debug', + ], + + 'daily' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/laravel.log'), + 'level' => 'debug', + 'days' => 14, + ], + + 'slack' => [ + 'driver' => 'slack', + 'url' => env('LOG_SLACK_WEBHOOK_URL'), + 'username' => 'Laravel Log', + 'emoji' => ':boom:', + 'level' => 'critical', + ], + + 'papertrail' => [ + 'driver' => 'monolog', + 'level' => 'debug', + 'handler' => SyslogUdpHandler::class, + 'handler_with' => [ + 'host' => env('PAPERTRAIL_URL'), + 'port' => env('PAPERTRAIL_PORT'), + ], + ], + + 'stderr' => [ + 'driver' => 'monolog', + 'handler' => StreamHandler::class, + 'with' => [ + 'stream' => 'php://stderr', + ], + ], + + 'syslog' => [ + 'driver' => 'syslog', + 'level' => 'debug', + ], + + 'errorlog' => [ + 'driver' => 'errorlog', + 'level' => 'debug', + ], + ], + +]; diff --git a/database/migrations/2018_12_03_104758_init_database.php b/database/migrations/2018_12_03_104758_init_database.php index c071e0f..a1b68cb 100644 --- a/database/migrations/2018_12_03_104758_init_database.php +++ b/database/migrations/2018_12_03_104758_init_database.php @@ -16,51 +16,51 @@ class InitDatabase extends Migration $this->down(); Schema::create('modes', function (Blueprint $table) { - $table->timestamps(); - $table->integer('id')->autoIncrement(); - $table->string('name',16); - $table->string('note',255); + $table->timestamps(); + $table->integer('id')->autoIncrement(); + $table->string('name',16); + $table->string('note',255); - $table->unique(['name']); + $table->unique(['name']); }); Schema::create('cugs', function (Blueprint $table) { - $table->timestamps(); - $table->integer('id'); - $table->string('name',16); - $table->string('note',255); - $table->integer('parent_id')->nullable(); + $table->timestamps(); + $table->integer('id'); + $table->string('name',16); + $table->string('note',255); + $table->integer('parent_id')->nullable(); - $table->primary('id'); - $table->foreign('parent_id')->references('id')->on('cugs'); - $table->unique(['name']); + $table->primary('id'); + $table->foreign('parent_id')->references('id')->on('cugs'); + $table->unique(['name']); }); Schema::create('frames', function (Blueprint $table) { - $table->timestamps(); - $table->integer('id')->autoIncrement(); - $table->integer('frame'); - $table->char('index',1); - $table->integer('mode_id'); - $table->char('type',2); - $table->smallInteger('cost')->default(0); - $table->integer('cug_id')->default(0); - $table->boolean('public')->default(FALSE); - $table->binary('content'); - $table->string('note',255)->nullable(); + $table->timestamps(); + $table->integer('id')->autoIncrement(); + $table->integer('frame'); + $table->char('index',1); + $table->integer('mode_id'); + $table->char('type',2); + $table->smallInteger('cost')->default(0); + $table->integer('cug_id')->default(0); + $table->boolean('public')->default(FALSE); + $table->binary('content'); + $table->string('note',255)->nullable(); - //$table->unique(['frame','index','mode_id']); // Not needed since we have timewarp + //$table->unique(['frame','index','mode_id']); // Not needed since we have timewarp - $table->foreign('mode_id')->references('id')->on('modes'); - $table->foreign('cug_id')->references('id')->on('cugs'); + $table->foreign('mode_id')->references('id')->on('modes'); + $table->foreign('cug_id')->references('id')->on('cugs'); }); Schema::create('routes', function (Blueprint $table) { - $table->integer('id')->autoIncrement(); - $table->char('key',1); - $table->integer('route'); + $table->integer('id')->autoIncrement(); + $table->char('key',1); + $table->integer('route'); - $table->foreign('route')->references('id')->on('frames'); + $table->foreign('route')->references('id')->on('frames'); }); } @@ -76,4 +76,4 @@ class InitDatabase extends Migration Schema::dropIfExists('cugs'); Schema::dropIfExists('modes'); } -} +} \ No newline at end of file diff --git a/database/migrations/2018_12_09_103357_create_framemeta.php b/database/migrations/2018_12_09_103357_create_framemeta.php new file mode 100644 index 0000000..2e771cf --- /dev/null +++ b/database/migrations/2018_12_09_103357_create_framemeta.php @@ -0,0 +1,44 @@ +down(); + + Schema::create('framemeta', function (Blueprint $table) { + $table->integer('frame_id')->primary(); + $table->string('r0'); + $table->string('r1'); + $table->string('r2'); + $table->string('r3'); + $table->string('r4'); + $table->string('r5'); + $table->string('r6'); + $table->string('r7'); + $table->string('r8'); + $table->string('r9'); + + $table->foreign('frame_id')->references('id')->on('frames'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('framemeta'); + } +} \ No newline at end of file diff --git a/database/migrations/2018_12_10_171426_create_user.php b/database/migrations/2018_12_10_171426_create_user.php new file mode 100644 index 0000000..acc9ae2 --- /dev/null +++ b/database/migrations/2018_12_10_171426_create_user.php @@ -0,0 +1,38 @@ +down(); + + Schema::create('users', function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->string('login',8)->unique(); + $table->string('password'); + $table->string('name'); + $table->string('email')->unique(); + $table->string('location'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users'); + } +} diff --git a/database/migrations/2018_12_10_211904_create_user_cug.php b/database/migrations/2018_12_10_211904_create_user_cug.php new file mode 100644 index 0000000..bf5e125 --- /dev/null +++ b/database/migrations/2018_12_10_211904_create_user_cug.php @@ -0,0 +1,38 @@ +down(); + + Schema::create('cug_users', function (Blueprint $table) { + $table->integer('cug_id'); + $table->integer('user_id')->unsigned(); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('cug_id')->references('id')->on('cugs'); + $table->unique(['user_id','cug_id']); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('cug_users'); + } +} \ No newline at end of file diff --git a/database/migrations/2018_12_10_211936_create_cug_owners.php b/database/migrations/2018_12_10_211936_create_cug_owners.php new file mode 100644 index 0000000..a854694 --- /dev/null +++ b/database/migrations/2018_12_10_211936_create_cug_owners.php @@ -0,0 +1,37 @@ +down(); + + Schema::create('cug_owners', function (Blueprint $table) { + $table->integer('cug_id'); + $table->integer('user_id')->unsigned(); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('cug_id')->references('id')->on('cugs'); + $table->unique(['user_id','cug_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('cug_owners'); + } +} \ No newline at end of file diff --git a/database/migrations/2018_12_10_214547_frame_add_access.php b/database/migrations/2018_12_10_214547_frame_add_access.php new file mode 100644 index 0000000..049b9af --- /dev/null +++ b/database/migrations/2018_12_10_214547_frame_add_access.php @@ -0,0 +1,38 @@ +renameColumn('public','closed'); + $table->boolean('access')->default(FALSE); + $table->dropForeign(['cug_id']); + $table->dropColumn('cug_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('frames', function (Blueprint $table) { + $table->dropColumn('access'); + $table->renameColumn('closed','public'); + $table->integer('cug_id')->default(0); + $table->foreign('cug_id')->references('id')->on('cugs'); + }); + } +}