"D:\xampp\htdocs\laravel\nafes\app\Http\Controllers\Auth\AuthController.php"
use App\User;
use App\BannedUser;
use Auth;
use Hash;
use Str;
public function login(Request $request){
$credentials = $request->only('username', 'password');
$ip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $request->ip());
if (\Auth::attempt($credentials)) {
$usr = User::where('username',$request['username'])->first();
$banned = BannedUser::where('user_ip', $ip)->orWhere('user_id', \Auth::user()->id)->where(function ($query) {
return $query->where('banned_till','>=', \Carbon\Carbon::now()->format('Y-m-d'))->orWhere('forever', 1);
})->first();
$user = \Auth::user();
if (!empty($banned)) {
$this->guard()->logout();
if($banned->forever == 1) {
$msg = 'لقد تم ايقاف هذه الخاصية عن حسابك لمخالفتك قوانين نافس';
$msg .= '<br> لقد تم حظر حسابك نهائياً';
$msg .= '<br> المخالفة:'.$banned->reason;
} else {
$msg = 'لقد تم ايقاف هذه الخاصية عن حسابك لمخالفتك قوانين نافس';
$msg .= '<br> تم حظر حسابك حتى:'.Carbon\Carbon::parse($banned->banned_till)->format('d/m/Y');
$msg .= '<br> المخالفة:'.$banned->reason;
}
return response()->json(['message' => $msg ], 405);
} else {
$user->user_ip = $ip;
$user->save();
return redirect('/')->with('success', 'Successfully login.');
// $url = route('competitions');
// return response()->json(['url' => $url ], 200);
}
} else {
return redirect('login')->with('error', 'The user credentials were incorrect.');
//return response()->json(['message' => 'The user credentials were incorrect.' ], 500);
}
}
====
Route::post('login', 'Auth\AuthController@login')->name('login');
====
<form action="{{ route('login') }}" method="post">
{{ csrf_field() }}
@if(!empty(session('error')))
<strong style="color: red;">{{ session('error') }}</strong>
@endif
===
Comments
Post a Comment