1
|
|
|
<?php namespace Modules\User\Repositories\Usher; |
2
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Auth\Guard; |
4
|
|
|
use Modules\Core\Contracts\Authentication; |
5
|
|
|
use Modules\User\Repositories\UserRepository; |
6
|
|
|
|
7
|
|
|
class UsherAuthentication implements Authentication |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var Guard |
11
|
|
|
*/ |
12
|
|
|
private $guard; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var UserRepository |
16
|
|
|
*/ |
17
|
|
|
private $repository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param Guard $guard |
21
|
|
|
* @param UserRepository $repository |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Guard $guard, UserRepository $repository) |
24
|
|
|
{ |
25
|
|
|
$this->guard = $guard; |
26
|
|
|
$this->repository = $repository; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Authenticate a user |
31
|
|
|
* @param array $credentials |
32
|
|
|
* @param bool $remember Remember the user |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function login(array $credentials, $remember = false) |
36
|
|
|
{ |
37
|
|
|
return $this->guard->attempt($credentials, $remember); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register a new user. |
42
|
|
|
* @param array $user |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function register(array $user) |
46
|
|
|
{ |
47
|
|
|
return $this->repository->create((array) $user); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Assign a role to the given user. |
52
|
|
|
* @param \Modules\User\Repositories\UserRepository $user |
53
|
|
|
* @param \Modules\User\Repositories\RoleRepository $role |
54
|
|
|
* @return mixed |
55
|
|
|
*/ |
56
|
|
|
public function assignRole($user, $role) |
57
|
|
|
{ |
58
|
|
|
return $user->assignRole($role); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Log the user out of the application. |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
|
public function logout() |
66
|
|
|
{ |
67
|
|
|
return $this->guard->logout(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Activate the given used id |
72
|
|
|
* @param int $userId |
73
|
|
|
* @param string $code |
74
|
|
|
* @return mixed |
75
|
|
|
*/ |
76
|
|
|
public function activate($userId, $code) |
77
|
|
|
{ |
78
|
|
|
// TODO |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Create an activation code for the given user |
83
|
|
|
* @param \Modules\User\Repositories\UserRepository $user |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function createActivation($user) |
87
|
|
|
{ |
88
|
|
|
// TODO |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Create a reminders code for the given user |
93
|
|
|
* @param \Modules\User\Repositories\UserRepository $user |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
|
|
public function createReminderCode($user) |
97
|
|
|
{ |
98
|
|
|
// TODO |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Completes the reset password process |
103
|
|
|
* @param $user |
104
|
|
|
* @param string $code |
105
|
|
|
* @param string $password |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function completeResetPassword($user, $code, $password) |
109
|
|
|
{ |
110
|
|
|
// TODO |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Determines if the current user has access to given permission |
115
|
|
|
* @param $permission |
116
|
|
|
* @return bool |
117
|
|
|
*/ |
118
|
|
|
public function hasAccess($permission) |
119
|
|
|
{ |
120
|
|
|
return $this->guard->user()->hasAccess($permission); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Check if the user is logged in |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function check() |
128
|
|
|
{ |
129
|
|
|
return $this->guard->user(); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|