Browse Source

Move the Invitation table to Eloquent

pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
9fef217db7
  1. 33
      app/Invite.php
  2. 2
      app/controllers/LoginController.php
  3. 4
      app/widgets/Login/Login.php
  4. 5
      app/widgets/Rooms/Rooms.php
  5. 10
      app/widgets/Rooms/_rooms_invite.tpl
  6. 36
      composer.lock
  7. 28
      database/migrations/20180401144542_create_invites_table.php

33
app/Invite.php

@ -0,0 +1,33 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Invite extends Model
{
public $primaryKey = 'code';
public $incrementing = false;
public function user()
{
return $this->belongsTo('App\User');
}
public static function set($jid, $resource)
{
$invitation = \App\Invite::where('user_id', $jid)
->where('resource', $resource)
->first();
if (!$invitation) {
$invitation = new \App\Invite;
$invitation->code = generateKey(8);
$invitation->user_id = $jid;
$invitation->resource = $resource;
$invitation->save();
}
return $invitation;
}
}

2
app/controllers/LoginController.php

@ -19,7 +19,7 @@ class LoginController extends Base
$user = new User;
if ($user->isLogged()) {
if ($this->fetchGet('i') && Validator::length(8)->validate($this->fetchGet('i'))) {
$invitation = \Modl\Invite::get($this->fetchGet('i'));
$invitation = \App\Invite::find($this->fetchGet('i'));
$this->redirect('chat', [$invitation->resource, 'room']);
} else {
$this->redirect('root');

4
app/widgets/Login/Login.php

@ -66,11 +66,11 @@ class Login extends Base
if ($this->get('i')
&& Validator::length(8)->validate($this->get('i'))) {
$invitation = \Modl\Invite::get($this->get('i'));
$invitation = \App\Invite::find($this->get('i'));
if ($invitation) {
$this->view->assign('invitation', $invitation);
$this->view->assign('contact', \App\Contact::firstOrNew(['id' => $invitation->jid]));
$this->view->assign('contact', \App\Contact::firstOrNew(['id' => $invitation->user_id]));
}
}

5
app/widgets/Rooms/Rooms.php

@ -131,10 +131,9 @@ class Rooms extends \Movim\Widget\Base
{
$view = $this->tpl();
$cd = new \Modl\ContactDAO;
$view->assign('contacts', $cd->getRosterSimple());
$view->assign('contacts', \App\User::me()->session->contacts()->pluck('jid'));
$view->assign('room', $room);
$view->assign('invite', \Modl\Invite::set($this->user->jid, $room));
$view->assign('invite', \App\Invite::set($this->user->id, $room));
Dialog::fill($view->draw('_rooms_invite', true));
}

10
app/widgets/Rooms/_rooms_invite.tpl

@ -11,12 +11,10 @@
<h2 style="text-align: center;">{$c->__('global.or')}</h2>
<div>
<input type="hidden" value="{$room}" name="to" id="to"/>
<datalist id="contact_list" style="display: none;">
{if="is_array($contacts)"}
{loop="$contacts"}
<option value="{$value->jid}"/>
{/loop}
{/if}
<datalist id="contact_list">
{loop="$contacts"}
<option value="{$value}"/>
{/loop}
</datalist>
<input
name="invite"

36
composer.lock

@ -773,7 +773,7 @@
},
{
"name": "illuminate/container",
"version": "v5.5.39",
"version": "v5.5.40",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
@ -817,16 +817,16 @@
},
{
"name": "illuminate/contracts",
"version": "v5.5.39",
"version": "v5.5.40",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
"reference": "eb9a0171866fca0669c9acab6c7441e19b4694ca"
"reference": "04fbae936ed14e673dddd18a39662f49e7d199f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/eb9a0171866fca0669c9acab6c7441e19b4694ca",
"reference": "eb9a0171866fca0669c9acab6c7441e19b4694ca",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/04fbae936ed14e673dddd18a39662f49e7d199f5",
"reference": "04fbae936ed14e673dddd18a39662f49e7d199f5",
"shasum": ""
},
"require": {
@ -857,20 +857,20 @@
],
"description": "The Illuminate Contracts package.",
"homepage": "https://laravel.com",
"time": "2018-01-19T17:59:58+00:00"
"time": "2018-03-20T15:34:35+00:00"
},
{
"name": "illuminate/database",
"version": "v5.5.39",
"version": "v5.5.40",
"source": {
"type": "git",
"url": "https://github.com/illuminate/database.git",
"reference": "cfba60398815ff93bef31ade7c1d5dbbabdcaafc"
"reference": "be5fff68fcc6393c984c5164fc26ef7973c869e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/database/zipball/cfba60398815ff93bef31ade7c1d5dbbabdcaafc",
"reference": "cfba60398815ff93bef31ade7c1d5dbbabdcaafc",
"url": "https://api.github.com/repos/illuminate/database/zipball/be5fff68fcc6393c984c5164fc26ef7973c869e9",
"reference": "be5fff68fcc6393c984c5164fc26ef7973c869e9",
"shasum": ""
},
"require": {
@ -916,34 +916,34 @@
"orm",
"sql"
],
"time": "2018-03-06T18:27:38+00:00"
"time": "2018-03-15T12:39:57+00:00"
},
{
"name": "illuminate/support",
"version": "v5.5.39",
"version": "v5.5.40",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
"reference": "7540abdf66efe232bb657b9a5982fbb0d4de428f"
"reference": "5d2ccb17e526ad537bffc16abc1d516457ae5587"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/7540abdf66efe232bb657b9a5982fbb0d4de428f",
"reference": "7540abdf66efe232bb657b9a5982fbb0d4de428f",
"url": "https://api.github.com/repos/illuminate/support/zipball/5d2ccb17e526ad537bffc16abc1d516457ae5587",
"reference": "5d2ccb17e526ad537bffc16abc1d516457ae5587",
"shasum": ""
},
"require": {
"doctrine/inflector": "~1.1",
"ext-mbstring": "*",
"illuminate/contracts": "5.5.*",
"nesbot/carbon": "^1.20",
"nesbot/carbon": "^1.24.1",
"php": ">=7.0"
},
"replace": {
"tightenco/collect": "<5.5.33"
},
"suggest": {
"illuminate/filesystem": "Required to use the composer class (5.2.*).",
"illuminate/filesystem": "Required to use the composer class (5.5.*).",
"symfony/process": "Required to use the composer class (~3.3).",
"symfony/var-dumper": "Required to use the dd function (~3.3)."
},
@ -973,7 +973,7 @@
],
"description": "The Illuminate Support package.",
"homepage": "https://laravel.com",
"time": "2018-03-09T16:54:15+00:00"
"time": "2018-03-10T15:44:32+00:00"
},
{
"name": "michelf/php-markdown",

28
database/migrations/20180401144542_create_invites_table.php

@ -0,0 +1,28 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateInvitesTable extends Migration
{
public function up()
{
$this->schema->create('invites', function(Blueprint $table) {
$table->string('code', 8);
$table->string('user_id', 64);
$table->string('resource', 128);
$table->timestamps();
$table->primary('code');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
});
}
public function down()
{
$this->schema->drop('invites');
}
}
Loading…
Cancel
Save