1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Authenticate;
|
4
|
|
|
|
5
|
|
|
trait AuthenticateResponse
|
6
|
|
|
{
|
7
|
|
|
/**
|
8
|
|
|
* @var array $params
|
9
|
|
|
*/
|
10
|
|
|
public $params = [];
|
11
|
|
|
|
12
|
|
|
/**
|
13
|
|
|
* @return bool
|
14
|
|
|
*/
|
15
|
|
|
private function checkStatus()
|
16
|
|
|
{
|
17
|
|
|
return isset($this->params['status']) && $this->params['status'];
|
18
|
|
|
}
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* @return void|mixed
|
22
|
|
|
*/
|
23
|
|
|
protected function getCheckResult()
|
24
|
|
|
{
|
25
|
|
|
// if the status value is true,
|
26
|
|
|
// we send output generated from the token value.
|
27
|
|
|
if($this->checkStatus()){
|
28
|
|
|
$this->setAuthenticateSuccess(true);
|
29
|
|
|
return true;
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
//return false
|
33
|
|
|
return false;
|
34
|
|
|
}
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* @return void|mixed
|
38
|
|
|
*/
|
39
|
|
|
protected function getLogoutResult()
|
40
|
|
|
{
|
41
|
|
|
// if the status value is true,
|
42
|
|
|
// we send output generated from the token value.
|
43
|
|
|
if($this->checkStatus()){
|
44
|
|
|
return true;
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
//logout exception
|
48
|
|
|
$this->{$this->params['exception']}();
|
49
|
|
|
}
|
50
|
|
|
|
51
|
|
|
/**
|
52
|
|
|
* @return array
|
53
|
|
|
*/
|
54
|
|
|
protected function getResult()
|
55
|
|
|
{
|
56
|
|
|
$result= [];
|
57
|
|
|
|
58
|
|
|
// if the status value is true,
|
59
|
|
|
// we send output generated from the token value.
|
60
|
|
|
if($this->checkStatus()){
|
61
|
|
|
$result['message'] = 'token success';
|
62
|
|
|
$result['token'] = $this->params['token'];
|
63
|
|
|
|
64
|
|
|
//we send the result value.
|
65
|
|
|
return $result;
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
//in the params property, we set the exception type according to the exception value.
|
69
|
|
|
$exceptionType = (isset($this->params['exception'])) ? $this->params['exception'] : 'credentials';
|
70
|
|
|
|
71
|
|
|
// if the status is unsuccessful,
|
72
|
|
|
// the direct exception will be thrown away.
|
73
|
|
|
$this->exceptionManager($exceptionType);
|
|
|
|
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* set authenticate loaded container value
|
78
|
|
|
*
|
79
|
|
|
* @param bool $value
|
80
|
|
|
*/
|
81
|
|
|
private function setAuthenticateSuccess($value=true)
|
82
|
|
|
{
|
83
|
|
|
if(app()->has('authenticateSuccess')){
|
84
|
|
|
app()->terminate('authenticateSuccess');
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
app()->register('authenticateSuccess',$value);
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
|
91
|
|
|
} |