pos-gis/app/Http/Controllers/AuthController.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-10-07 06:13:42 +00:00
<?php
namespace App\Http\Controllers;
use App\Interfaces\APIInterface;
use App\Interfaces\AuthApps;
use Illuminate\Http\Request;
class AuthController extends Controller
{
public function login(AuthApps $authApps){
if ($authApps->check()){
return redirect("/dashboard");
}
return view("login");
}
public function doLogin(Request $request, AuthApps $authApps, APIInterface $API){
$data["username"] = $request->get("username");
$data["password"] = $request->get("password");
// dd($data);
// dd($request->all());
$result = $API->post("auth/login" , $data);
// dd($result);
if ($result->rc == 200){
$authApps->add($result->data->token);
return redirect("/dashboard");
}else{
return redirect()->back()->withErrors(['errorLogin' => $result->rm]);
}
}
public function logoutEx(AuthApps $authApps){
$authApps->clear();
return redirect("/");
}
public function check(APIInterface $API){
// $API->doPost();
// $authApps->clear();
return redirect("/");
}
}