feat: /api/users/login

This commit is contained in:
b1ek 2024-08-29 20:34:01 +10:00
parent 3c0a6007d0
commit 55d9b7dc6b
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 20 additions and 1 deletions

View File

@ -26,7 +26,25 @@ class PublicUserController extends Controller
'password' => Hash::make($request->input('password')) 'password' => Hash::make($request->input('password'))
]); ]);
$user->save(); $user->save();
session('user', $user->id); session()->put('user', $user->id);
session()->save(); session()->save();
} }
public function login(Request $request)
{
$user = User::where([ 'email' => $request->input('email') ])->get();
if ($user->count() == 0) {
return response()
->json('bad_password', 400);
}
$user = $user[0];
if (Hash::check($request->input('password'), $user->password)) {
session()->put('user', $user->id);
session()->save();
return;
}
return response()
->json('bad_password', 400);
}
} }

View File

@ -10,6 +10,7 @@ Route::get('/', function() {
Route::prefix('/api')->group(function() { Route::prefix('/api')->group(function() {
Route::controller(PublicUserController::class)->prefix('/users')->group(function() { Route::controller(PublicUserController::class)->prefix('/users')->group(function() {
Route::put('/register', 'register'); Route::put('/register', 'register');
Route::post('/login', 'login');
}); });
}); });