-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,047 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Auth; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\User; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class AuthController extends Controller | ||
{ | ||
public function login(Request $request) | ||
{ | ||
$http = new \GuzzleHttp\Client; | ||
|
||
try { | ||
$response = $http->post(url('/oauth/token'), [ | ||
'form_params' => [ | ||
'grant_type' => 'password', | ||
'client_id' => config('services.passport.client_id'), | ||
'client_secret' => config('services.passport.client_secret'), | ||
'username' => $request->emil, | ||
'password' => $request->password, | ||
] | ||
]); | ||
|
||
return $response->getBody(); | ||
} catch (\GuzzleHttp\Exception\BadResponseException $e) { | ||
if ($e->getCode() === 400) { | ||
return response()->json('Invalid request. Please input an email or a password', $e->getCode()); | ||
} else if ($e->getCode() === 401) { | ||
return response()->json('Your credentials are incorrect. Please try again', $e->getCode()); | ||
} | ||
|
||
return response()->json('Something wrong on the server', $e->getCode()); | ||
} | ||
} | ||
|
||
public function logout() | ||
{ | ||
auth()->user()->tokens->each(function ($token, $key) { | ||
$token->revoke(); | ||
}); | ||
|
||
return response()->json('Logged out successfully', 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.