Skip to content

Instantly share code, notes, and snippets.

@noxify
Created October 9, 2017 20:24
Show Gist options
  • Save noxify/7df7064831f1d7057d0bc8354fd13f01 to your computer and use it in GitHub Desktop.
Save noxify/7df7064831f1d7057d0bc8354fd13f01 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Rinvex\Fort\Handlers;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Auth\Authenticatable;
use Rinvex\Fort\Notifications\RegistrationSuccessNotification;
use Rinvex\Fort\Notifications\VerificationSuccessNotification;
use Rinvex\Fort\Notifications\AuthenticationLockoutNotification;
class GenericHandler
{
/**
* The container instance.
*
* @var \Illuminate\Container\Container
*/
protected $app;
/**
* Create a new fort event listener instance.
*
* @param \Illuminate\Contracts\Container\Container $app
*/
public function __construct(Container $app)
{
$this->app = $app;
}
/**
* Register the listeners for the subscriber.
*
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
*/
public function subscribe(Dispatcher $dispatcher)
{
$dispatcher->listen(Lockout::class, __CLASS__.'@authLockout');
$dispatcher->listen('rinvex.fort.register.success', __CLASS__.'@registerSuccess');
$dispatcher->listen('rinvex.fort.register.social.success', __CLASS__.'@registerSocialSuccess');
$dispatcher->listen('rinvex.fort.emailverification.success', __CLASS__.'@emailVerificationSuccess');
$dispatcher->listen('rinvex.fort.user.password.changed', __CLASS__.'@userPasswordChanged');
}
/**
* Listen to the authentication lockout event.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function authLockout(Request $request)
{
if (config('rinvex.fort.throttle.lockout_email')) {
$user = get_login_field($loginfield = $request->get('loginfield')) === 'email' ? app('rinvex.fort.user')->where('email', $loginfield)->first() : app('rinvex.fort.user')->where('username', $loginfield)->first();
$user->notify(new AuthenticationLockoutNotification($request));
}
}
/**
* Listen to the register success event.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*
* @return void
*/
public function registerSuccess(Authenticatable $user)
{
// Send welcome email
if (config('rinvex.fort.registration.welcome_email')) {
$user->notify(new RegistrationSuccessNotification());
}
}
/**
* Listen to the register social success event.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*
* @return void
*/
public function registerSocialSuccess(Authenticatable $user)
{
// Send welcome email
if (config('rinvex.fort.registration.welcome_email')) {
$user->notify(new RegistrationSuccessNotification(true));
}
}
/**
* Listen to the email verification success.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*
* @return void
*/
public function emailVerificationSuccess(Authenticatable $user)
{
if (config('rinvex.fort.emailverification.success_email')) {
$user->notify(new VerificationSuccessNotification($user->is_active));
}
}
/**
* Listen to the user password changed.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*
* @return void
*/
public function userPasswordChanged(Authenticatable $user)
{
app('rinvex.fort.session')->where('user_id', $user->id)->delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment