Skip to content

Instantly share code, notes, and snippets.

@ahmedash95
Forked from Developeraya/middleware
Last active May 16, 2017 16:50
Show Gist options
  • Save ahmedash95/12ca44d159b780e2394cb4e8d45704db to your computer and use it in GitHub Desktop.
Save ahmedash95/12ca44d159b780e2394cb4e8d45704db to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Closure;
class checkChangePasswordMiddleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'profile'
];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if($this->inExceptArray($request)){
return $next;
}
$user = Sentinel::getUser();
// if($user)
// {
if($user->change_password == 0)
{
return redirect()->route('user.profile');
}
else
{
return $next($request);
}
// }
// else
// {
// return $next($request);
// }
}
/**
* Determine if the request has a URI that should pass through CSRF verification.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function inExceptArray($request)
{
foreach ($this->except as $except) {
if ($except !== '/') {
$except = trim($except, '/');
}
if ($request->is($except)) {
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment