44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
|
<?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("/");
|
||
|
}
|
||
|
}
|