Update user table on access

This commit is contained in:
David Bomba 2019-06-04 07:46:46 +10:00
parent d057903229
commit e458ec6331
7 changed files with 116 additions and 7 deletions

View File

@ -0,0 +1,56 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
/**
* Class UserLoggedIn
* @package App\Events\User
*/
class UserLoggedIn
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var $user
*/
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@ -100,7 +100,7 @@ class StoreInvoice implements ShouldQueue
if($payment)
{
//fire payment notifications here
PaymentNotification::dipatch($payment);
PaymentNotification::dispatch($payment);
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\User;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class UpdateUserLastLogin
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
$user = $event->user;
$user->last_login = now()
$user->save();
}
}

View File

@ -25,6 +25,10 @@ class BaseModel extends Model
use UserSessionAttributes;
use SoftDeletes;
//todo customise names of archived_at / updated_at columns
///const CREATED_AT = 'creation_date';
//const UPDATED_AT = 'last_update';
//protected $dateFormat = 'Y-m-d H:i:s.u';
public function __call($method, $params)

View File

@ -17,12 +17,14 @@ use App\Events\Invoice\InvoiceWasMarkedSent;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Events\Payment\PaymentWasCreated;
use App\Events\User\UserCreated;
use App\Events\User\UserLoggedIn;
use App\Listeners\Activity\CreatedClientActivity;
use App\Listeners\Activity\PaymentCreatedActivity;
use App\Listeners\Invoice\CreateInvoiceActivity;
use App\Listeners\Invoice\CreateInvoiceInvitations;
use App\Listeners\Invoice\UpdateInvoiceActivity;
use App\Listeners\SendVerificationNotification;
use App\Listeners\User\UpdateUserLastLogin;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
@ -36,7 +38,9 @@ class EventServiceProvider extends ServiceProvider
UserCreated::class => [
SendVerificationNotification::class,
],
UserLoggedIn::class => [
UpdateUserLastLogin::class,
],
// Clients
ClientWasCreated::class => [
CreatedClientActivity::class,
@ -87,10 +91,10 @@ class EventServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(DispatcherContract $events)
{
parent::boot();
//
parent::boot($events);
}
}

View File

@ -65,7 +65,6 @@ class CompanyTransformer extends EntityTransformer
'id' => $this->encodePrimaryKey($company->id),
'name' => $company->name,
'company_key' => $company->company_key,
'last_login' => $company->last_login,
'address1' => $company->address1,
'address2' => $company->address2,
'city' => $company->city,

View File

@ -72,6 +72,7 @@ class UserTransformer extends EntityTransformer
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email,
'last_login' => $user->last_login,
'updated_at' => $user->updated_at,
'deleted_at' => $user->deleted_at,
'phone' => $user->phone,
@ -84,7 +85,7 @@ class UserTransformer extends EntityTransformer
public function includeUserCompany(User $user)
{
//cannot use this here as it will fail retrieving the company as we depend on the token in the header which may not be present for this request
//cannot use this here as it will fail retrieving the company as we depend on the token in the header which may not be present for this request
//$transformer = new CompanyUserTransformer($this->serializer);
//return $this->includeItem($user->user_company(), $transformer, CompanyUser::class);