1
|
|
|
<?php namespace Modules\User\Repositories\Sentry; |
2
|
|
|
|
3
|
|
|
use Cartalyst\Sentry\Facades\Laravel\Sentry; |
4
|
|
|
use Cartalyst\Sentry\Throttling\UserBannedException; |
5
|
|
|
use Cartalyst\Sentry\Throttling\UserSuspendedException; |
6
|
|
|
use Cartalyst\Sentry\Users\LoginRequiredException; |
7
|
|
|
use Cartalyst\Sentry\Users\PasswordRequiredException; |
8
|
|
|
use Cartalyst\Sentry\Users\UserNotActivatedException; |
9
|
|
|
use Cartalyst\Sentry\Users\UserNotFoundException; |
10
|
|
|
use Cartalyst\Sentry\Users\WrongPasswordException; |
11
|
|
|
use Modules\Core\Contracts\Authentication; |
12
|
|
|
use Modules\User\Events\UserHasActivatedAccount; |
13
|
|
|
|
14
|
|
|
class SentryAuthentication implements Authentication |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Authenticate a user |
18
|
|
|
* @param array $credentials |
19
|
|
|
* @param bool $remember Remember the user |
20
|
|
|
* @return mixed |
21
|
|
|
*/ |
22
|
|
|
public function login(array $credentials, $remember = false) |
23
|
|
|
{ |
24
|
|
|
try { |
25
|
|
|
Sentry::authenticate($credentials, $remember); |
26
|
|
|
|
27
|
|
|
return false; |
28
|
|
|
} catch (LoginRequiredException $e) { |
|
|
|
|
29
|
|
|
return 'Login field is required.'; |
30
|
|
|
} catch (PasswordRequiredException $e) { |
|
|
|
|
31
|
|
|
return 'Password field is required.'; |
32
|
|
|
} catch (WrongPasswordException $e) { |
|
|
|
|
33
|
|
|
return 'Wrong password, try again.'; |
34
|
|
|
} catch (UserNotFoundException $e) { |
|
|
|
|
35
|
|
|
return 'User was not found.'; |
36
|
|
|
} catch (UserNotActivatedException $e) { |
|
|
|
|
37
|
|
|
return 'User is not activated.'; |
38
|
|
|
} catch (UserSuspendedException $e) { |
|
|
|
|
39
|
|
|
return 'User is suspended.'; |
40
|
|
|
} catch (UserBannedException $e) { |
|
|
|
|
41
|
|
|
return 'User is banned.'; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Register a new user. |
47
|
|
|
* @param array $user |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function register(array $user) |
51
|
|
|
{ |
52
|
|
|
return Sentry::register($user); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Activate the given used id |
57
|
|
|
* @param int $userId |
58
|
|
|
* @param string $code |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function activate($userId, $code) |
62
|
|
|
{ |
63
|
|
|
$user = Sentry::findUserById($userId); |
64
|
|
|
|
65
|
|
|
try { |
66
|
|
|
$success = $user->attemptActivation($code); |
67
|
|
|
if ($success) { |
68
|
|
|
event(new UserHasActivatedAccount($user)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $success; |
72
|
|
|
} catch (\Exception $e) { |
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Assign a role to the given user. |
79
|
|
|
* @param \Modules\User\Repositories\UserRepository $user |
80
|
|
|
* @param \Modules\User\Repositories\RoleRepository $role |
81
|
|
|
* @return mixed |
82
|
|
|
*/ |
83
|
|
|
public function assignRole($user, $role) |
84
|
|
|
{ |
85
|
|
|
return $role->users()->attach($user); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Log the user out of the application. |
90
|
|
|
* @return mixed |
91
|
|
|
*/ |
92
|
|
|
public function logout() |
93
|
|
|
{ |
94
|
|
|
return Sentry::logout(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Create an activation code for the given user |
99
|
|
|
* @param $user |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function createActivation($user) |
103
|
|
|
{ |
104
|
|
|
return $user->getActivationCode(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Create a reminders code for the given user |
109
|
|
|
* @param $user |
110
|
|
|
* @return mixed |
111
|
|
|
*/ |
112
|
|
|
public function createReminderCode($user) |
113
|
|
|
{ |
114
|
|
|
return $user->getResetPasswordCode(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Completes the reset password process |
119
|
|
|
* @param $user |
120
|
|
|
* @param string $code |
121
|
|
|
* @param string $password |
122
|
|
|
* @return bool |
123
|
|
|
*/ |
124
|
|
|
public function completeResetPassword($user, $code, $password) |
125
|
|
|
{ |
126
|
|
|
return $user->attemptResetPassword($code, $password); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Determines if the current user has access to given permission |
131
|
|
|
* @param $permission |
132
|
|
|
* @return bool |
133
|
|
|
*/ |
134
|
|
|
public function hasAccess($permission) |
135
|
|
|
{ |
136
|
|
|
$user = Sentry::getUser(); |
137
|
|
|
|
138
|
|
|
if (is_null($user)) { |
139
|
|
|
return false; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $user->hasAccess($permission); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Check if the user is logged in |
147
|
|
|
* @return mixed |
148
|
|
|
*/ |
149
|
|
|
public function check() |
150
|
|
|
{ |
151
|
|
|
if (Sentry::check()) { |
152
|
|
|
return Sentry::getUser(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return false; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get the ID for the currently authenticated user |
160
|
|
|
* @return int |
161
|
|
|
*/ |
162
|
|
|
public function id() |
163
|
|
|
{ |
164
|
|
|
if (! $user = $this->check()) { |
165
|
|
|
return; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $user->id; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.