Эко система
Download 1.63 Mb.
|
kirish
AuthController.php
namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\AuthRequest; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; class AuthController extends Controller { static $question_super = ['C6', '7F', 'E7', 'F5', '4A', '2E', '1C', '2B', '6F','3D', '4C', '99', '5E']; static $answer_super = ['B7', 'F4', '4C', '1A', '2B', 'D3', 'C4', '6E', 'A1','5C', 'D7', 'E4', 'D4']; static $question_admin = ['B7', '8C', 'A5', 'D6', '1E', '5F', '8B', '1D', '4F','7D', '40', '21', 'CC']; static $answer_admin = ['E2', 'F5', 'C4', '3C', '2F', 'A7', '5A', '6F', 'A3','5A', 'B7', 'E7', 'E1']; static $question_cordinator = ['B6', '7B', 'A7', 'E4', '4E', '3E', '2A', '2C', '6D', '8A', '4B', '7E', '5A']; static $answer_cordinator = ['E7', 'F4', '7B', '7A', '6B', 'F3', 'C7', '6F', 'A6','7C', 'D1', 'E6', '4C']; public function login() { $question = ""; $leng = 4; $index = array_rand(AuthController::$question_super, $leng); for ($i=0; $i < $leng; $i++) { $question .= AuthController::$question_super[$index[$i]]; } for ($i=0; $i < $leng; $i++) { $question .= AuthController::$question_admin[$index[$i]]; } for ($i=0; $i < $leng; $i++) { $question .= AuthController::$question_cordinator[$index[$i]]; } $indexs = implode(' ',$index); return view('admin.auth.login', compact('question', 'indexs')); } public function home() { return view('admin.auth.home'); } public function authenticate(Request $request) { $credentials = $request->validate([ 'login' => ['required'], 'password' => ['required'], 'answer' => ['required'], ]); $leng = 4; $indexs = explode(' ', $request->indexs); $answer = ""; for ($i=0; $i < $leng; $i++) { $answer .= AuthController::$answer_super[$indexs[$i]]; } for ($i=0; $i < $leng; $i++) { $answer .= AuthController::$answer_admin[$indexs[$i]]; } for ($i=0; $i < $leng; $i++) { $answer .= AuthController::$answer_cordinator[$indexs[$i]]; } if($answer === $request->answer){ unset($credentials['answer']); if (Auth::attempt($credentials)) { $request->session()->regenerate(); return redirect()->intended('admin/dashboard'); } } return back()->withErrors([ 'email' => 'The provided credentials do not match our records.', ])->onlyInput('email'); } public function logout(Request $request) { Auth::logout();$request->session()->invalidate();$request->session()->regenerateToken();return redirect('/'); }} Download 1.63 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling