|
11 | 11 | use Illuminate\Support\Facades\Auth; |
12 | 12 | use Illuminate\Support\Facades\Hash; |
13 | 13 | use Illuminate\Validation\Rules; |
14 | | -use Illuminate\Validation\ValidationException; |
15 | 14 | use Illuminate\View\View; |
16 | 15 |
|
17 | 16 | class RegisteredUserController extends Controller |
18 | 17 | { |
19 | 18 | /** |
20 | 19 | * Display the registration view. |
21 | 20 | */ |
22 | | - public function create(Request $request, $type = null): View |
| 21 | + public function create(): View |
23 | 22 | { |
24 | | - if ($type === 'campus') { |
25 | | - return view('auth.register'); |
26 | | - } elseif ($type === 'innovate') { |
27 | | - return view('auth.innovate.register'); |
28 | | - } else { |
29 | | - return view('auth.select-account-type'); |
30 | | - } |
| 23 | + return view('auth.register'); |
31 | 24 | } |
32 | 25 |
|
33 | 26 | /** |
34 | 27 | * Handle an incoming registration request. |
35 | 28 | * |
36 | | - * @throws ValidationException |
| 29 | + * @throws \Illuminate\Validation\ValidationException |
37 | 30 | */ |
38 | 31 | public function store(Request $request): RedirectResponse |
39 | 32 | { |
40 | | - $this->storeValidation($request); |
41 | | - |
42 | | - $user = User::create([ |
43 | | - 'first_name' => $request->first_name, |
44 | | - 'last_name' => $request->last_name, |
45 | | - 'username' => $request->username, |
46 | | - 'email' => $request->email, |
47 | | - 'password' => Hash::make($request->password), |
48 | | - 'phone_number' => $request->phone_number, |
49 | | - 'user_type' => 'campus', |
| 33 | + $request->validate([ |
| 34 | + 'name' => ['required', 'string', 'max:255'], |
| 35 | + 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class], |
| 36 | + 'password' => ['required', 'confirmed', Rules\Password::defaults()], |
50 | 37 | ]); |
51 | 38 |
|
52 | | - event(new Registered($user)); |
53 | | - |
54 | | - Auth::login($user); |
55 | | - Auth::user()->update(['last_login_at' => now()]); |
56 | | - |
57 | | - // Send verification email |
58 | | - if(!$user->hasVerifiedEmail()) { |
59 | | - $user->sendEmailVerificationNotification(); |
60 | | - } |
61 | | - |
62 | | - return redirect()->route('verification.notice'); |
63 | | - } |
64 | | - |
65 | | - public function store_innovate(Request $request): RedirectResponse |
66 | | - { |
67 | | - $this->storeValidation($request); |
68 | | - |
69 | 39 | $user = User::create([ |
70 | | - 'first_name' => $request->first_name, |
71 | | - 'last_name' => $request->last_name, |
72 | | - 'username' => $request->username, |
| 40 | + 'name' => $request->name, |
73 | 41 | 'email' => $request->email, |
74 | 42 | 'password' => Hash::make($request->password), |
75 | | - 'phone_number' => $request->phone_number, |
76 | | - 'user_type' => 'innovate', |
77 | 43 | ]); |
78 | 44 |
|
79 | 45 | event(new Registered($user)); |
80 | 46 |
|
81 | 47 | Auth::login($user); |
82 | | - Auth::user()->update(['last_login_at' => now()]); |
83 | 48 |
|
84 | | - // Send verification email |
85 | | - if(!$user->hasVerifiedEmail()) { |
86 | | - $user->sendEmailVerificationNotification(); |
87 | | - } |
88 | | - |
89 | | - return redirect()->route('verification.notice'); |
| 49 | + return redirect(RouteServiceProvider::HOME); |
90 | 50 | } |
91 | | - |
92 | | - /** |
93 | | - * @param Request $request |
94 | | - * @return void |
95 | | - */ |
96 | | - public function storeValidation(Request $request): void |
97 | | - { |
98 | | - $request->validate([ |
99 | | - 'first_name' => ['required', 'string', 'max:255'], |
100 | | - 'last_name' => ['required', 'string', 'max:255'], |
101 | | - 'username' => ['required', 'string', 'max:255', 'unique:' . User::class], |
102 | | - 'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class], |
103 | | - 'password' => ['required', 'confirmed', Rules\Password::defaults()], |
104 | | - 'phone_number' => ['nullable', 'string', 'max:255'], |
105 | | - ]); |
106 | | - |
107 | | - $contact = $request->contact; |
108 | | - |
109 | | - //remove the first character if it's a '+' |
110 | | - if (str_starts_with($contact, '+')) { |
111 | | - $contact = substr($contact, 1); |
112 | | - } |
113 | | - |
114 | | - //dd($contact); |
115 | | - |
116 | | - // Check if the first character of the string is '0' |
117 | | - if (str_starts_with($contact, '0')) { |
118 | | - // Replace the first character '0' with '254' |
119 | | - $contact = '254' . substr($contact, 1); |
120 | | - } |
121 | | - |
122 | | - $request->merge(['contact' => $contact]); |
123 | | - } |
124 | | - |
125 | 51 | } |
0 commit comments