feat: /api/users/register

This commit is contained in:
b1ek 2024-08-29 19:48:29 +10:00
parent f32cb1832a
commit d106ba956a
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Hash;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Request;
use Validator;
class PublicUserController extends Controller
{
public function register(Request $request)
{
$data = $request->all()['user'];
if (User::where([ 'email' => $data['email'] ])->count() != 0) {
return response('email_taken', 400);
}
/**
* @var User
*/
$user = User::create([
...$data,
'password' => Hash::make($request->input('password'))
]);
$user->save();
session('user', $user->id);
session()->save();
}
}

View File

@ -1,7 +1,18 @@
<?php
use App\Http\Controllers\PublicUserController;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
Route::get('/', function() {
return view('welcome');
});
Route::prefix('/api')->group(function() {
Route::controller(PublicUserController::class)->prefix('/users')->group(function() {
Route::put('/register', 'register');
});
});
Route::get('/session', function() {
exit(print_r(session()->all(), true));
});