PARAG-42 User Login API

This commit is contained in:
s152483 2019-12-16 13:04:01 +01:00
parent c7e85999cd
commit 3f64e933be
2 changed files with 21 additions and 1 deletions

View File

@ -2,8 +2,11 @@
namespace App\Http\Controllers\Auth; namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class LoginController extends Controller class LoginController extends Controller
{ {
@ -36,4 +39,21 @@ class LoginController extends Controller
{ {
$this->middleware('guest')->except('logout'); $this->middleware('guest')->except('logout');
} }
public function loginAPI(Request $request){
$this->validate($request, [
'email' => 'required',
'password' => 'required',
]);
if(Auth::guard('api')->attempt([
'email' => $request->email,
'password' => $request->password]))
{
return response()->json(["message " => "Accepted."], 200);
}
else{
return response()->json(["message " => "Record not found."], 404);
}
}
} }

View File

@ -37,9 +37,9 @@ class User extends Authenticatable
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
]; ];
public function receipts() public function receipts()
{ {
return $this->hasMany('App\Models\Receipt'); return $this->hasMany('App\Models\Receipt');
} }
} }