48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\View\View;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
public function show(): View
|
|
{
|
|
return view('auth.register');
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:40'],
|
|
'email' => ['required', 'email', 'max:120', 'unique:users,email'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
'real_name' => ['nullable', 'string', 'max:40'],
|
|
'phone' => ['nullable', 'string', 'max:30'],
|
|
'company' => ['nullable', 'string', 'max:120'],
|
|
'industry' => ['nullable', 'string', 'max:60'],
|
|
]);
|
|
|
|
$user = User::create([
|
|
'name' => $data['name'],
|
|
'email' => $data['email'],
|
|
'password' => $data['password'],
|
|
'real_name' => $data['real_name'] ?? null,
|
|
'phone' => $data['phone'] ?? null,
|
|
'company' => $data['company'] ?? null,
|
|
'industry' => $data['industry'] ?? null,
|
|
]);
|
|
|
|
Auth::login($user);
|
|
|
|
$user->awardPoints(20);
|
|
|
|
return redirect('/');
|
|
}
|
|
}
|