mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-21 22:51:04 -04:00
Update user table on access
This commit is contained in:
parent
d057903229
commit
e458ec6331
56
app/Events/User/UserLoggedIn.php
Normal file
56
app/Events/User/UserLoggedIn.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
@ -100,7 +100,7 @@ class StoreInvoice implements ShouldQueue
|
|||||||
if($payment)
|
if($payment)
|
||||||
{
|
{
|
||||||
//fire payment notifications here
|
//fire payment notifications here
|
||||||
PaymentNotification::dipatch($payment);
|
PaymentNotification::dispatch($payment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
app/Listeners/User/UpdateUserLastLogin.php
Normal file
45
app/Listeners/User/UpdateUserLastLogin.php
Normal 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,10 @@ class BaseModel extends Model
|
|||||||
use UserSessionAttributes;
|
use UserSessionAttributes;
|
||||||
use SoftDeletes;
|
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';
|
//protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||||
|
|
||||||
public function __call($method, $params)
|
public function __call($method, $params)
|
||||||
|
@ -17,12 +17,14 @@ use App\Events\Invoice\InvoiceWasMarkedSent;
|
|||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Events\User\UserCreated;
|
use App\Events\User\UserCreated;
|
||||||
|
use App\Events\User\UserLoggedIn;
|
||||||
use App\Listeners\Activity\CreatedClientActivity;
|
use App\Listeners\Activity\CreatedClientActivity;
|
||||||
use App\Listeners\Activity\PaymentCreatedActivity;
|
use App\Listeners\Activity\PaymentCreatedActivity;
|
||||||
use App\Listeners\Invoice\CreateInvoiceActivity;
|
use App\Listeners\Invoice\CreateInvoiceActivity;
|
||||||
use App\Listeners\Invoice\CreateInvoiceInvitations;
|
use App\Listeners\Invoice\CreateInvoiceInvitations;
|
||||||
use App\Listeners\Invoice\UpdateInvoiceActivity;
|
use App\Listeners\Invoice\UpdateInvoiceActivity;
|
||||||
use App\Listeners\SendVerificationNotification;
|
use App\Listeners\SendVerificationNotification;
|
||||||
|
use App\Listeners\User\UpdateUserLastLogin;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
class EventServiceProvider extends ServiceProvider
|
class EventServiceProvider extends ServiceProvider
|
||||||
@ -36,7 +38,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
UserCreated::class => [
|
UserCreated::class => [
|
||||||
SendVerificationNotification::class,
|
SendVerificationNotification::class,
|
||||||
],
|
],
|
||||||
|
UserLoggedIn::class => [
|
||||||
|
UpdateUserLastLogin::class,
|
||||||
|
],
|
||||||
// Clients
|
// Clients
|
||||||
ClientWasCreated::class => [
|
ClientWasCreated::class => [
|
||||||
CreatedClientActivity::class,
|
CreatedClientActivity::class,
|
||||||
@ -87,10 +91,10 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(DispatcherContract $events)
|
||||||
{
|
{
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
//
|
parent::boot($events);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,6 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
'id' => $this->encodePrimaryKey($company->id),
|
'id' => $this->encodePrimaryKey($company->id),
|
||||||
'name' => $company->name,
|
'name' => $company->name,
|
||||||
'company_key' => $company->company_key,
|
'company_key' => $company->company_key,
|
||||||
'last_login' => $company->last_login,
|
|
||||||
'address1' => $company->address1,
|
'address1' => $company->address1,
|
||||||
'address2' => $company->address2,
|
'address2' => $company->address2,
|
||||||
'city' => $company->city,
|
'city' => $company->city,
|
||||||
|
@ -72,6 +72,7 @@ class UserTransformer extends EntityTransformer
|
|||||||
'first_name' => $user->first_name,
|
'first_name' => $user->first_name,
|
||||||
'last_name' => $user->last_name,
|
'last_name' => $user->last_name,
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
|
'last_login' => $user->last_login,
|
||||||
'updated_at' => $user->updated_at,
|
'updated_at' => $user->updated_at,
|
||||||
'deleted_at' => $user->deleted_at,
|
'deleted_at' => $user->deleted_at,
|
||||||
'phone' => $user->phone,
|
'phone' => $user->phone,
|
||||||
@ -84,7 +85,7 @@ class UserTransformer extends EntityTransformer
|
|||||||
|
|
||||||
public function includeUserCompany(User $user)
|
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);
|
//$transformer = new CompanyUserTransformer($this->serializer);
|
||||||
|
|
||||||
//return $this->includeItem($user->user_company(), $transformer, CompanyUser::class);
|
//return $this->includeItem($user->user_company(), $transformer, CompanyUser::class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user