|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Auth\AuthController; |
|
6
|
|
|
use Illuminate\Support\Facades\Lang; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use App\Models\Manager; |
|
9
|
|
|
use App\Models\Lookup\Department; |
|
10
|
|
|
use App\Services\Validation\RegistrationValidator; |
|
11
|
|
|
|
|
12
|
|
|
class FirstVisitController extends AuthController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Show the form for completing Manager registration on first visit. |
|
16
|
|
|
* |
|
17
|
|
|
* @return \Illuminate\Http\Response |
|
18
|
|
|
*/ |
|
19
|
|
|
public function showFirstVisitManagerForm() |
|
20
|
|
|
{ |
|
21
|
|
|
$routes = [ |
|
22
|
|
|
'return' => route('home'), |
|
23
|
|
|
'continue' => route('manager.finish_registration'), |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
return view('auth.first_visit_manager', [ |
|
27
|
|
|
'routes' => $routes, |
|
28
|
|
|
'first_visit' => Lang::get('common/auth/first_manager_visit'), |
|
29
|
|
|
'departments' => Department::all(), |
|
30
|
|
|
'not_in_gov_option' => ['value' => 0, 'name' => Lang::get('common/auth/register.not_in_gov')], |
|
31
|
|
|
]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Process the final data required for Managers. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Request $request |
|
|
|
|
|
|
38
|
|
|
* @return void |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
|
|
public function finishManagerRegistration(Request $request) |
|
41
|
|
|
{ |
|
42
|
|
|
$data = $request->all(); |
|
43
|
|
|
$validator = RegistrationValidator::finalizeManagerValidator($data); |
|
44
|
|
|
$validator->validate(); |
|
45
|
|
|
|
|
46
|
|
|
$user = $request->user(); |
|
47
|
|
|
|
|
48
|
|
|
// Save manager specific fields to user |
|
49
|
|
|
$managerDepartment = Department::find($data['department']); |
|
50
|
|
|
$inGovernment = ($managerDepartment !== null); |
|
51
|
|
|
$user->not_in_gov = !$inGovernment; |
|
52
|
|
|
$user->gov_email = $inGovernment ? $data['gov_email'] : null; |
|
53
|
|
|
$user->save(); |
|
54
|
|
|
$user->refresh(); |
|
55
|
|
|
|
|
56
|
|
|
// Add (or update) manager profile |
|
57
|
|
|
// NOTE: modifying a field in $user, and saving it, appears to create Manager object. I don't know how. -- Tristan |
|
58
|
|
|
// That means that after setting not_in_gov or gov_email, a manager already exists here. Adding a new one will throw an exception. |
|
59
|
|
|
$department_id = $inGovernment ? $managerDepartment->id : null; |
|
60
|
|
|
if ($user->manager === null) { |
|
61
|
|
|
$user->applicant()->save(new Manager()); |
|
62
|
|
|
$user->refresh(); |
|
63
|
|
|
} |
|
64
|
|
|
$user->manager->department_id = $department_id; |
|
65
|
|
|
$user->manager->save(); |
|
66
|
|
|
|
|
67
|
|
|
$user->refresh(); |
|
68
|
|
|
return redirect(route('manager.home')); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|