File size: 1,718 Bytes
89a1081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\UserStoreRequest;
use App\Models\User;
use App\Service\Admin\Core\CustomerService;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\View\View;

class RegisteredUserController extends Controller
{
    public CustomerService $customerService;

    public function __construct(CustomerService $customerService) {

        $this->customerService = $customerService;
    }

    /**
     * Display the registration view.
     * @return View
     */
    public function create(): View {

        $title = "Registration";
        return view('user.auth.register', compact('title'));
    }

    /**
     * @param UserStoreRequest $request
     * @return Application|RedirectResponse|Redirector
     */
    public function store(UserStoreRequest $request): Redirector|RedirectResponse|Application {

        $user = User::create([
            'name'                   => $request->input('name'),
            'email'                  => $request->input('email'),
            'gateway_credentials'   => config('setting.gateway_credentials'),
            'password'               => Hash::make($request->input('password')),
            'email_verified_code'    => randomNumber(),
            'email_verified_send_at' => carbon(),
        ]);

        $this->customerService->applyOnboardingBonus($user);
        $this->customerService->handleEmailVerification($user);
        Auth::login($user);
        
        return redirect()->route('user.dashboard');
    }
}