|
1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Controllers\Admin; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Http\Requests\Admin\Profile\UpdatePasswordRequest; |
|
4
|
|
|
use Arcanesoft\Contracts\Auth\Models\User; |
|
5
|
|
|
use Arcanesoft\Core\Http\Controllers\AdminController; |
|
6
|
|
|
use Arcanesoft\Core\Traits\Notifyable; |
|
7
|
|
|
use Log; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ProfileController |
|
11
|
|
|
* |
|
12
|
|
|
* @package Arcanesoft\Auth\Http\Controllers\Admin |
|
13
|
|
|
* @author ARCANEDEV <[email protected]> |
|
14
|
|
|
* |
|
15
|
|
|
* @todo: Adding the authorization checks |
|
16
|
|
|
*/ |
|
17
|
|
|
class ProfileController extends AdminController |
|
18
|
|
|
{ |
|
19
|
|
|
/* ----------------------------------------------------------------- |
|
20
|
|
|
| Traits |
|
21
|
|
|
| ----------------------------------------------------------------- |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use Notifyable; |
|
25
|
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
|
27
|
|
|
| Properties |
|
28
|
|
|
| ----------------------------------------------------------------- |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The authenticated user. |
|
33
|
|
|
* |
|
34
|
|
|
* @var \Arcanesoft\Contracts\Auth\Models\User |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $user; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The view namespace. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $viewNamespace = 'auth'; |
|
44
|
|
|
|
|
45
|
|
|
/* ----------------------------------------------------------------- |
|
46
|
|
|
| Constructor |
|
47
|
|
|
| ----------------------------------------------------------------- |
|
48
|
|
|
*/ |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* ProfileController constructor. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
|
|
57
|
|
|
$this->addBreadcrumbRoute('Profile', 'admin::auth.profile.index'); |
|
58
|
|
|
$this->setCurrentPage('auth-profile'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/* ----------------------------------------------------------------- |
|
62
|
|
|
| Main Methods |
|
63
|
|
|
| ----------------------------------------------------------------- |
|
64
|
|
|
*/ |
|
65
|
|
|
|
|
66
|
|
|
public function index() |
|
67
|
|
|
{ |
|
68
|
|
|
$user = $this->getAuthenticatedUser(); |
|
69
|
|
|
|
|
70
|
|
|
$this->setTitle("Profile - {$user->full_name}"); |
|
|
|
|
|
|
71
|
|
|
$this->addBreadcrumbRoute($user->full_name, 'admin::auth.profile.index'); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
return $this->view('admin.profile.index', compact('user')); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function edit() |
|
77
|
|
|
{ |
|
78
|
|
|
// TODO: complete the implementation |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function update() |
|
82
|
|
|
{ |
|
83
|
|
|
// TODO: complete the implementation |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function updatePassword(UpdatePasswordRequest $request, User $user) |
|
87
|
|
|
{ |
|
88
|
|
|
$user->update($request->getValidatedData()); |
|
89
|
|
|
|
|
90
|
|
|
$this->transNotification('password-updated', [], $user->toArray()); |
|
91
|
|
|
|
|
92
|
|
|
return redirect()->route('admin::auth.profile.index'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/* ----------------------------------------------------------------- |
|
96
|
|
|
| Other methods |
|
97
|
|
|
| ----------------------------------------------------------------- |
|
98
|
|
|
*/ |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get the authenticated user. |
|
102
|
|
|
* |
|
103
|
|
|
* @return \Arcanesoft\Contracts\Auth\Models\User |
|
104
|
|
|
*/ |
|
105
|
|
|
private function getAuthenticatedUser() |
|
106
|
|
|
{ |
|
107
|
|
|
return auth()->user(); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Notify with translation. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $action |
|
114
|
|
|
* @param array $replace |
|
115
|
|
|
* @param array $context |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
|
120
|
|
|
{ |
|
121
|
|
|
$title = trans("auth::profile.messages.{$action}.title"); |
|
122
|
|
|
$message = trans("auth::profile.messages.{$action}.message", $replace); |
|
123
|
|
|
|
|
124
|
|
|
Log::info($message, $context); |
|
125
|
|
|
$this->notifySuccess($message, $title); |
|
126
|
|
|
|
|
127
|
|
|
return $message; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: