feat: /api/users/login
This commit is contained in:
parent
3c0a6007d0
commit
55d9b7dc6b
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue