Created
May 25, 2016 17:36
-
-
Save marttosc/48fafe057f7ea6697e9ba756a67febbf to your computer and use it in GitHub Desktop.
Using middleware to change response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class PasswordTemporary | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$user = app('auth')->user(); | |
$passwords = app('db')->table('temporary_passwords')->orderBy('default', 'desc')->get(); | |
$isTemporary = false; | |
foreach ($passwords as $password) { | |
if (app('hash')->check($password->password, $user->password)) { | |
$isTemporary = true; | |
break; | |
} | |
} | |
if (!$isTemporary && $request->route()->getName() === 'pass.temp') { | |
return redirect()->home(); | |
} | |
if ($isTemporary && $request->route()->getName() !== 'pass.temp') { | |
return redirect()->route('pass.temp'); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment