1
|
|
|
<?php namespace Distilleries\Expendable\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Contracts\LayoutManagerContract; |
4
|
|
|
use Distilleries\Expendable\Http\Datatables\User\UserDatatable; |
5
|
|
|
use Distilleries\Expendable\Http\Forms\User\UserForm; |
6
|
|
|
use Distilleries\Expendable\Http\Controllers\Backend\Base\BaseComponent; |
7
|
|
|
use Distilleries\Expendable\Models\User; |
8
|
|
|
use Illuminate\Contracts\Auth\Guard; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
|
11
|
|
|
class UserController extends BaseComponent { |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
public function __construct(UserDatatable $datatable, UserForm $form, User $model, LayoutManagerContract $layoutManager) |
15
|
|
|
{ |
16
|
|
|
parent::__construct($model, $layoutManager); |
17
|
|
|
$this->datatable = $datatable; |
18
|
|
|
$this->form = $form; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// ------------------------------------------------------------------------------------------------ |
22
|
|
|
// ------------------------------------------------------------------------------------------------ |
23
|
|
|
// ------------------------------------------------------------------------------------------------ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function getProfile(Guard $auth) |
27
|
|
|
{ |
28
|
|
|
return $this->getEdit($auth->user()->getKey()); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
// ------------------------------------------------------------------------------------------------ |
32
|
|
|
|
33
|
|
|
public function postProfile(Request $request, Guard $auth) |
34
|
|
|
{ |
35
|
|
|
if ($auth->user()->getAuthIdentifier() == $request->get($this->model->getKeyName())) |
36
|
|
|
{ |
37
|
|
|
$this->postEdit($request); |
38
|
|
|
|
39
|
|
|
return $this->getProfile($auth); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
abort(403, trans('permission-util::errors.unthorized')); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// ------------------------------------------------------------------------------------------------ |
46
|
|
|
|
47
|
|
|
public function postSearchWithRole(Request $request) |
48
|
|
|
{ |
49
|
|
|
$query = $this->model->where('role_id', '=', $request->get('role')); |
|
|
|
|
50
|
|
|
$this->postSearch($request, $query); |
51
|
|
|
|
52
|
|
|
return $this->postSearch($request, $query); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
View Code Duplication |
public function postUnLock(Request $request){ |
57
|
|
|
|
58
|
|
|
$model = $this->model->findOrFail($request->get('id')); |
|
|
|
|
59
|
|
|
$model->nb_of_try = 0; |
60
|
|
|
$model->save(); |
61
|
|
|
|
62
|
|
|
return redirect()->back(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
View Code Duplication |
public function postLock(Request $request){ |
67
|
|
|
|
68
|
|
|
$model = $this->model->findOrFail($request->get('id')); |
|
|
|
|
69
|
|
|
$model->nb_of_try = config('expendable.auth.nb_of_try'); |
70
|
|
|
$model->save(); |
71
|
|
|
|
72
|
|
|
return redirect()->back(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: