-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/IT-Academy-BCN/ita-landing…
… into feature/register
- Loading branch information
Showing
9 changed files
with
1,535 additions
and
240 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
|
||
class AuthController extends Controller | ||
{ | ||
|
||
/** | ||
* Log in a user and create a session | ||
* | ||
* @method POST | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function login(Request $request) | ||
{ | ||
// Validate inputs | ||
$request->validate([ | ||
'dni' => 'required', | ||
'password' => 'required|string' | ||
]); | ||
|
||
// Get user's credentials | ||
$credentials = [ | ||
'dni' => $request->dni, | ||
'password' => $request->password, | ||
]; | ||
|
||
// Verify user credentials | ||
if (Auth::attempt($credentials)) { | ||
$user = Auth::user(); | ||
$token = $user->createToken('authToken')->accessToken; | ||
|
||
return response()->json(['result' => ['message' => 'Logged in successfully!', 'access_token' => $token], 'status' => true]); | ||
} else { | ||
return response()->json(['result' => ['message' => 'Invalid credentials'], 'status' => false], 401); | ||
} | ||
} | ||
|
||
|
||
} |
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.