1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Authenticate\Driver\Eloquent;
|
4
|
|
|
|
5
|
|
|
use Resta\Authenticate\AuthenticateProvider;
|
6
|
|
|
use Resta\Authenticate\Driver\BuilderContract;
|
7
|
|
|
use Resta\Authenticate\Resource\AuthUserManager;
|
8
|
|
|
use Resta\Authenticate\Driver\BuilderParamGenerator;
|
9
|
|
|
|
10
|
|
|
class UserBuilder extends UserBuilderHelper implements BuilderContract
|
11
|
|
|
{
|
12
|
|
|
//get param generator
|
13
|
|
|
use BuilderParamGenerator;
|
|
|
|
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* @var AuthenticateProvider
|
17
|
|
|
*/
|
18
|
|
|
protected $auth;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* UserBuilder constructor.
|
22
|
|
|
* @param $auth \Resta\Authenticate\AuthenticateProvider
|
23
|
|
|
*/
|
24
|
|
|
public function __construct($auth)
|
25
|
|
|
{
|
26
|
|
|
//authenticate instance
|
27
|
|
|
$this->auth = $auth;
|
28
|
|
|
|
29
|
|
|
parent::__construct();
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
/**
|
33
|
|
|
* get all device tokens for user
|
34
|
|
|
*
|
35
|
|
|
* @param AuthUserManager $manager
|
36
|
|
|
*/
|
37
|
|
|
public function allDeviceTokens($manager)
|
38
|
|
|
{
|
39
|
|
|
return $this->allDeviceTokenQuery($manager);
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/**
|
43
|
|
|
* check builder
|
44
|
|
|
*
|
45
|
|
|
* @param $token
|
46
|
|
|
*/
|
47
|
|
|
public function check($token)
|
48
|
|
|
{
|
49
|
|
|
// using the driver object we write the query builder statement.
|
50
|
|
|
// we do the values of the query with the token that are sent.
|
51
|
|
|
$query = $this->checkQuery($token);
|
52
|
|
|
|
53
|
|
|
// with query we bind the returned values to the params property of the auth object.
|
54
|
|
|
// and so the auth object will make a final return with these values.
|
55
|
|
|
$this->paramValues('check',$query);
|
56
|
|
|
}
|
57
|
|
|
|
58
|
|
|
/**
|
59
|
|
|
* login builder
|
60
|
|
|
*
|
61
|
|
|
* @param \Resta\Authenticate\Resource\AuthLoginCredentialsManager $credentials
|
62
|
|
|
* @return mixed|void
|
63
|
|
|
*/
|
64
|
|
|
public function login($credentials)
|
65
|
|
|
{
|
66
|
|
|
// using the driver object we write the query builder statement.
|
67
|
|
|
// we do the values of the query with the credentials that are sent.
|
68
|
|
|
$query = $this->setQuery($credentials);
|
69
|
|
|
|
70
|
|
|
// with query we bind the returned values to the params property of the auth object.
|
71
|
|
|
// and so the auth object will make a final return with these values.
|
72
|
|
|
$this->paramValues('login',$query);
|
73
|
|
|
|
74
|
|
|
// we assign the credential hash value
|
75
|
|
|
// to the global of the authenticate object.
|
76
|
|
|
$this->auth->credentialHash = $credentials->getCredentialHash();
|
|
|
|
|
77
|
|
|
|
78
|
|
|
// when the query succeeds,
|
79
|
|
|
// we update the token value.
|
80
|
|
|
$this->updateToken();
|
81
|
|
|
|
82
|
|
|
if(isset($this->auth->params['authToken'])){
|
83
|
|
|
$this->saveDeviceToken();
|
84
|
|
|
}
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
/**
|
88
|
|
|
* logout builder
|
89
|
|
|
*
|
90
|
|
|
* @param $token
|
91
|
|
|
*/
|
92
|
|
|
public function logout($token)
|
93
|
|
|
{
|
94
|
|
|
// using the driver object we write the query builder statement.
|
95
|
|
|
// we do the values of the query with the token that are sent.
|
96
|
|
|
$query = $this->logoutQuery($token);
|
97
|
|
|
|
98
|
|
|
// with query we bind the returned values to the params property of the auth object.
|
99
|
|
|
// and so the auth object will make a final return with these values.
|
100
|
|
|
$this->paramValues('logout',$query);
|
101
|
|
|
|
102
|
|
|
//token updating as null
|
103
|
|
|
if(isset($this->auth->params['authToken'])){
|
104
|
|
|
if(!$this->deleteDeviceToken()){
|
|
|
|
|
105
|
|
|
$this->auth->params['status'] = 0;
|
106
|
|
|
$this->auth->params['exception'] = 'logoutInternal';
|
107
|
|
|
return false;
|
108
|
|
|
}
|
109
|
|
|
}
|
110
|
|
|
|
111
|
|
|
if($this->auth->params['status']===0){
|
112
|
|
|
$this->auth->params['exception'] = 'logoutException';
|
113
|
|
|
}
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
/**
|
117
|
|
|
* get user process
|
118
|
|
|
*
|
119
|
|
|
* @param AuthUserManager $manager
|
120
|
|
|
*/
|
121
|
|
|
public function userProcess($manager)
|
122
|
|
|
{
|
123
|
|
|
return $this->userProcessQuery($manager);
|
124
|
|
|
}
|
125
|
|
|
}
|
126
|
|
|
|