mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-17 16:02:31 +01:00
da83aa1f23
Fix
62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Settings;
|
|
use App\Models\User;
|
|
use App\Providers\RouteServiceProvider;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rules;
|
|
|
|
class RegisteredUserController extends Controller
|
|
{
|
|
/**
|
|
* Display the registration view.
|
|
*
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
$users = User::all();
|
|
if ($users->count() >= 1) {//Only allow 1 user for this app
|
|
return redirect('/login');
|
|
}
|
|
return view('auth.register');
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming registration request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
|
]);
|
|
|
|
$user = User::create([
|
|
'name' => $request->name,
|
|
'email' => $request->email,
|
|
'password' => Hash::make($request->password),
|
|
'api_token' => Str::random(60)
|
|
]);
|
|
|
|
event(new Registered($user));
|
|
|
|
Auth::login($user);
|
|
|
|
return redirect('/');
|
|
}
|
|
}
|