|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Icybee package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Olivier Laviale <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Icybee\Modules\Users\Operation; |
|
13
|
|
|
|
|
14
|
|
|
use ICanBoogie\ErrorCollection; |
|
15
|
|
|
use ICanBoogie\Operation; |
|
16
|
|
|
|
|
17
|
|
|
use Icybee\Binding\Core\PrototypedBindings; |
|
18
|
|
|
use Icybee\Modules\Users\User; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Log the user out of the system. |
|
22
|
|
|
* |
|
23
|
|
|
* @property-read User $record The active record representing the user that was logged out. This |
|
24
|
|
|
* property is still available after the user was logged out, unlike the {@link $user} property of |
|
25
|
|
|
* `ICanBoogie/Core` instances. |
|
26
|
|
|
*/ |
|
27
|
|
|
class LogoutOperation extends Operation |
|
28
|
|
|
{ |
|
29
|
|
|
use PrototypedBindings; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns the record of the user to logout. |
|
33
|
|
|
* |
|
34
|
|
|
* The current user is returned. |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function lazy_get_record() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->app->user; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Adds the {@link CONTROL_RECORD} control. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function get_controls() |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
|
|
48
|
|
|
self::CONTROL_RECORD => true |
|
49
|
|
|
|
|
50
|
|
|
] + parent::get_controls(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Always returns `true`. |
|
55
|
|
|
* |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function validate(ErrorCollection $errors) |
|
59
|
|
|
{ |
|
60
|
|
|
return true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Logs out the user. |
|
65
|
|
|
* |
|
66
|
|
|
* The {@link logout()} method of the user is invoked to log the user out. |
|
67
|
|
|
* |
|
68
|
|
|
* The location of the response can be defined by the `continue` request parameter or the request referer, or '/'. |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function process() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->record->logout(); |
|
73
|
|
|
|
|
74
|
|
|
$request = $this->request; |
|
75
|
|
|
$this->response->location = ($request['redirect_to'] ?: $request['continue']) ?: ($request->referer ?: '/'); |
|
76
|
|
|
|
|
77
|
|
|
return true; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|