mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 18:14:36 -04:00
Add new login notification
This commit is contained in:
parent
b780b636d6
commit
f60b9c30eb
@ -13,6 +13,7 @@ namespace App\Http\Controllers\Auth;
|
|||||||
|
|
||||||
use App\DataMapper\Analytics\LoginFailure;
|
use App\DataMapper\Analytics\LoginFailure;
|
||||||
use App\DataMapper\Analytics\LoginSuccess;
|
use App\DataMapper\Analytics\LoginSuccess;
|
||||||
|
use App\Events\User\UserLoggedIn;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Jobs\Account\CreateAccount;
|
use App\Jobs\Account\CreateAccount;
|
||||||
@ -24,6 +25,7 @@ use App\Models\CompanyToken;
|
|||||||
use App\Models\CompanyUser;
|
use App\Models\CompanyUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Transformers\CompanyUserTransformer;
|
use App\Transformers\CompanyUserTransformer;
|
||||||
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Google_Client;
|
use Google_Client;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
@ -170,6 +172,8 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$user = $this->guard()->user();
|
$user = $this->guard()->user();
|
||||||
|
|
||||||
|
event(new UserLoggedIn($user, $user->account->default_company, Ninja::eventVars($user->id)));
|
||||||
|
|
||||||
//if user has 2fa enabled - lets check this now:
|
//if user has 2fa enabled - lets check this now:
|
||||||
|
|
||||||
if($user->google_2fa_secret && $request->has('one_time_password'))
|
if($user->google_2fa_secret && $request->has('one_time_password'))
|
||||||
|
@ -68,8 +68,6 @@ class TokenAuth
|
|||||||
//stateless, don't remember the user.
|
//stateless, don't remember the user.
|
||||||
auth()->login($user, false);
|
auth()->login($user, false);
|
||||||
|
|
||||||
event(new UserLoggedIn($user, $company_token->company, Ninja::eventVars()));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$error = [
|
$error = [
|
||||||
'message' => 'Invalid token',
|
'message' => 'Invalid token',
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
|
|
||||||
namespace App\Listeners\User;
|
namespace App\Listeners\User;
|
||||||
|
|
||||||
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Mail\User\UserLoggedIn;
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
@ -38,11 +41,29 @@ class UpdateUserLastLogin implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle($event)
|
public function handle($event)
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($event->company->db);
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
$user = $event->user;
|
$user = $event->user;
|
||||||
|
|
||||||
$user->last_login = now();
|
$user->last_login = now();
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
$event_vars = $event->event_vars;
|
||||||
|
$ip = array_key_exists('ip', $event->event_vars) ? $event->event_vars['ip'] : 'IP address not resolved';
|
||||||
|
|
||||||
|
if($user->ip != $ip)
|
||||||
|
{
|
||||||
|
$nmo = new NinjaMailerObject;
|
||||||
|
$nmo->mailable = new UserLoggedIn($user, $user->account->companies()->first(), $ip);
|
||||||
|
$nmo->company = $user->account->companies()->first();
|
||||||
|
$nmo->settings = $user->account->companies()->first()->settings;
|
||||||
|
$nmo->to_user = $user;
|
||||||
|
NinjaMailerJob::dispatch($nmo);
|
||||||
|
|
||||||
|
$user->ip = $ip;
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
namespace App\Mail\Import;
|
namespace App\Mail\Import;
|
||||||
|
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
namespace App\Mail\Migration;
|
namespace App\Mail\Migration;
|
||||||
|
|
||||||
@ -46,6 +55,7 @@ class MaxCompanies extends Mailable
|
|||||||
$this->whitelabel = $this->company->account->isPaid();
|
$this->whitelabel = $this->company->account->isPaid();
|
||||||
|
|
||||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||||
|
->subject(ctrans('texts.max_companies'))
|
||||||
->view('email.migration.max_companies');
|
->view('email.migration.max_companies');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
app/Mail/User/UserLoggedIn.php
Normal file
59
app/Mail/User/UserLoggedIn.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Mail\User;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class UserLoggedIn extends Mailable
|
||||||
|
{
|
||||||
|
// use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public $ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($user, $company, $ip)
|
||||||
|
{
|
||||||
|
$this->company = $company;
|
||||||
|
$this->user = $user;
|
||||||
|
$this->ip = $ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the message.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||||
|
->subject(ctrans('texts.new_login_detected'))
|
||||||
|
->view('email.admin.notification')
|
||||||
|
->with([
|
||||||
|
'settings' => $this->company->settings,
|
||||||
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'title' => ctrans('texts.new_login_detected'),
|
||||||
|
'body' => ctrans('texts.new_login_description', ['email' =>$this->user->email, 'ip' => $this->ip, 'time' => now()]),
|
||||||
|
'whitelabel' => $this->company->account->isPaid(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -4246,6 +4246,8 @@ $LANG = array(
|
|||||||
'activity_102' => ':user archived recurring invoice :recurring_invoice',
|
'activity_102' => ':user archived recurring invoice :recurring_invoice',
|
||||||
'activity_103' => ':user deleted recurring invoice :recurring_invoice',
|
'activity_103' => ':user deleted recurring invoice :recurring_invoice',
|
||||||
'activity_104' => ':user restored recurring invoice :recurring_invoice',
|
'activity_104' => ':user restored recurring invoice :recurring_invoice',
|
||||||
|
'new_login_detected' => 'New login detected for your account.',
|
||||||
|
'new_login_description' => 'You recently logged in to your Invoice Ninja account from a new location or device:<br><br><b>IP:</b> :ip<br><b>Time:</b> :time<br><b>Email:</b> :email',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $LANG;
|
return $LANG;
|
||||||
|
18
resources/views/email/admin/notification.blade.php
Normal file
18
resources/views/email/admin/notification.blade.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
@component('email.template.master', ['design' => 'light', 'settings' => $settings])
|
||||||
|
|
||||||
|
@slot('header')
|
||||||
|
@include('email.components.header', ['logo' => $logo])
|
||||||
|
@endslot
|
||||||
|
|
||||||
|
<h2>{!! $title !!}</h2>
|
||||||
|
|
||||||
|
<p>{!! $body !!}</p>
|
||||||
|
|
||||||
|
@if(isset($whitelabel) && !$whitelabel)
|
||||||
|
@slot('footer')
|
||||||
|
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
|
||||||
|
For any info, please visit InvoiceNinja.
|
||||||
|
@endcomponent
|
||||||
|
@endslot
|
||||||
|
@endif
|
||||||
|
@endcomponent
|
Loading…
x
Reference in New Issue
Block a user