<?php

namespace App\Http\Controllers\authentications;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class LoginBasic extends Controller
{
  public function index()
  {
    return view('content.authentications.auth-login-basic');
  }

  public function login(Request $request)
  {
    $credentials = $request->only('username', 'password');

    if (Auth::attempt($credentials)) {
      $request->session()->regenerate();
      return redirect()->to('/dashboard');
    } else {
      return redirect()->route("auth-login-basic")->withErrors([
        "message" => "Username/Password incorrect!"
      ]);
    }
  }

  public function logout(Request $request)
  {
    Auth::logout();
    $request->session()->regenerate();
    return redirect()->to("/");
  }
}
